fabric.worker.transaction
Class TransactionManager

java.lang.Object
  extended by fabric.worker.transaction.TransactionManager

public final class TransactionManager
extends java.lang.Object

Holds transaction management information for a single thread. Each thread has its own TransactionManager.

We say that a transaction has acquired a write lock on an object if any entry in the object's $history list has $writeLockHolder set to that transaction. @see fabric.lang.Object._Impl

We say that a transaction has acquired a read lock if it is in the "read list" for that object. @see fabric.lang.Object._Impl.$readMapEntry

When a transaction acquires a read lock, we ensure that the read condition holds: that the holder of the write lock is an ancestor of that transaction. Before reading an object, we ensure that the transaction holds a read lock and that the read condition still holds.

When a transaction acquires a write lock, we ensure that the write condition holds: the holders of the read and write locks are all ancestors of that transaction. Before writing an object, we ensure that the transaction holds a write lock and that the write condition still holds.

Assumptions:

The following objects are used as condition variables:


Method Summary
 void abortTransaction()
           
 void associateAndSyncLog(Log log, TransactionID tid)
          Associates the given log with this worker's transaction manager and synchronizes the log with the given tid.
 void associateLog(Log log)
          Associates the given transaction log with this transaction manager.
 boolean checkForStaleObjects()
          Checks whether any of the objects used by a transaction are stale.
 void commitTransaction()
          Commits the transaction if possible; otherwise, aborts the transaction.
 void commitTransaction(boolean useAuthentication)
          Commits the transaction if possible; otherwise, aborts the transaction.
 void commitTransactionAt(long commitTime)
           
 void deregisterThread(java.lang.Thread thread)
          Registers that the given thread has finished.
 Log getCurrentLog()
           
 TransactionID getCurrentTid()
           
 RemoteWorker getFetchWorker(Object._Proxy proxy)
           
static TransactionManager getInstance()
           
static ReadMapEntry getReadMapEntry(Object._Impl impl, long expiry)
           
 SecurityCache getSecurityCache()
           
 UpdateMap getUpdateMap()
           
 void registerCreate(Object._Impl obj)
           
 void registerRead(Object._Impl obj)
           
 void registerRemoteCall(RemoteWorker worker)
          Registers a remote call to the given worker.
 void registerThread(java.lang.Thread thread)
          Registers the given thread with the current transaction.
 boolean registerWrite(Object._Impl obj)
          This should be called before the object is modified.
 void sendCommitMessagesAndCleanUp()
          Sends commit messages to the cohorts.
 void sendPrepareMessages(long commitTime)
          Sends prepare messages to the cohorts.
static void startThread(java.lang.Thread thread)
          Starts the given thread, registering it as necessary.
 void startTransaction()
          Starts a new transaction.
 void startTransaction(TransactionID tid)
          Starts a new transaction with the given tid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getReadMapEntry

public static ReadMapEntry getReadMapEntry(Object._Impl impl,
                                           long expiry)

getInstance

public static TransactionManager getInstance()

abortTransaction

public void abortTransaction()

commitTransaction

public void commitTransaction()
                       throws AbortException,
                              TransactionRestartingException,
                              TransactionAtomicityViolationException
Commits the transaction if possible; otherwise, aborts the transaction.

Throws:
AbortException - if the transaction was aborted.
TransactionRestartingException - if the transaction was aborted and needs to be retried.
TransactionAtomicityViolationException

commitTransaction

public void commitTransaction(boolean useAuthentication)
                       throws AbortException,
                              TransactionRestartingException,
                              TransactionAtomicityViolationException
Commits the transaction if possible; otherwise, aborts the transaction.

Parameters:
useAuthentication - whether to use an authenticated channel to talk to the store
Throws:
AbortException - if the transaction was aborted.
TransactionRestartingException - if the transaction was aborted and needs to be retried.
TransactionAtomicityViolationException

commitTransactionAt

public void commitTransactionAt(long commitTime)
                         throws AbortException,
                                TransactionRestartingException
Throws:
AbortException
TransactionRestartingException

sendPrepareMessages

public void sendPrepareMessages(long commitTime)
Sends prepare messages to the cohorts. Also sends abort messages if any cohort fails to prepare.


sendCommitMessagesAndCleanUp

public void sendCommitMessagesAndCleanUp()
                                  throws TransactionAtomicityViolationException
Sends commit messages to the cohorts.

Throws:
TransactionAtomicityViolationException

registerCreate

public void registerCreate(Object._Impl obj)

registerRead

public void registerRead(Object._Impl obj)

registerWrite

public boolean registerWrite(Object._Impl obj)
This should be called before the object is modified.

Returns:
whether a new (top-level) transaction was created.

checkForStaleObjects

public boolean checkForStaleObjects()
Checks whether any of the objects used by a transaction are stale.

Returns:
true iff stale objects were found

startTransaction

public void startTransaction()
Starts a new transaction. The sub-transaction runs in the same thread as the caller.


startTransaction

public void startTransaction(TransactionID tid)
Starts a new transaction with the given tid. The given tid is assumed to be a valid descendant of the current tid. If the given tid is null, a random tid is generated for the sub-transaction.


startThread

public static void startThread(java.lang.Thread thread)
Starts the given thread, registering it as necessary.


registerThread

public void registerThread(java.lang.Thread thread)
Registers the given thread with the current transaction. This should be called before the thread is started.


deregisterThread

public void deregisterThread(java.lang.Thread thread)
Registers that the given thread has finished.


registerRemoteCall

public void registerRemoteCall(RemoteWorker worker)
Registers a remote call to the given worker.


associateLog

public void associateLog(Log log)
Associates the given transaction log with this transaction manager.


getCurrentLog

public Log getCurrentLog()

getCurrentTid

public TransactionID getCurrentTid()

getUpdateMap

public UpdateMap getUpdateMap()

getFetchWorker

public RemoteWorker getFetchWorker(Object._Proxy proxy)
Returns:
the worker on which the object resides. An object resides on a worker if it is either on that worker's local store, or if it was created by the current transaction and is owned by that worker.

getSecurityCache

public SecurityCache getSecurityCache()

associateAndSyncLog

public void associateAndSyncLog(Log log,
                                TransactionID tid)
Associates the given log with this worker's transaction manager and synchronizes the log with the given tid.