Package com.iizix.txp.impl
Class TXPCoordinatorImpl
- java.lang.Object
- com.iizix.txp.impl.TXPCoordinatorImpl
- All Implemented Interfaces:
ITXPCoordinator
,ITXPMonitor
public class TXPCoordinatorImpl extends java.lang.Object implements ITXPCoordinator
Basic and crude (for now)ITXPCoordinator
implementation- Author:
- Freggle
Constructor Summary
Constructors Constructor Description TXPCoordinatorImpl()
Constructs aTXPCoordinatorImpl
instance with the default policyTXPCoordinatorImpl(ITXPPolicy policy)
Constructs aTXPCoordinatorImpl
instance with the specified policy
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMonitor(ITXPMonitor monitor)
Adds the specified TXP monitor.void
commit(ITXProcess process)
Called by the process to signal that the process logic/application requests a commit.ITXPCoordinator
getCoordinator()
Returns the coordinatorITXProcess
newProcess()
Creates a new implementation specificITXProcess
instance and sets itself as coordinator.void
onBeganProcess(ITXProcess process)
Called when a process created and associated with he controllervoid
onCommitCanceled(ITXProcess process, TXPException reason)
Called when the process aborts committing.void
onCommitInitiated(ITXProcess process)
Called when a process is called to attempt a commitvoid
onMonitorAdded(ITXPMonitor monitor)
Called when a monitor is added to the coordinator's monitor chainvoid
onMonitorRemoved(ITXPMonitor monitor)
Called when a monitor is removed from the coordinator's monitor chainvoid
onNodeAssociated(ITXProcess process, ITXPNode node, ITXPNode.State returnedState)
Called when a node is associated with a processvoid
onNodeCommitFailedPolicyAction(ITXProcess process, ITXPNode node, ITXPPolicy.Action action)
Called when the policy action is determined for a node that failed to commitvoid
onNodeDisassociated(ITXProcess process, ITXPNode node)
Called when a node is disassociated from a processvoid
onNodeReady(ITXProcess process, ITXPNode node, ITXPNode.State returnedState)
Called when a node has finished doing the work neededvoid
onNodeReadyFailedPolicyAction(ITXProcess process, ITXPNode node, ITXPPolicy.Action action)
Called when the policy action is determined for a node that failed processingvoid
onNodeRollbackFailedPolicyAction(ITXProcess process, ITXPNode node, ITXPPolicy.Action action)
Called when the policy action is determined for a node that failed to rollbackvoid
onNodeTimeoutSignaled(ITXProcess process, ITXPNode node)
Called when a node indicates it timed out waiting on the process.void
onNodeTimeoutSignaledPolicyAction(ITXProcess process, ITXPNode node, ITXPPolicy.Action action)
Called when the policy action is determined for a node that timed out waiting for completion.void
onProcessCompleted(ITXProcess process)
Called when a process has been completed (either committed or rolled back)void
onProcessCreated(ITXProcess process)
Called when the process is created.void
onProcessTimeoutSignaled(ITXProcess process)
Called when a process indicates it timed out waiting on the nodesvoid
onProcessTimeoutSignaledPolicyAction(ITXProcess process, ITXPPolicy.Action action)
Called when the policy action is determined for a process that timed out waiting for the nodes to do the work.void
onRollbackCanceled(ITXProcess process, TXPException reason)
Called when the process aborts rolling back.void
onRollbackInitiated(ITXProcess process)
Called when a process is called to attempt a rollbackvoid
ready(ITXProcess process, ITXPNode node, ITXPNode.State nodeState)
Called by the process to signal that a node is ready for completion.void
removeMonitor(ITXPMonitor monitor)
Removes the specified TXP monitor.void
rollback(ITXProcess process)
Called by the process to signal that the process logic/application requests a rollback.void
setLogger(ITXPLogger logger)
Sets the logger.
Constructor Detail
TXPCoordinatorImpl
public TXPCoordinatorImpl()
Constructs aTXPCoordinatorImpl
instance with the default policy
TXPCoordinatorImpl
public TXPCoordinatorImpl(ITXPPolicy policy)
Constructs aTXPCoordinatorImpl
instance with the specified policy- Parameters:
policy
- the policy to use
Method Detail
setLogger
public void setLogger(ITXPLogger logger)
Sets the logger.- Parameters:
logger
- The new logger instance.
newProcess
public ITXProcess newProcess()
Description copied from interface:ITXPCoordinator
Creates a new implementation specificITXProcess
instance and sets itself as coordinator.- Specified by:
newProcess
in interfaceITXPCoordinator
- Returns:
- an
ITXProcess
instance
ready
public void ready(ITXProcess process, ITXPNode node, ITXPNode.State nodeState)
Description copied from interface:ITXPCoordinator
Called by the process to signal that a node is ready for completion. Typically the coordinator handles error states that may occur using a policy.- Specified by:
ready
in interfaceITXPCoordinator
- Parameters:
process
- the processnode
- the nodenodeState
- the current state of the node
commit
public void commit(ITXProcess process) throws TXPException
Description copied from interface:ITXPCoordinator
Called by the process to signal that the process logic/application requests a commit. Typically the coordinator coordinates the commit and handles error states that may occur using a policy.- Specified by:
commit
in interfaceITXPCoordinator
- Parameters:
process
- the process- Throws:
TXPException
- a coordinator and policy dependent exception (today 1 of 3, more details later)
rollback
public void rollback(ITXProcess process) throws TXPException
Description copied from interface:ITXPCoordinator
Called by the process to signal that the process logic/application requests a rollback. Typically the coordinator coordinates the commit and handles error states that may occur using a policy.- Specified by:
rollback
in interfaceITXPCoordinator
- Parameters:
process
- the process- Throws:
TXPException
- a coordinator and policy dependent exception (today 1 of 3, more details later)
addMonitor
public void addMonitor(ITXPMonitor monitor)
Description copied from interface:ITXPCoordinator
Adds the specified TXP monitor. Monitors can be used for logging and monitoring processes under this coordinator's control.- Specified by:
addMonitor
in interfaceITXPCoordinator
- Parameters:
monitor
- the monitor
removeMonitor
public void removeMonitor(ITXPMonitor monitor)
Description copied from interface:ITXPCoordinator
Removes the specified TXP monitor.- Specified by:
removeMonitor
in interfaceITXPCoordinator
- Parameters:
monitor
- The monitor.
getCoordinator
public ITXPCoordinator getCoordinator()
Description copied from interface:ITXPMonitor
Returns the coordinator- Specified by:
getCoordinator
in interfaceITXPMonitor
- Returns:
- the coordinator
onMonitorAdded
public void onMonitorAdded(ITXPMonitor monitor)
Description copied from interface:ITXPMonitor
Called when a monitor is added to the coordinator's monitor chain- Specified by:
onMonitorAdded
in interfaceITXPMonitor
- Parameters:
monitor
- the monitor that got added
onMonitorRemoved
public void onMonitorRemoved(ITXPMonitor monitor)
Description copied from interface:ITXPMonitor
Called when a monitor is removed from the coordinator's monitor chain- Specified by:
onMonitorRemoved
in interfaceITXPMonitor
- Parameters:
monitor
- the monitor that got removed
onBeganProcess
public void onBeganProcess(ITXProcess process)
Description copied from interface:ITXPMonitor
Called when a process created and associated with he controller- Specified by:
onBeganProcess
in interfaceITXPMonitor
- Parameters:
process
- the process
onNodeAssociated
public void onNodeAssociated(ITXProcess process, ITXPNode node, ITXPNode.State returnedState)
Description copied from interface:ITXPMonitor
Called when a node is associated with a process- Specified by:
onNodeAssociated
in interfaceITXPMonitor
- Parameters:
process
- the processnode
- the nodereturnedState
- the returned node state
onNodeDisassociated
public void onNodeDisassociated(ITXProcess process, ITXPNode node)
Description copied from interface:ITXPMonitor
Called when a node is disassociated from a process- Specified by:
onNodeDisassociated
in interfaceITXPMonitor
- Parameters:
process
- the processnode
- the node
onNodeReady
public void onNodeReady(ITXProcess process, ITXPNode node, ITXPNode.State returnedState)
Description copied from interface:ITXPMonitor
Called when a node has finished doing the work needed- Specified by:
onNodeReady
in interfaceITXPMonitor
- Parameters:
process
- the processnode
- the nodereturnedState
- the node state after attempting to do the work
onNodeTimeoutSignaled
public void onNodeTimeoutSignaled(ITXProcess process, ITXPNode node)
Description copied from interface:ITXPMonitor
Called when a node indicates it timed out waiting on the process.- Specified by:
onNodeTimeoutSignaled
in interfaceITXPMonitor
- Parameters:
process
- the processnode
- the node
onProcessTimeoutSignaled
public void onProcessTimeoutSignaled(ITXProcess process)
Description copied from interface:ITXPMonitor
Called when a process indicates it timed out waiting on the nodes- Specified by:
onProcessTimeoutSignaled
in interfaceITXPMonitor
- Parameters:
process
- the process
onCommitInitiated
public void onCommitInitiated(ITXProcess process)
Description copied from interface:ITXPMonitor
Called when a process is called to attempt a commit- Specified by:
onCommitInitiated
in interfaceITXPMonitor
- Parameters:
process
- the process
onCommitCanceled
public void onCommitCanceled(ITXProcess process, TXPException reason)
Description copied from interface:ITXPMonitor
Called when the process aborts committing. This can happen if a rollback is requested or one or more nodes have not yet finished processing.- Specified by:
onCommitCanceled
in interfaceITXPMonitor
- Parameters:
process
- the processreason
- the exception thrown by the commit
onRollbackInitiated
public void onRollbackInitiated(ITXProcess process)
Description copied from interface:ITXPMonitor
Called when a process is called to attempt a rollback- Specified by:
onRollbackInitiated
in interfaceITXPMonitor
- Parameters:
process
- the process
onRollbackCanceled
public void onRollbackCanceled(ITXProcess process, TXPException reason)
Description copied from interface:ITXPMonitor
Called when the process aborts rolling back. This can happen if one or more nodes have not yet finished processing.- Specified by:
onRollbackCanceled
in interfaceITXPMonitor
- Parameters:
process
- the processreason
- the exception thrown by the rollback
onNodeReadyFailedPolicyAction
public void onNodeReadyFailedPolicyAction(ITXProcess process, ITXPNode node, ITXPPolicy.Action action)
Description copied from interface:ITXPMonitor
Called when the policy action is determined for a node that failed processing- Specified by:
onNodeReadyFailedPolicyAction
in interfaceITXPMonitor
- Parameters:
process
- the processnode
- the nodeaction
- the policy action
onNodeCommitFailedPolicyAction
public void onNodeCommitFailedPolicyAction(ITXProcess process, ITXPNode node, ITXPPolicy.Action action)
Description copied from interface:ITXPMonitor
Called when the policy action is determined for a node that failed to commit- Specified by:
onNodeCommitFailedPolicyAction
in interfaceITXPMonitor
- Parameters:
process
- the processnode
- the nodeaction
- the action
onNodeRollbackFailedPolicyAction
public void onNodeRollbackFailedPolicyAction(ITXProcess process, ITXPNode node, ITXPPolicy.Action action)
Description copied from interface:ITXPMonitor
Called when the policy action is determined for a node that failed to rollback- Specified by:
onNodeRollbackFailedPolicyAction
in interfaceITXPMonitor
- Parameters:
process
- the processnode
- the nodeaction
- the action
onNodeTimeoutSignaledPolicyAction
public void onNodeTimeoutSignaledPolicyAction(ITXProcess process, ITXPNode node, ITXPPolicy.Action action)
Description copied from interface:ITXPMonitor
Called when the policy action is determined for a node that timed out waiting for completion.- Specified by:
onNodeTimeoutSignaledPolicyAction
in interfaceITXPMonitor
- Parameters:
process
- the processnode
- the nodeaction
- the action
onProcessTimeoutSignaledPolicyAction
public void onProcessTimeoutSignaledPolicyAction(ITXProcess process, ITXPPolicy.Action action)
Description copied from interface:ITXPMonitor
Called when the policy action is determined for a process that timed out waiting for the nodes to do the work.- Specified by:
onProcessTimeoutSignaledPolicyAction
in interfaceITXPMonitor
- Parameters:
process
- the processaction
- the action
onProcessCreated
public void onProcessCreated(ITXProcess process)
Description copied from interface:ITXPMonitor
Called when the process is created.- Specified by:
onProcessCreated
in interfaceITXPMonitor
- Parameters:
process
- The process.
onProcessCompleted
public void onProcessCompleted(ITXProcess process)
Description copied from interface:ITXPMonitor
Called when a process has been completed (either committed or rolled back)- Specified by:
onProcessCompleted
in interfaceITXPMonitor
- Parameters:
process
- The process.