com.atomikos.icatch.imp
Class CoordinatorImp

java.lang.Object
  extended by com.atomikos.icatch.imp.CoordinatorImp
All Implemented Interfaces:
FSMEnterListener<TxState>, FSMPreEnterEventSource<TxState>, FSMPreEnterListener<TxState>, FSMTransitionListener<TxState>, Stateful<TxState>, CompositeCoordinator, Participant, RecoveryCoordinator, Recoverable, StateRecoverable<TxState>, AlarmTimerListener, Identifiable, Serializable, EventListener

public class CoordinatorImp
extends Object
implements CompositeCoordinator, Participant, RecoveryCoordinator, StateRecoverable<TxState>, AlarmTimerListener, Stateful<TxState>, FSMPreEnterListener<TxState>, FSMTransitionListener<TxState>, FSMEnterListener<TxState>

All things related to termination logic.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface com.atomikos.icatch.Participant
READ_ONLY
 
Constructor Summary
  CoordinatorImp()
          No argument constructor as required by Recoverable interface.
protected CoordinatorImp(String root, boolean heuristic_commit, boolean checkorphans)
          Constructor for testing only.
  CoordinatorImp(String root, RecoveryCoordinator coord, boolean heuristic_commit, boolean checkorphans)
          Constructor.
protected CoordinatorImp(String root, RecoveryCoordinator coord, boolean heuristic_commit, long timeout, boolean checkorphans, boolean single_threaded_2pc)
          Constructor.
 
Method Summary
 void addFSMEnterListener(FSMEnterListener l, TxState state)
           
 void addFSMPreEnterListener(FSMPreEnterListener l, TxState state)
           
 RecoveryCoordinator addParticipant(Participant participant)
           
 void alarm(AlarmTimer timer)
           
 HeuristicMessage[] commit(boolean onePhase)
           
 HeuristicMessage[] commitHeuristically()
           
protected  void dispose()
           
 void entered(FSMEnterEvent<TxState> e)
           
 void forget()
           
 String getCoordinatorId()
           
 TxState[] getFinalStates()
          Needed by the Recovery system to determine when a logged state can be forgotten.
 HeuristicMessage[] getHeuristicMessages()
          Get the heuristic info for the message round.
 HeuristicMessage[] getHeuristicMessages(Object heuristicState)
          Gets the heuristic messages for all participants that are in the given heuristic state
 Object getId()
           
 ObjectImage getObjectImage()
          Get an object image for this instance.
 ObjectImage getObjectImage(TxState state)
          Get an object image for the given state.
 Participant getParticipant()
           
 TxState[] getRecoverableStates()
          Get the states that should be recoverable.
 RecoveryCoordinator getRecoveryCoordinator()
           
 TxState getState()
           
 TxState getStateWithTwoPhaseCommitDecision()
           
 HeuristicMessage[] getTags()
          Get the heuristic tags for this coordinator.
protected  long getTimeOut()
           
 String getURI()
           
protected  void incLocalSiblingCount()
          Called when a tx import is being done.
 boolean isCommitted()
          Tests if the transaction was committed or not.
 Boolean isRecoverableWhileActive()
           
 void preEnter(FSMEnterEvent<TxState> event)
           
 int prepare()
           
 boolean recover()
           
 Boolean replayCompletion(Participant participant)
           
protected  void restore(ObjectImage image)
          Help function for restoration.
 HeuristicMessage[] rollback()
           
 HeuristicMessage[] rollbackHeuristically()
           
 void setCascadeList(Dictionary allParticipants)
           
 void setGlobalSiblingCount(int count)
           
 void setRecoverableWhileActive()
           
protected  void startThreads(long timeout)
          Start threads, propagator and timer logic.
protected  void terminate(boolean commit)
          Terminate the work, on behalf of Terminator.
 void transitionPerformed(FSMTransitionEvent<TxState> e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CoordinatorImp

protected CoordinatorImp(String root,
                         boolean heuristic_commit,
                         boolean checkorphans)
Constructor for testing only.


CoordinatorImp

protected CoordinatorImp(String root,
                         RecoveryCoordinator coord,
                         boolean heuristic_commit,
                         long timeout,
                         boolean checkorphans,
                         boolean single_threaded_2pc)
Constructor.

Parameters:
root - The root tid.
coord - The RecoverCoordinator, null if root.
console - The console to log to, or null if none.
heuristic_commit - Whether to do commit on heuristic.
timeout - The timeout in milliseconds for indoubts before a heuristic decision is made.
checkorphans - If true, orphan checks are made on prepare. For OTS, this is false.
single_threaded_2pc - If true then commit is done in the same thread as the one that started the tx.

CoordinatorImp

public CoordinatorImp(String root,
                      RecoveryCoordinator coord,
                      boolean heuristic_commit,
                      boolean checkorphans)
Constructor.

Parameters:
root - The root String for this one.
console - The console to log to, or null if none.
coord - The recovery coordinator for indoubt resolution.
heuristic_commit - If true, heuristic decision is commit.
checkorphans - If true, orphan checking is done at prepare.

CoordinatorImp

public CoordinatorImp()
No argument constructor as required by Recoverable interface.

Method Detail

isRecoverableWhileActive

public Boolean isRecoverableWhileActive()
Specified by:
isRecoverableWhileActive in interface CompositeCoordinator

getHeuristicMessages

public HeuristicMessage[] getHeuristicMessages(Object heuristicState)
Gets the heuristic messages for all participants that are in the given heuristic state

Parameters:
heuristicState - The heuristic state, or the terminated state.
Returns:
HeuristicMessage[] The heuristic messages of all participants in the given state, or an empty array if none.

isCommitted

public boolean isCommitted()
Tests if the transaction was committed or not.

Returns:
boolean True iff committed.

getHeuristicMessages

public HeuristicMessage[] getHeuristicMessages()
Get the heuristic info for the message round.

Specified by:
getHeuristicMessages in interface Participant
Returns:
HeuristicMessages[] The heuristic messages, or an empty array if none.

getTags

public HeuristicMessage[] getTags()
Get the heuristic tags for this coordinator. This info is returned to remote client TMs by a Participant proxy.

Specified by:
getTags in interface CompositeCoordinator

startThreads

protected void startThreads(long timeout)
Start threads, propagator and timer logic. Needed on construction AND by replay request events: timers have stopped by then!

Parameters:
timeout - The timeout for the thread wakeup interval.
console - The console, null if none.

getTimeOut

protected long getTimeOut()

getState

public TxState getState()
Specified by:
getState in interface Stateful<TxState>
See Also:
Stateful

addFSMEnterListener

public void addFSMEnterListener(FSMEnterListener l,
                                TxState state)
See Also:
FSMEnterEventSource.

addFSMPreEnterListener

public void addFSMPreEnterListener(FSMPreEnterListener l,
                                   TxState state)
Specified by:
addFSMPreEnterListener in interface FSMPreEnterEventSource<TxState>

getRecoveryCoordinator

public RecoveryCoordinator getRecoveryCoordinator()
Specified by:
getRecoveryCoordinator in interface CompositeCoordinator
See Also:
CompositeCoordinator.

getParticipant

public Participant getParticipant()
                           throws UnsupportedOperationException
Throws:
UnsupportedOperationException
See Also:
CompositeCoordinator.

getCoordinatorId

public String getCoordinatorId()
Specified by:
getCoordinatorId in interface CompositeCoordinator
See Also:
CompositeCoordinator

addParticipant

public RecoveryCoordinator addParticipant(Participant participant)
                                   throws SysException,
                                          IllegalStateException,
                                          RollbackException
Throws:
SysException
IllegalStateException
RollbackException

incLocalSiblingCount

protected void incLocalSiblingCount()
Called when a tx import is being done.


preEnter

public void preEnter(FSMEnterEvent<TxState> event)
              throws IllegalStateException
Specified by:
preEnter in interface FSMPreEnterListener<TxState>
Throws:
IllegalStateException
See Also:
FSMPreEnterListener.

getURI

public String getURI()
Specified by:
getURI in interface Participant
Specified by:
getURI in interface RecoveryCoordinator
See Also:
Participant

recover

public boolean recover()
                throws SysException
Specified by:
recover in interface Participant
Throws:
SysException
See Also:
Participant

forget

public void forget()
Specified by:
forget in interface Participant
See Also:
Participant.

setCascadeList

public void setCascadeList(Dictionary allParticipants)
                    throws SysException
Specified by:
setCascadeList in interface Participant
Throws:
SysException
See Also:
Participant.

setGlobalSiblingCount

public void setGlobalSiblingCount(int count)
Specified by:
setGlobalSiblingCount in interface Participant
See Also:
Participant.

prepare

public int prepare()
            throws RollbackException,
                   IllegalStateException,
                   HeurHazardException,
                   HeurMixedException,
                   SysException
Specified by:
prepare in interface Participant
Throws:
RollbackException
IllegalStateException
HeurHazardException
HeurMixedException
SysException
See Also:
Participant.

commit

public HeuristicMessage[] commit(boolean onePhase)
                          throws HeurRollbackException,
                                 HeurMixedException,
                                 HeurHazardException,
                                 IllegalStateException,
                                 RollbackException,
                                 SysException
Specified by:
commit in interface Participant
Throws:
HeurRollbackException
HeurMixedException
HeurHazardException
IllegalStateException
RollbackException
SysException
See Also:
Participant.

rollback

public HeuristicMessage[] rollback()
                            throws HeurCommitException,
                                   HeurMixedException,
                                   SysException,
                                   HeurHazardException,
                                   IllegalStateException
Specified by:
rollback in interface Participant
Throws:
HeurCommitException
HeurMixedException
SysException
HeurHazardException
IllegalStateException
See Also:
Participant.

rollbackHeuristically

public HeuristicMessage[] rollbackHeuristically()
                                         throws HeurCommitException,
                                                HeurMixedException,
                                                SysException,
                                                HeurHazardException,
                                                IllegalStateException
Throws:
HeurCommitException
HeurMixedException
SysException
HeurHazardException
IllegalStateException

commitHeuristically

public HeuristicMessage[] commitHeuristically()
                                       throws HeurMixedException,
                                              SysException,
                                              HeurRollbackException,
                                              HeurHazardException,
                                              IllegalStateException,
                                              RollbackException
Throws:
HeurMixedException
SysException
HeurRollbackException
HeurHazardException
IllegalStateException
RollbackException

replayCompletion

public Boolean replayCompletion(Participant participant)
                         throws IllegalStateException
Specified by:
replayCompletion in interface RecoveryCoordinator
Throws:
IllegalStateException
See Also:
RecoveryCoordinator.

restore

protected void restore(ObjectImage image)
Help function for restoration.


getObjectImage

public ObjectImage getObjectImage()
Description copied from interface: Recoverable
Get an object image for this instance. Allows later reconstruction of the instance.

Specified by:
getObjectImage in interface Recoverable
See Also:
Recoverable

getObjectImage

public ObjectImage getObjectImage(TxState state)
Description copied from interface: StateRecoverable
Get an object image for the given state.

Specified by:
getObjectImage in interface StateRecoverable<TxState>
Parameters:
state - The state about to be reached. Because the instance is not yet IN the new state, this state is supplied as a parameter.
Returns:
ObjectImage The image, or null to override the recoverability preference. In other words, if null is returned that logging is not done for the given state, even if the state was returned as one of the recoverable states.
See Also:
StateRecoverable

getRecoverableStates

public TxState[] getRecoverableStates()
Description copied from interface: StateRecoverable
Get the states that should be recoverable.

Specified by:
getRecoverableStates in interface StateRecoverable<TxState>
Returns:
Object[] An array of states that are meant to be recoverable. For efficiency, this should also include a state where the logimage is forgettable!
See Also:
StateRecoverable

getFinalStates

public TxState[] getFinalStates()
Description copied from interface: StateRecoverable
Needed by the Recovery system to determine when a logged state can be forgotten. If the instance reaches one of these states, then it will no longer be recoverable.

Specified by:
getFinalStates in interface StateRecoverable<TxState>
Returns:
Object[] The list of final states.
See Also:
StateRecoverable

getId

public Object getId()
Specified by:
getId in interface Identifiable
See Also:
Recoverable

alarm

public void alarm(AlarmTimer timer)
Specified by:
alarm in interface AlarmTimerListener

dispose

protected void dispose()

terminate

protected void terminate(boolean commit)
                  throws HeurRollbackException,
                         HeurMixedException,
                         SysException,
                         SecurityException,
                         HeurCommitException,
                         HeurHazardException,
                         RollbackException,
                         IllegalStateException
Terminate the work, on behalf of Terminator.

Parameters:
commit - True iff commit termination is asked.
Throws:
HeurRollbackException
HeurMixedException
SysException
SecurityException
HeurCommitException
HeurHazardException
RollbackException
IllegalStateException

setRecoverableWhileActive

public void setRecoverableWhileActive()
                               throws UnsupportedOperationException
Specified by:
setRecoverableWhileActive in interface CompositeCoordinator
Throws:
UnsupportedOperationException

getStateWithTwoPhaseCommitDecision

public TxState getStateWithTwoPhaseCommitDecision()

transitionPerformed

public void transitionPerformed(FSMTransitionEvent<TxState> e)
Specified by:
transitionPerformed in interface FSMTransitionListener<TxState>

entered

public void entered(FSMEnterEvent<TxState> e)
Specified by:
entered in interface FSMEnterListener<TxState>


Copyright © 2014. All Rights Reserved.