tp.impl
Class MyTM

java.lang.Object
  extended by tp.impl.CSEP545ServiceObject
      extended by tp.impl.MyTM
All Implemented Interfaces:
Remote, CSEP545Service, TM

public class MyTM
extends CSEP545ServiceObject
implements TM

Your Transaction Manager

A rudimentary implementation is provided for your convenience.


Nested Class Summary
 
Nested classes/interfaces inherited from interface tp.impl.CSEP545Service
CSEP545Service.Type
 
Field Summary
 
Fields inherited from class tp.impl.CSEP545ServiceObject
dir, registry, svcid
 
Constructor Summary
MyTM()
           
 
Method Summary
 void abort(Transaction xid)
          abort transaction
 void commit(Transaction xid)
          commit transaction
 boolean enlist(Transaction xid, String enlistingRM)
          enlist the RM as a member of this transaction
protected  void init(String[] args)
          IMPLEMENT THIS METHOD process command line parameters and setup any parameterized values.
protected  void initStorage()
          IMPLEMENT THIS METHOD Initialize necessary data files.
protected  void readyToServe()
          IMPLEMENT THIS METHOD Bootstrapping completed and the server is up and running.
protected  void recovery()
          IMPLEMENT THIS METHOD Run recovery algorithm and reconstruct the state of service before failure.
 void refresh()
          Refresh all remote references used by this service.
 void register(String rm)
          look up RMI registry to cache remote reference of RM represented by rm.
 void shutdown()
          Gracefully shutdown target service.
 Transaction start()
          start a new transaction
protected  void startUp()
          IMPLEMENT THIS METHOD If you use extra threads in your service, start them in this method.
 
Methods inherited from class tp.impl.CSEP545ServiceObject
getDataRoot, getServiceID, kill, lookupRemote, lookupRemote, lookupRemote, lookupRemote, main
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MyTM

public MyTM()
Method Detail

start

public Transaction start()
                  throws RemoteException
Description copied from interface: TM
start a new transaction

Specified by:
start in interface TM
Returns:
newly generated unique transaction context
Throws:
RemoteException
See Also:
WC.start()

commit

public void commit(Transaction xid)
            throws InvalidTransactionException,
                   TransactionAbortedException,
                   RemoteException
Description copied from interface: TM
commit transaction

Specified by:
commit in interface TM
Parameters:
xid - transaction identifier
Throws:
InvalidTransactionException
TransactionAbortedException
RemoteException
See Also:
WC.commit(Transaction)

abort

public void abort(Transaction xid)
           throws RemoteException
Description copied from interface: TM
abort transaction

Specified by:
abort in interface TM
Parameters:
xid - transaction identifier
Throws:
RemoteException
See Also:
WC.abort(Transaction)

enlist

public boolean enlist(Transaction xid,
                      String enlistingRM)
               throws TransactionAbortedException,
                      InvalidTransactionException,
                      RemoteException
Description copied from interface: TM
enlist the RM as a member of this transaction

Specified by:
enlist in interface TM
Parameters:
xid - transaction identifier
enlistingRM - RM to add to transaction identified by xid
Returns:
true when enlisted. false otherwise.
Throws:
TransactionAbortedException
InvalidTransactionException
RemoteException
See Also:
RM.getName()

register

public void register(String rm)
              throws RemoteException
look up RMI registry to cache remote reference of RM represented by rm. This makes easier to coordinate two-phase commit.

Specified by:
register in interface TM
Parameters:
rm - the name of RM to register
Throws:
RemoteException
See Also:
RM.getName()

shutdown

public void shutdown()
              throws RemoteException
Description copied from interface: CSEP545Service
Gracefully shutdown target service. On restart, the service should not need to recover its state. Please make sure to call Registry.unbind(String)

Specified by:
shutdown in interface CSEP545Service
Overrides:
shutdown in class CSEP545ServiceObject
Throws:
RemoteException
See Also:
Registry.unbind(String)

init

protected void init(String[] args)
             throws Exception
Description copied from class: CSEP545ServiceObject
IMPLEMENT THIS METHOD process command line parameters and setup any parameterized values. For example, setting self destruct counter should be done in this method.

Specified by:
init in class CSEP545ServiceObject
Parameters:
args - command line arguments except common arguments
Throws:
Exception

initStorage

protected void initStorage()
                    throws Exception
Description copied from class: CSEP545ServiceObject
IMPLEMENT THIS METHOD Initialize necessary data files. Invoked in two cases. For example, you can create database files for RM and commit log file for TM

Specified by:
initStorage in class CSEP545ServiceObject
Throws:
Exception

recovery

protected void recovery()
                 throws Exception
Description copied from class: CSEP545ServiceObject
IMPLEMENT THIS METHOD Run recovery algorithm and reconstruct the state of service before failure. This method is invoked when the data directory already exists. Note that if the service has been shutdown cleanly, calling this method should not affect the state.

Specified by:
recovery in class CSEP545ServiceObject
Throws:
Exception

startUp

protected void startUp()
                throws Exception
Description copied from class: CSEP545ServiceObject
IMPLEMENT THIS METHOD If you use extra threads in your service, start them in this method. For example, you can launch periodic deadlock-detector thread here. Or, any kinds of asynchronous taks such as timeout-retry, failure detector, etc.

Specified by:
startUp in class CSEP545ServiceObject
Throws:
Exception

readyToServe

protected void readyToServe()
                     throws Exception
Description copied from class: CSEP545ServiceObject
IMPLEMENT THIS METHOD Bootstrapping completed and the server is up and running.

Specified by:
readyToServe in class CSEP545ServiceObject
Throws:
Exception

refresh

public void refresh()
             throws RemoteException,
                    NotBoundException
Description copied from interface: CSEP545Service
Refresh all remote references used by this service. For easier automated testing recovery from failure.

Specified by:
refresh in interface CSEP545Service
Throws:
RemoteException
NotBoundException