1 17 package org.alfresco.filesys.server; 18 19 import java.net.InetAddress ; 20 21 import javax.transaction.Status ; 22 import javax.transaction.SystemException ; 23 import javax.transaction.UserTransaction ; 24 25 import org.alfresco.error.AlfrescoRuntimeException; 26 import org.alfresco.filesys.server.auth.ClientInfo; 27 import org.alfresco.filesys.server.core.SharedDevice; 28 import org.alfresco.filesys.server.core.SharedDeviceList; 29 import org.alfresco.service.transaction.TransactionService; 30 31 36 public abstract class SrvSession 37 { 38 39 41 private NetworkServer m_server; 42 43 45 private int m_sessId; 46 47 49 private String m_uniqueId; 50 51 53 private int m_processId = -1; 54 55 57 private boolean m_loggedOn; 58 59 61 private ClientInfo m_clientInfo; 62 63 65 private byte[] m_challenge; 66 67 69 private int m_debug; 70 private String m_dbgPrefix; 71 72 74 private boolean m_shutdown; 75 76 78 private String m_protocol; 79 80 82 private String m_remoteName; 83 84 86 private Object m_authToken; 87 88 90 private SharedDeviceList m_dynamicShares; 91 92 94 private UserTransaction m_transaction; 95 private boolean m_readOnlyTrans; 96 97 99 protected int m_reqCount; 100 protected int m_transCount; 101 protected int m_transConvCount; 102 103 111 public SrvSession(int sessId, NetworkServer srv, String proto, String remName) 112 { 113 m_sessId = sessId; 114 m_server = srv; 115 116 setProtocolName(proto); 117 setRemoteName(remName); 118 } 119 120 125 public final void addDynamicShare(SharedDevice shrDev) { 126 127 129 if ( m_dynamicShares == null) 130 m_dynamicShares = new SharedDeviceList(); 131 132 134 m_dynamicShares.addShare(shrDev); 135 } 136 137 142 public final Object getAuthenticationToken() 143 { 144 return m_authToken; 145 } 146 147 152 public final boolean hasAuthenticationToken() 153 { 154 return m_authToken != null ? true : false; 155 } 156 157 162 public final byte[] getChallengeKey() 163 { 164 return m_challenge; 165 } 166 167 172 public final boolean hasChallengeKey() 173 { 174 return m_challenge != null ? true : false; 175 } 176 177 182 public final int getProcessId() 183 { 184 return m_processId; 185 } 186 187 192 public abstract InetAddress getRemoteAddress(); 193 194 199 public final int getSessionId() 200 { 201 return m_sessId; 202 } 203 204 209 public final NetworkServer getServer() 210 { 211 return m_server; 212 } 213 214 219 public final boolean hasClientInformation() 220 { 221 return m_clientInfo != null ? true : false; 222 } 223 224 229 public final ClientInfo getClientInformation() 230 { 231 return m_clientInfo; 232 } 233 234 239 public final boolean hasDynamicShares() { 240 return m_dynamicShares != null ? true : false; 241 } 242 243 248 public final SharedDeviceList getDynamicShareList() { 249 return m_dynamicShares; 250 } 251 252 257 public final boolean hasProtocolName() 258 { 259 return m_protocol != null ? true : false; 260 } 261 262 267 public final String getProtocolName() 268 { 269 return m_protocol; 270 } 271 272 277 public final boolean hasRemoteName() 278 { 279 return m_remoteName != null ? true : false; 280 } 281 282 287 public final String getRemoteName() 288 { 289 return m_remoteName; 290 } 291 292 297 public final boolean isLoggedOn() 298 { 299 return m_loggedOn; 300 } 301 302 307 public final boolean isShutdown() 308 { 309 return m_shutdown; 310 } 311 312 317 public final String getUniqueId() 318 { 319 return m_uniqueId; 320 } 321 322 328 public final boolean hasDebug(int dbgFlag) 329 { 330 if ((m_debug & dbgFlag) != 0) 331 return true; 332 return false; 333 } 334 335 340 public final void setAuthenticationToken(Object authToken) 341 { 342 m_authToken = authToken; 343 } 344 345 350 public final void setClientInformation(ClientInfo client) 351 { 352 m_clientInfo = client; 353 } 354 355 360 public final void setChallengeKey(byte[] key) 361 { 362 m_challenge = key; 363 } 364 365 370 public final void setDebug(int flgs) 371 { 372 m_debug = flgs; 373 } 374 375 380 public final void setDebugPrefix(String prefix) 381 { 382 m_dbgPrefix = prefix; 383 } 384 385 390 public final void setLoggedOn(boolean loggedOn) 391 { 392 m_loggedOn = loggedOn; 393 } 394 395 400 public final void setProcessId(int id) 401 { 402 m_processId = id; 403 } 404 405 410 public final void setProtocolName(String name) 411 { 412 m_protocol = name; 413 } 414 415 420 public final void setRemoteName(String name) 421 { 422 m_remoteName = name; 423 } 424 425 430 public final void setSessionId(int id) 431 { 432 m_sessId = id; 433 } 434 435 440 public final void setUniqueId(String unid) 441 { 442 m_uniqueId = unid; 443 } 444 445 450 protected final void setShutdown(boolean flg) 451 { 452 m_shutdown = flg; 453 } 454 455 458 public void closeSession() 459 { 460 462 if ( hasDynamicShares()) { 463 464 466 getServer().getShareMapper().deleteShares(this); 467 } 468 } 469 470 478 public final boolean beginTransaction(TransactionService transService, boolean readOnly) 479 throws AlfrescoRuntimeException 480 { 481 boolean created = false; 482 483 485 if ( m_transaction != null) 486 { 487 489 try 490 { 491 492 if ( m_transaction.getStatus() == Status.STATUS_MARKED_ROLLBACK || 493 m_transaction.getStatus() == Status.STATUS_ROLLEDBACK || 494 m_transaction.getStatus() == Status.STATUS_ROLLING_BACK) 495 { 496 498 m_transaction.rollback(); 499 } 500 } 501 catch ( SystemException ex) 502 { 503 } 504 505 507 if ( readOnly == false && m_readOnlyTrans == true) 508 { 509 511 try 512 { 513 m_transaction.commit(); 514 m_transConvCount++; 515 } 516 catch ( Exception ex) 517 { 518 throw new AlfrescoRuntimeException("Failed to commit read-only transaction, " + ex.getMessage()); 519 } 520 finally 521 { 522 524 m_transaction = null; 525 } 526 } 527 } 528 529 531 if ( m_transaction == null) 532 { 533 try 534 { 535 m_transaction = transService.getUserTransaction(readOnly); 536 m_transaction.begin(); 537 538 created = true; 539 540 m_readOnlyTrans = readOnly; 541 542 m_transCount++; 543 } 544 catch (Exception ex) 545 { 546 throw new AlfrescoRuntimeException("Failed to create transaction, " + ex.getMessage()); 547 } 548 } 549 550 return created; 551 } 552 553 558 public final void endTransaction() 559 throws AlfrescoRuntimeException 560 { 561 563 if ( m_transaction != null) 564 { 565 try 566 { 567 569 if ( m_transaction.getStatus() == Status.STATUS_MARKED_ROLLBACK) 570 { 571 573 m_transaction.rollback(); 574 } 575 else 576 { 577 579 m_transaction.commit(); 580 } 581 } 582 catch ( Exception ex) 583 { 584 throw new AlfrescoRuntimeException("Failed to end transaction", ex); 585 } 586 finally 587 { 588 590 m_transaction = null; 591 } 592 } 593 594 } 595 600 public final boolean hasUserTransaction() 601 { 602 return m_transaction != null ? true : false; 603 } 604 605 610 public final UserTransaction getUserTransaction() 611 { 612 UserTransaction trans = m_transaction; 613 m_transaction = null; 614 return trans; 615 } 616 } 617 | Popular Tags |