com.atomikos.icatch.imp
Class TransactionServiceImp

java.lang.Object
  extended by com.atomikos.icatch.imp.TransactionServiceImp
All Implemented Interfaces:
FSMEnterListener, RecoveryService, SubTxAwareParticipant, TransactionService, Serializable, EventListener

public class TransactionServiceImp
extends Object
implements TransactionService, FSMEnterListener, SubTxAwareParticipant, RecoveryService

General implementation of Transaction Service.

See Also:
Serialized Form

Constructor Summary
TransactionServiceImp(String name, StateRecoveryManager recoverymanager, UniqueIdMgr tidmgr, long maxtimeout, boolean checkorphans, int maxActives, boolean single_threaded_2pc)
          Create a new instance, with orphan checking set.
TransactionServiceImp(String name, StateRecoveryManager recoverymanager, UniqueIdMgr tidmgr, long maxtimeout, int maxActives, boolean single_threaded_2pc)
          Create a new instance, with orphan checking set.
 
Method Summary
 void addTSListener(TSListener listener)
          Adds a listener to the transaction service.
 void committed(CompositeTransaction tx)
          Called if a tx is ended successfully.
 CompositeTransaction createCompositeTransaction(long timeout)
          Starts a new transaction.
protected  String createTid()
          Create a new tid.
 void entered(FSMEnterEvent event)
          Called when the FSM has entered a new state.
 void finalize()
           
 CompositeCoordinator getCompositeCoordinator(String root)
          Gets a composite coordinator for the given root.
 CompositeTransaction getCompositeTransaction(String tid)
          Gets the composite transaction with the given tid.
protected  Object getLatch(String root)
          Get an object to lock for the given root.
 LogControl getLogControl()
          Get a LogControl for the service.
 String getName()
           
 Participant getParticipant(String root)
          Gets a participant handle for the given root.
protected  StateRecoveryManager getStateRecoveryManager()
          Get the state recovery manager.
 RecoveryCoordinator getSuperiorRecoveryCoordinator(String root)
          Gets the superior recovery coordinator for a given root.
 void init(Properties properties)
          Initializes the TM, and recovers.
 void recover()
          Asks the TM to recover.
protected  void recoverCoordinators()
          Recover instances from a given recovery manager.
 CompositeTransaction recreateCompositeTransaction(Propagation context, boolean orphancheck, boolean heur_commit)
          Recreates a composite transaction based on an imported context.
 void removeTSListener(TSListener listener)
          Removes a listener from the transaction service.
 void rolledback(CompositeTransaction tx)
          Called if a tx is ended with failure.
 void shutdown(boolean force)
          Shuts down the server in a clean way.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransactionServiceImp

public TransactionServiceImp(String name,
                             StateRecoveryManager recoverymanager,
                             UniqueIdMgr tidmgr,
                             long maxtimeout,
                             int maxActives,
                             boolean single_threaded_2pc)
Create a new instance, with orphan checking set.

Parameters:
name - The unique name of this TM.
recoverymanager - The recovery manager to use.
tidmgr - The String manager to use.
console - The console to use. Null if none.
maxtimeout - The max timeout for new or imported txs.
maxActives - The max number of active txs, or negative if unlimited.
single_threaded_2pc - Whether 2PC commit should happen in the same thread that started the tx.

TransactionServiceImp

public TransactionServiceImp(String name,
                             StateRecoveryManager recoverymanager,
                             UniqueIdMgr tidmgr,
                             long maxtimeout,
                             boolean checkorphans,
                             int maxActives,
                             boolean single_threaded_2pc)
Create a new instance, with orphan checking set.

Parameters:
name - The unique name of this TM.
recoverymanager - The recovery manager to use.
tidmgr - The String manager to use.
console - The console to use. Null if none.
maxtimeout - The max timeout for new or imported txs.
checkorphans - If false, orphan checking is disabled
maxActives - The max number of active txs, or negative if unlimited. even for creation requests that ask for checks. This mode may be needed for being compatible with certain configurations that do not support orphan detection.
single_threaded_2pc - Whether 2PC commit should happen in the same thread that started the tx.
Method Detail

getLatch

protected Object getLatch(String root)
Get an object to lock for the given root. To increase concurrency and still provide atomic operations within the scope of one root.

Returns:
Object The object to lock for the given root.

createTid

protected String createTid()
                    throws SysException
Create a new tid.

Returns:
String The newly created and unique identifier.
Throws:
SysException

getStateRecoveryManager

protected StateRecoveryManager getStateRecoveryManager()
Get the state recovery manager.

Returns:
StateRecoveryManager The recovery manager.

recoverCoordinators

protected void recoverCoordinators()
                            throws SysException
Recover instances from a given recovery manager.

Throws:
SysException - For unexpected failure.

getName

public String getName()
Specified by:
getName in interface RecoveryService
Returns:
String The unique name of the TM. Resources can use this name to determine what resource transactions need to be considered for recovery by this transaction service.

recover

public void recover()
Description copied from interface: RecoveryService
Asks the TM to recover. Resources should call this method whenever recovery is needed. The earliest time at which resources can call this method is when setRecoveryService is called on the resource. Note: resources that are registered before the TM starts up will not need to call this method. On the other hand, resources that are registered when the transaction service is already running should use this method to trigger recovery. It is up to the implementation of the resource to determine whether this is desirable.

Specified by:
recover in interface RecoveryService
See Also:
RecoveryService

getLogControl

public LogControl getLogControl()
Get a LogControl for the service.

Returns:
LogControl The instance.

getCompositeCoordinator

public CompositeCoordinator getCompositeCoordinator(String root)
                                             throws SysException
Description copied from interface: TransactionService
Gets a composite coordinator for the given root. Needed to allow TM to swap out instances after heuristic termination. If a commit, abort, forget or replay request comes in, this method should be called first to revive the instance.

Specified by:
getCompositeCoordinator in interface TransactionService
Parameters:
root - The root in case.
Returns:
The composite coordinator for this root.
Throws:
SysException
See Also:
TransactionService

addTSListener

public void addTSListener(TSListener listener)
                   throws IllegalStateException
Description copied from interface: TransactionService
Adds a listener to the transaction service. This method should be called before init! If called afterwards, only the init (false) callback will happen in the listener.

Specified by:
addTSListener in interface TransactionService
Parameters:
listener - The listener.
Throws:
IllegalStateException
See Also:
TransactionService

removeTSListener

public void removeTSListener(TSListener listener)
Description copied from interface: TransactionService
Removes a listener from the transaction service.

Specified by:
removeTSListener in interface TransactionService
Parameters:
listener - The listener.
See Also:
TransactionService

init

public void init(Properties properties)
          throws SysException
Description copied from interface: TransactionService
Initializes the TM, and recovers. Should be first method called.

Specified by:
init in interface TransactionService
Parameters:
properties - The properties used to initialize the system.
Throws:
SysException
See Also:
TransactionService

getParticipant

public Participant getParticipant(String root)
                           throws SysException
Description copied from interface: TransactionService
Gets a participant handle for the given root. This method is for subordinated coordinators: in those cases, a participant role is fulfilled w.r.t. parent coordinators.

Specified by:
getParticipant in interface TransactionService
Parameters:
root - The root identifier.
Returns:
Participant The participant instance.
Throws:
SysException - On failure, or if the given root is not known.
See Also:
TransactionService

entered

public void entered(FSMEnterEvent event)
Description copied from interface: FSMEnterListener
Called when the FSM has entered a new state.

Specified by:
entered in interface FSMEnterListener
See Also:
FSMEnterListener.

committed

public void committed(CompositeTransaction tx)
Called if a tx is ended successfully. In order to remove the tx from the mapping.

Specified by:
committed in interface SubTxAwareParticipant
Parameters:
tx - The composite transaction that has terminated locally at its node.
See Also:
SubTxAwareParticipant

rolledback

public void rolledback(CompositeTransaction tx)
Called if a tx is ended with failure. In order to remove tx from mapping.

Specified by:
rolledback in interface SubTxAwareParticipant
See Also:
SubTxAwareParticipant

getCompositeTransaction

public CompositeTransaction getCompositeTransaction(String tid)
Description copied from interface: TransactionService
Gets the composite transaction with the given tid.

Specified by:
getCompositeTransaction in interface TransactionService
Parameters:
tid - The transaction identifier.
Returns:
CompositeTransaction The transaction, or null if none.
See Also:
TransactionService

recreateCompositeTransaction

public CompositeTransaction recreateCompositeTransaction(Propagation context,
                                                         boolean orphancheck,
                                                         boolean heur_commit)
                                                  throws SysException
Description copied from interface: TransactionService
Recreates a composite transaction based on an imported context. Needed by the application's communication layer.

Specified by:
recreateCompositeTransaction in interface TransactionService
Parameters:
context - The propagation context. Any interposition actions should already have taken place, so that the propagation is ready to be used by the local transaction service.
orphancheck - If true, real composite transactions are done. If false, unchecked behavior applies.
heur_commit - True for heuristic commit, false for heuristic rollback.
Returns:
CompositeTransaction The recreated local instance.
Throws:
SysException
See Also:
TransactionService

shutdown

public void shutdown(boolean force)
              throws SysException,
                     IllegalStateException
Description copied from interface: TransactionService
Shuts down the server in a clean way.

Specified by:
shutdown in interface TransactionService
Parameters:
force - If true, shutdown will not wait for possibly indoubt txs to finish. Calling shutdown with force being true implies that shutdown will not fail, but there may be remaining timer threads that stay asleep until there timeouts expire. Such remaining active transactions will NOT be able to finish, because the recovery manager will be shutdown by that time. New transactions will not be allowed.
Throws:
SysException
IllegalStateException - If active transactions exist, and not force.
See Also:
TransactionService

finalize

public void finalize()
              throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

getSuperiorRecoveryCoordinator

public RecoveryCoordinator getSuperiorRecoveryCoordinator(String root)
Description copied from interface: TransactionService
Gets the superior recovery coordinator for a given root. Needed for imported transactions only.

Specified by:
getSuperiorRecoveryCoordinator in interface TransactionService
Parameters:
root - The root ID
Returns:
The recovery coordinator, or null if the root does not exist or if the root was not imported.
See Also:
TransactionService.getSuperiorRecoveryCoordinator(java.lang.String)

createCompositeTransaction

public CompositeTransaction createCompositeTransaction(long timeout)
                                                throws SysException
Description copied from interface: TransactionService
Starts a new transaction.

Specified by:
createCompositeTransaction in interface TransactionService
Returns:
CompositeTransaction The new instance.
Throws:
SysException


Copyright © 2012. All Rights Reserved.