com.sun.jini.outrigger
Class TxnState

java.lang.Object
  extended by com.sun.jini.outrigger.TxnState

 class TxnState
extends Object

Class that manages transaction related state on behalf of EntryHandles. Can accommodate entries locked by more than one transaction. The synchronization of this object is managed by the EntryHandle that owns it.

Author:
Sun Microsystems, Inc.
See Also:
EntryHandle

Field Summary
private  EntryHolder holder
          The holder the handle which owns this object is in
private static Logger matchingLogger
          Logger for logging information about entry matching
private  Object mgrs
          The list of known managers.
private  TransactableMgr[] rslt
          Used by mgr()
private  int state
          The current state of the handle, such as READ or TAKE.
private static Logger txnLogger
          Logger for logging transaction related information
 
Constructor Summary
TxnState(TransactableMgr mgr, int state, EntryHolder holder)
          Create a new TxnState.
 
Method Summary
(package private)  boolean abort(TransactableMgr mgr, OutriggerServerImpl space, EntryHandle owner)
          Abort this object's part of the transaction.
(package private)  void add(TransactableMgr mgr, int op)
          Add mgr to the list of known managers, setting the state of this handle to op.
(package private)  void addTxns(Collection collection)
          Add all the managers of this transaction to the given collection.
(package private)  boolean canPerform(TransactableMgr mgr, int op)
          Returns true if the operation op under the transaction manager by mgr is legal on the associated entry given the operations already performed on the entry under other transactions.
(package private)  boolean commit(TransactableMgr mgr, OutriggerServerImpl space, EntryHandle owner)
          Commit this object's part of the transaction.
(package private)  boolean empty()
          Return true if there are no more transactions associated with this object.
(package private)  boolean knownMgr(TransactableMgr mgr)
          Return true if mgr is one of the managers known to be managing this entry.
private  TransactableMgr mgr()
          Returns the one manager associated with this transaction.
private  void monitor(TransactableMgr mgr)
          If we need to, add this manager to the list of transactions that need to be monitored because of conflicts over this entry.
(package private)  boolean onlyMgr(TransactableMgr mgr)
          Return true if the given manager is the only one we know about.
(package private)  int prepare(TransactableMgr mgr, OutriggerServerImpl space, EntryHandle owner)
          Prepare to commit this object's part of the transaction.
(package private)  boolean promoteToTakeIfNeeded()
          It this entry is read locked promote to take locked and return true, otherwise return false.
private  int removeMgr(TransactableMgr mgr)
          Remove the given mgr from the list of known managers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mgrs

private Object mgrs
The list of known managers. In order to keep things small in the common case that there is only one known manager, mgrs is managed as a ``list'' in one of two states -- it is either a direct reference to the only manager for this handle, or a reference to an HashSet with entries for each associated manager.


state

private int state
The current state of the handle, such as READ or TAKE.


holder

private final EntryHolder holder
The holder the handle which owns this object is in


matchingLogger

private static final Logger matchingLogger
Logger for logging information about entry matching


txnLogger

private static final Logger txnLogger
Logger for logging transaction related information


rslt

private final TransactableMgr[] rslt
Used by mgr()

Constructor Detail

TxnState

TxnState(TransactableMgr mgr,
         int state,
         EntryHolder holder)
Create a new TxnState. It will start initially with the type of lock indicated by state under the transaction managed by mgr. holder is the holder the associated entry handle is in.

Method Detail

prepare

int prepare(TransactableMgr mgr,
            OutriggerServerImpl space,
            EntryHandle owner)
Prepare to commit this object's part of the transaction. Return the prepare's status.


abort

boolean abort(TransactableMgr mgr,
              OutriggerServerImpl space,
              EntryHandle owner)
Abort this object's part of the transaction. Return true if this clears the last transaction associated with this object.


commit

boolean commit(TransactableMgr mgr,
               OutriggerServerImpl space,
               EntryHandle owner)
Commit this object's part of the transaction. The space is the OutriggerServerImpl on which the operation happens -- some commit operations have space-wide side effects (for example, a commit of a write operation can cause event notifications for clients registered under the transaction's parent). Return true if this clears the last transaction associated with this object.


removeMgr

private int removeMgr(TransactableMgr mgr)
Remove the given mgr from the list of known managers. Return the number of mgrs still associated with this entry.


add

void add(TransactableMgr mgr,
         int op)
Add mgr to the list of known managers, setting the state of this handle to op.


monitor

private void monitor(TransactableMgr mgr)
If we need to, add this manager to the list of transactions that need to be monitored because of conflicts over this entry. Any existing blocking txn is sufficient.

See Also:
TxnMonitorTask.addSibling(com.sun.jini.outrigger.Txn)

promoteToTakeIfNeeded

boolean promoteToTakeIfNeeded()
It this entry is read locked promote to take locked and return true, otherwise return false. Assumes the take is being performed under the one transaction that owns a lock on the entry.


canPerform

boolean canPerform(TransactableMgr mgr,
                   int op)
Returns true if the operation op under the transaction manager by mgr is legal on the associated entry given the operations already performed on the entry under other transactions. It is legal to: All other operations are not legal, so canPerform otherwise returns false.


knownMgr

boolean knownMgr(TransactableMgr mgr)
Return true if mgr is one of the managers known to be managing this entry.


onlyMgr

boolean onlyMgr(TransactableMgr mgr)
Return true if the given manager is the only one we know about.


addTxns

void addTxns(Collection collection)
Add all the managers of this transaction to the given collection.


empty

boolean empty()
Return true if there are no more transactions associated with this object.


mgr

private TransactableMgr mgr()
Returns the one manager associated with this transaction. Throws an AssertionError if there is more or fewer than one manager associated with this transaction.



Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.