org.openmdx.base.concurrent.locks
Class StateTransitions

java.lang.Object
  extended by org.openmdx.base.concurrent.locks.StateTransitions

public class StateTransitions
extends Object

State Transitions


Constructor Summary
StateTransitions(Enum initialState)
          Constructor
StateTransitions(Enum initial, String id, boolean debug)
          Constructor
 
Method Summary
 void assertState(Enum expected)
          Tests whether the expected Status matches the current one.
 void assertState(EnumSet expected)
          Tests whether the current Status value is among the expected ones.
 void awaitState(EnumSet stati, java.util.concurrent.locks.Condition event)
          Wait for one of a given set of states
 boolean awaitState(EnumSet stati, java.util.concurrent.locks.Condition event, long timeout)
          Wait for one of a given set of states
 Enum getState()
          Retrieve the state.
 void setState(java.util.concurrent.locks.Condition event, Enum state)
          Set the state
 void setState(Enum state)
          Set the state
 boolean stateMatches(Enum state)
          Test whether the current state matches a given one.
 boolean stateMatches(EnumSet stati)
          Test whether the current state matches a given one.
 String toString()
           
 void transition(Enum from, java.util.concurrent.locks.Condition event, Enum to)
          Change the state
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StateTransitions

public StateTransitions(Enum initialState)
Constructor

Parameters:
initialState - the initial state

StateTransitions

public StateTransitions(Enum initial,
                        String id,
                        boolean debug)
Constructor

Parameters:
initial -
id - the id used for log() and toString()
debug - tells whether logging is enabled
Method Detail

getState

public Enum getState()
Retrieve the state.

Returns:
the status's value

stateMatches

public boolean stateMatches(Enum state)
Test whether the current state matches a given one.

Returns:
true if the current state queals the given one.

stateMatches

public boolean stateMatches(EnumSet stati)
Test whether the current state matches a given one.

Returns:
true if the current state queals the given one.

setState

public void setState(Enum state)
Set the state

Parameters:
state - The status's value

setState

public final void setState(java.util.concurrent.locks.Condition event,
                           Enum state)
Set the state

Parameters:
event - the event leading to thei change in state
state - The status's value

assertState

public void assertState(Enum expected)
Tests whether the expected Status matches the current one.

Parameters:
expected - the expected Status
Throws:
IllegalStateException - if the expected Status does not match the current one

assertState

public void assertState(EnumSet expected)
Tests whether the current Status value is among the expected ones.

Parameters:
expected - the expected Status set
Throws:
IllegalStateException - if the current Status is not among the expected ones

transition

public void transition(Enum from,
                       java.util.concurrent.locks.Condition event,
                       Enum to)
Change the state

Parameters:
from -
event -
to -

awaitState

public boolean awaitState(EnumSet stati,
                          java.util.concurrent.locks.Condition event,
                          long timeout)
                   throws InterruptedException
Wait for one of a given set of states

Parameters:
stati - the status one is waiting for
condition - the condition leading to the awaited transition
timeout - the timeout in milliseconds
Returns:
true if one of the requested states has been reached; false if the method timed out.
Throws:
InterruptedException - if the thread is interrupted

awaitState

public void awaitState(EnumSet stati,
                       java.util.concurrent.locks.Condition event)
                throws InterruptedException
Wait for one of a given set of states

Parameters:
stati - the status one is waiting for
condition - the condition leading to the awaited transition
Throws:
InterruptedException - if the thread is interrupted

toString

public String toString()
Overrides:
toString in class Object


This software is published under the BSD license. Copyright © 2003-2007, OMEX AG, Switzerland, All rights reserved. Use is subject to license terms.