tppt.xopen
Class TransactionManager

java.lang.Object
  |
  +--tppt.xopen.TransactionManager
All Implemented Interfaces:
AX, TMInterface, TX

public class TransactionManager
extends java.lang.Object
implements TMInterface

This class implements the simple version of Transaction Manager in the two-phase commit protocol.

Version:
2.0
Author:
Jodie Wu
See Also:
TMInterface

Field Summary
private  TwoPhaseLogger logger
          The logger
private static int tid
          This variable stored the global transaction sequence.
private static TMInterface tm
          The Transaction Manager instance.
 
Fields inherited from interface tppt.xopen.TMInterface
runningTrans
 
Constructor Summary
TransactionManager()
          The constructor
 
Method Summary
 boolean ax_reg(int tid, ResourceManager rm)
          Register the ResourceManager for specified transaction.
private static TMInterface create()
          Create the TransactionManager instance if it has not been created.
 java.util.HashMap getRunningTransaction()
          Return all the registered transactions.
static TMInterface getTMInstance()
          Get the TransactionManager instance.
 int tx_begin()
          Application Program should call this method in order to obtain a global traansaction Id.
 boolean tx_close(int tid)
          Application Program should call this method to close the global trnsaction.
 boolean tx_commit(int tid)
          Application Program should call this method when it is ready to commit.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

tm

private static TMInterface tm
The Transaction Manager instance.

logger

private TwoPhaseLogger logger
The logger

tid

private static int tid
This variable stored the global transaction sequence.
Constructor Detail

TransactionManager

public TransactionManager()
The constructor
Method Detail

create

private static TMInterface create()
Create the TransactionManager instance if it has not been created. Here we need one and only one TransactionManager object, so we use the idea of Singleton design pattern. Use a static variable tm to store the instance. If tm is null, then create a new TransactionManager, return existing tm othereise.
Returns:
return the TransactionManager object.

getTMInstance

public static TMInterface getTMInstance()
Get the TransactionManager instance.
Returns:
return the transaction manager instance.
See Also:
TMInterface

getRunningTransaction

public java.util.HashMap getRunningTransaction()
Return all the registered transactions.
Specified by:
getRunningTransaction in interface TMInterface
Returns:
return the HashMap that stored all the registered Transaction.

tx_begin

public int tx_begin()
Application Program should call this method in order to obtain a global traansaction Id. This method might also initial the TransactionRecord for this new transaction and store it inside the runningTrans. This method is synchronized since more than one Application Program might be run at the same time.
Specified by:
tx_begin in interface TX
Returns:
the global transaction id.

tx_commit

public boolean tx_commit(int tid)
Application Program should call this method when it is ready to commit. This method should then perform two-phase commit protocol. The thing has to be done here are
   1. Phase one: Call xa_prepare() on all the registered RMs(cohorts) for the specified transaction.
   2. Phase two: All commit or all abort depends on the response from the cohorts.
      Call xa_commit() to commit the transaction for some RM.
      Call xa_rollback() to abort the transaction for some RM.
   3. Call the xa_close to close the connection & release the lock.
 
Specified by:
tx_commit in interface TX
Parameters:
tid - the id of transaction that want to commit.
Returns:
true if commit successfully; false otherwise.

tx_close

public boolean tx_close(int tid)
Application Program should call this method to close the global trnsaction. This method should remove this transaction record from the runningTrans HashMap.
Specified by:
tx_close in interface TX
Parameters:
tid - the global transaction id
Returns:
true if remove properly, false otherwise.

ax_reg

public boolean ax_reg(int tid,
                      ResourceManager rm)
Register the ResourceManager for specified transaction. This method is called by the ResourceManager that attempt to register itself for specific transaction.
Specified by:
ax_reg in interface AX
Parameters:
tid: - global transaction id
rid: - resource manager id
Returns:
true if register properly; false otherwise.