public class StateChangeSemaphore
extends java.lang.Object
This class is abstracted from concrete state change notification APIs so that
subclasses can be implemented as such listeners; they must call stateChangedNotify()
upon notification by the state machine.
| Constructor and Description |
|---|
StateChangeSemaphore(java.util.logging.Logger logger) |
| Modifier and Type | Method and Description |
|---|---|
void |
reset()
Resets the state change notification count.
|
protected void |
stateChangedNotify()
To be called from state change listener method of subclass.
|
void |
waitForStateChanges(int count)
Blocks until the specified number of state change notifications have been received
since last call to
reset(). |
public StateChangeSemaphore(java.util.logging.Logger logger)
protected void stateChangedNotify()
This call is expected to come from a different thread than the one that calls waitForStateChanges.
Both methods are synchronized, but there will not be a deadlock, since waitForStateChanges
yields ownership of the monitor when calling wait.
public void waitForStateChanges(int count)
throws java.lang.InterruptedException
reset().
Does not block at all if at least count state change notifications
have been received since the last call to reset. Otherwise only blocks until
the missing number of notifications has arrived.
Before returning, this method subtracts count from the internal counter for state change notifications,
which allows a client to catch up with fast firing event notifications by calling this method several times.
Note that the "synchronized" modifier is required in order for the client thread
to obtain ownership of this semaphore (i.e. its monitor),
without which the thread synchronization would not work.
See Object.notify() for an explanation.
count - number of state change notifications that must be received
since last call to reset()
so that this call will returnjava.lang.InterruptedExceptionpublic void reset()