setlock Operation Example
Example 1.5. Simple Concurrency Control public boolean op1 (...) { if (setlock (new Lock(LockMode.WRITE) == LockResult.GRANTED) { // actual state change operations follow ... } } Procedure 1.1. Steps followed by the operation setlock The operation setlock, provided by the LockManager class, performs the following functions in Example 1.5, “Simple Concurrency Control�. Check write lock compatibility with the currently held locks, and if allowed, continue. Call the StateManager operation activate.activate will load, if not done already, the latest persistent state of O from the object store, then call the StateManager operation modified, which has the effect of creating an instance of either RecoveryRecord or PersistenceRecord for O, depending upon whether O was persistent or not. The Lock is a WRITE lock so the old state of the object must be retained prior to modification. The record is then inserted into the RecordList of Trans. Create and insert a LockRecord instance in the RecordList of Trans. Now suppose that action Trans is aborted sometime after the lock has been acquired. Then the rollback operation of AtomicAction will process the RecordList instance associated with Trans by invoking an appropriate Abort operation on the various records. The implementation of this operation by the LockRecord class will release the WRITE lock while that of RecoveryRecord or PersistenceRecord will restore the prior state of O. It is important to realize that all of the above work is automatically being performed by TxCore on behalf of the application programmer. The programmer need only start the transaction and set an appropriate lock; TxCore and TXOJ take care of participant registration, persistence, concurrency control and recovery.