com.sun.jini.mahalo
Class TxnManagerTransaction

java.lang.Object
  extended by com.sun.jini.mahalo.TxnManagerTransaction
All Implemented Interfaces:
TimeConstants, LeasedResource, TransactionConstants

 class TxnManagerTransaction
extends Object
implements TransactionConstants, TimeConstants, LeasedResource

TxnManagerTransaction is a class which captures the internal representation of a transaction in the TxnManagerImpl server. This class is associated with a transaction id. The information encapsulated includes the list of participants which have joined the transaction, the state of the transaction, the crash. The user of a ParticipantHolder must make the association between an instance of a ParticipantHolder and some sort of key or index.

Author:
Sun Microsystems, Inc.

Field Summary
private  long expires
           
private  Job job
           
private  Object jobLock
          Interlock for Jobs is needed since many threads on behalf of many clients can simultaneously access or modify the Job associated with this transaction when when attempting to prepare, roll forward or roll back participants.
private  Object leaseLock
          Interlock for the expiration time since lease renewal which set it may compete against lease checks which read it.
private  LogManager logmgr
           
private static Logger operationsLogger
          Logger for operation related messages
private  List parts
           
(package private) static long serialVersionUID
           
private  TxnSettler settler
           
private  Object stateLock
          Interlock for transaction state needed since many threads on behalf of many clients can simultaneously access or attempt to modify this transaction's state as a side effect of calling commit or abort.
private static boolean[][] states
           
private  ServerTransaction str
           
private  TaskManager threadpool
          "Parallelizing" the interaction between the manager and participants means using threads to interact with participants on behalf of the manager.
private static Logger transactionsLogger
          Logger for transaction related messages
private  int trstate
           
private  Uuid uuid
           
private  WakeupManager wm
           
 
Fields inherited from interface net.jini.core.transaction.server.TransactionConstants
ABORTED, ACTIVE, COMMITTED, NOTCHANGED, PREPARED, VOTING
 
Fields inherited from interface com.sun.jini.constants.TimeConstants
DAYS, HOURS, MINUTES, SECONDS
 
Constructor Summary
TxnManagerTransaction(TransactionManager mgr, LogManager logmgr, long id, TaskManager threadpool, WakeupManager wm, TxnSettler settler, Uuid uuid)
          Constructs a TxnManagerTransaction
 
Method Summary
(package private)  void abort(long waitFor)
          Aborts the transaction.
(package private)  void add(ParticipantHandle handle)
          Convenience method which adds a given ParticipantHandle to the set of ParticpantHandles associated with this transaction.
(package private)  void commit(long waitFor)
          Commits the transaction.
private  void doAbort(long timeout)
           
(package private)  boolean ensureCurrent()
           
 Uuid getCookie()
          Returns the universally unique identifier associated with this lease.
 long getExpiration()
          Returns the expiration time of the lease.
private  String getParticipantInfo()
           
 int getState()
          This method returns the state of the transaction.
 Transaction getTransaction()
           
 void join(TransactionParticipant preparedPart, long crashCount)
          Implementation of the join method.
(package private)  void modifyParticipant(ParticipantHandle handle, int state)
          Convenience method which allows the caller to modify the prepState associated with a given ParticipantHandle
(package private)  boolean modifyTxnState(int state)
          Changes the manager-side state of the transaction.
private  Vector parthandles()
           
(package private)  void restoreTransientState(ProxyPreparer preparer)
           
 void setExpiration(long newExpiration)
          Changes the expiration time of the lease.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

states

private static final boolean[][] states

parts

private List parts

str

private final ServerTransaction str

trstate

private int trstate

expires

private long expires

logmgr

private LogManager logmgr

threadpool

private TaskManager threadpool
"Parallelizing" the interaction between the manager and participants means using threads to interact with participants on behalf of the manager. In the thread pool model, a TaskManager provides a finite set of threads used to accomplish a variety of tasks. A Job encapsulates a body of work which needs to be performed during the two-phase commit: preparing, committing and aborting. Each work item is broken into smaller pieces of work- interactions with a single participant- each assigned to a task. When a transaction is committing, a PrepareJob is created and its tasks are scheduled. After completion, the PrepareJob's outcome is computed. Depending on the outcome, either an AbortJob or CommitJob is scheduled. When a transaction is aborted, an AbortJob is scheduled. A caller may specify a timeout value for commit/abort. The timeout represents the length of time a caller is willing to wait for participants to be instructed to roll-forward/back. Should this timeout expire, a TimeoutExpiredException is thrown. This causes the caller's thread to return back to the caller. Someone needs to finish contacting all the participants. This is accomplished by the SettlerTask. SettlerTasks must use a different thread pool from what is used by the various Job types, otherwise deadlock will occur.


wm

private WakeupManager wm

settler

private TxnSettler settler

job

private Job job

uuid

private Uuid uuid

leaseLock

private Object leaseLock
Interlock for the expiration time since lease renewal which set it may compete against lease checks which read it.


jobLock

private Object jobLock
Interlock for Jobs is needed since many threads on behalf of many clients can simultaneously access or modify the Job associated with this transaction when when attempting to prepare, roll forward or roll back participants.


stateLock

private Object stateLock
Interlock for transaction state needed since many threads on behalf of many clients can simultaneously access or attempt to modify this transaction's state as a side effect of calling commit or abort.


operationsLogger

private static final Logger operationsLogger
Logger for operation related messages


transactionsLogger

private static final Logger transactionsLogger
Logger for transaction related messages

Constructor Detail

TxnManagerTransaction

TxnManagerTransaction(TransactionManager mgr,
                      LogManager logmgr,
                      long id,
                      TaskManager threadpool,
                      WakeupManager wm,
                      TxnSettler settler,
                      Uuid uuid)
Constructs a TxnManagerTransaction

Parameters:
mgr - TransactionManager which owns this internal representation.
logmgr - LogManager responsible for recording COMMITTED and ABORTED transactions to stable storage.
id - The transaction id
threadpool - The TaskManager which provides the pool of threads used to interact with participants.
settler - TxnSettler responsible for this transaction if unsettled.
Method Detail

add

void add(ParticipantHandle handle)
   throws InternalManagerException
Convenience method which adds a given ParticipantHandle to the set of ParticpantHandles associated with this transaction.

Parameters:
handle - The added handle
Throws:
InternalManagerException

modifyParticipant

void modifyParticipant(ParticipantHandle handle,
                       int state)
Convenience method which allows the caller to modify the prepState associated with a given ParticipantHandle

Parameters:
handle - The ParticipantHandle being modified
state - The new prepstate

modifyTxnState

boolean modifyTxnState(int state)
Changes the manager-side state of the transaction. This method makes only valid state changes and informs the caller if the change was successful. Calls to this method synchronize around the manager-side state variable appropriately.

Parameters:
state - the new desired state

join

public void join(TransactionParticipant preparedPart,
                 long crashCount)
          throws CannotJoinException,
                 CrashCountException,
                 RemoteException
Implementation of the join method.

Parameters:
preparedPart - The joining TransactionParticpant
crashCount - The crashcount associated with the joining TransactionParticipant
Throws:
CannotJoinException
CrashCountException
RemoteException
See Also:
TransactionParticipant

getState

public int getState()
This method returns the state of the transaction. Since the purpose of the set of ParticipantHolders is to associate a Transaction with a group of participants joined the transaction, we would like to get the state of the transaction associated with the aforementioned set.


commit

void commit(long waitFor)
      throws CannotCommitException,
             TimeoutExpiredException,
             RemoteException
Commits the transaction. This initiates the two-phase commit protocol. First, each net.jini.core.transaction.server.TransactionParticipant in the set of participants joined in the net.jini.core.transaction.server.Transaction is instructed to vote and the votes are tallied. This is the first phase (prepare phase). Depending on the outcome of the votes, the transaction is considered committed or aborted. Once commit/abort status is known, the participants are notified with a message to either roll-forward (commit case) or roll-back (abort case). This is the roll-phase. Since there may be a one-to-many relationship between a transaction and its participants, com.sun.jini.thread.TaskManagers are used as a generic mechanism to provide the threads needed to interact with the participants.

Throws:
CannotCommitException
TimeoutExpiredException
RemoteException

abort

void abort(long waitFor)
     throws CannotAbortException,
            TimeoutExpiredException
Aborts the transaction. This method attempts to set the state of the transaction to the ABORTED state. If successful, it then creates an AbortJob which schedules tasks executed on a thread pool. These tasks interact with the participants joined in this transaction to inform them to roll back.

Parameters:
waitFor - Timeout value which controls how long, the caller is willing to wait for the participants joined in the transaction to be instructed to roll-back.
Throws:
CannotAbortException
TimeoutExpiredException
See Also:
AbortJob, ParticipantTask, TaskManager, TransactionParticipant

getTransaction

public Transaction getTransaction()

getExpiration

public long getExpiration()
Description copied from interface: LeasedResource
Returns the expiration time of the lease.

Specified by:
getExpiration in interface LeasedResource
Returns:
The expiration time in milliseconds since the beginning of the epoch

setExpiration

public void setExpiration(long newExpiration)
Description copied from interface: LeasedResource
Changes the expiration time of the lease.

Specified by:
setExpiration in interface LeasedResource
Parameters:
newExpiration - The new expiration time in milliseconds since the beginning of the epoch

getCookie

public Uuid getCookie()
Description copied from interface: LeasedResource
Returns the universally unique identifier associated with this lease. Any proxies for this lease that implement ReferentUuid should return this object from their getReferentUuid method and should base their implementation of equals on this object.

Specified by:
getCookie in interface LeasedResource

doAbort

private void doAbort(long timeout)

ensureCurrent

boolean ensureCurrent()

parthandles

private Vector parthandles()

getParticipantInfo

private String getParticipantInfo()

restoreTransientState

void restoreTransientState(ProxyPreparer preparer)
                     throws RemoteException
Throws:
RemoteException


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