Class 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 Detail

      • TXPCoordinatorImpl

        public TXPCoordinatorImpl()
        Constructs a TXPCoordinatorImpl instance with the default policy
      • TXPCoordinatorImpl

        public TXPCoordinatorImpl​(ITXPPolicy policy)
        Constructs a TXPCoordinatorImpl 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 specific ITXProcess instance and sets itself as coordinator.
        Specified by:
        newProcess in interface ITXPCoordinator
        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 interface ITXPCoordinator
        Parameters:
        process - the process
        node - the node
        nodeState - 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 interface ITXPCoordinator
        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 interface ITXPCoordinator
        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 interface ITXPCoordinator
        Parameters:
        monitor - the monitor
      • 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 interface ITXPMonitor
        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 interface ITXPMonitor
        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 interface ITXPMonitor
        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 interface ITXPMonitor
        Parameters:
        process - the process
        node - the node
        returnedState - 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 interface ITXPMonitor
        Parameters:
        process - the process
        node - 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 interface ITXPMonitor
        Parameters:
        process - the process
        node - the node
        returnedState - 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 interface ITXPMonitor
        Parameters:
        process - the process
        node - 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 interface ITXPMonitor
        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 interface ITXPMonitor
        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 interface ITXPMonitor
        Parameters:
        process - the process
        reason - 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 interface ITXPMonitor
        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 interface ITXPMonitor
        Parameters:
        process - the process
        reason - the exception thrown by the rollback
      • onProcessCreated

        public void onProcessCreated​(ITXProcess process)
        Description copied from interface: ITXPMonitor
        Called when the process is created.
        Specified by:
        onProcessCreated in interface ITXPMonitor
        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 interface ITXPMonitor
        Parameters:
        process - The process.