org.hypergraphdb.peer.workflow
Class WorkflowState

java.lang.Object
  extended by org.hypergraphdb.peer.workflow.WorkflowState
Direct Known Subclasses:
WorkflowStateConstant

public class WorkflowState
extends java.lang.Object

Represents an activity's current state. The set of possible activity states is open-ended with a few predefined and recognized by the framework states. States are defined as symbolic constants through the makeStateConstant. A state constant is defined simply by giving it a name. Only one state constant is bound a given name and this is ensured by this class. To obtain the state constant corresponding to a given name use the toStateConstant method. To obtain a mutable state instance (usually associated with an activity), use the makeState.

State constants are implemented by the derived WorkflowStateConstant class which is intended to be used in Java final declarations only. Attempt to modify a state constant will result in an exception.

It is possible to track changes in a mutable state instance by registering a StateListener with it. Whenever the state changes, all listeners are invoked in the order in which they were added and all attempts to change the state are blocked while the listeners are being executed. So, a state listener can safely assume that the state remains constant while the listener is executing.

Predefined state constants must be used in implementations with the following defined semantics:

Author:
Borislav Iordanov

Field Summary
static WorkflowStateConstant Canceled
           
static WorkflowStateConstant Completed
           
static WorkflowStateConstant Failed
           
static WorkflowStateConstant Limbo
           
static WorkflowStateConstant Started
           
 
Method Summary
 void addListener(StateListener l)
           
 void assign(WorkflowStateConstant newState)
           Set a new state value.
 boolean compareAndAssign(WorkflowStateConstant oldState, WorkflowStateConstant newState)
           Moves to a new state (newState) if the current state is equal to a given state (oldState)
 boolean equals(java.lang.Object x)
           
 WorkflowStateConstant getConst()
          Return the state constant corresponding to the current state.
 int hashCode()
           
 boolean isCanceled()
           
 boolean isCompleted()
           
 boolean isFailed()
           
 boolean isFinished()
          Finished means it is either completed, failed or canceled.
 boolean isInLimbo()
           
 boolean isStarted()
           
static WorkflowState makeState()
          Return a new state initialized to Limbo.
static WorkflowState makeState(WorkflowStateConstant stateConstant)
          Return a new state initialized from the passed in state constant.
static WorkflowStateConstant makeStateConstant(java.lang.String name)
           Create a new custom state constant.
 void removeListener(StateListener l)
           
 void setCanceled()
           
 void setCompleted()
           
 void setFailed()
           
 void setStarted()
           
static WorkflowStateConstant toStateConstant(java.lang.String name)
          Return the state constant with the given name.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

Limbo

public static final WorkflowStateConstant Limbo

Started

public static final WorkflowStateConstant Started

Completed

public static final WorkflowStateConstant Completed

Failed

public static final WorkflowStateConstant Failed

Canceled

public static final WorkflowStateConstant Canceled
Method Detail

makeStateConstant

public static WorkflowStateConstant makeStateConstant(java.lang.String name)

Create a new custom state constant. The constants defined in this class represent states recognized by the framework and implementation are required to use them following their semantics. Additional intermediary states that an activity implementation may need however should be first declared as state constants through this method. State constants are maintained in a static constant pool where only one state constant with a given name may exist. This is unproblematic since states have only symbolic value and independently developed activities can safely share the same constant instances from the pool.


toStateConstant

public static WorkflowStateConstant toStateConstant(java.lang.String name)

Return the state constant with the given name. The method will throw an exception if there's no such constant.


makeState

public static WorkflowState makeState(WorkflowStateConstant stateConstant)

Return a new state initialized from the passed in state constant.


makeState

public static WorkflowState makeState()

Return a new state initialized to Limbo.


getConst

public WorkflowStateConstant getConst()

Return the state constant corresponding to the current state.


compareAndAssign

public boolean compareAndAssign(WorkflowStateConstant oldState,
                                WorkflowStateConstant newState)

Moves to a new state (newState) if the current state is equal to a given state (oldState)

Parameters:
oldState - The presumed current state.
newState - The new state.
Returns:
true if the change was made and false otherwise.
Throws:
an - exception if this is a state constant.

assign

public void assign(WorkflowStateConstant newState)

Set a new state value.

Parameters:
newState -
Throws:
an - exception if this is a state constant.

addListener

public void addListener(StateListener l)

removeListener

public void removeListener(StateListener l)

isInLimbo

public boolean isInLimbo()

isStarted

public boolean isStarted()

setStarted

public void setStarted()

isCompleted

public boolean isCompleted()

setCompleted

public void setCompleted()

isFailed

public boolean isFailed()

setFailed

public void setFailed()

isCanceled

public boolean isCanceled()

setCanceled

public void setCanceled()

isFinished

public boolean isFinished()

Finished means it is either completed, failed or canceled.


hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object x)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object