cz.cuni.amis.utils.flag
Class WaitForFlagChange<TYPE>

java.lang.Object
  extended by cz.cuni.amis.utils.flag.WaitForFlagChange<TYPE>
Type Parameters:
TYPE -
Direct Known Subclasses:
WaitForAgentStateChange

public class WaitForFlagChange<TYPE>
extends java.lang.Object

This class is implementing the waiting on some flag value.

Note that you may call only one AWAIT() at time.

Typical usage:
boolean flagValue = new WaitForFlagChange<Boolean>(booleanFlag, Boolean.TRUE).await();
int flagValue = new WaitForFlagChange<Integer>(integerFlag, new Integer[]{1,3}).await();


Nested Class Summary
static interface WaitForFlagChange.IAccept<TYPE>
           
 
Constructor Summary
WaitForFlagChange(IFlag<TYPE> flag)
          Wait for the next flag change.
WaitForFlagChange(IFlag<TYPE> flag, java.util.Collection<TYPE> waitingFor)
           
WaitForFlagChange(IFlag<TYPE> flag, TYPE waitingFor)
           
WaitForFlagChange(IFlag<TYPE> flag, TYPE[] waitingFor)
           
WaitForFlagChange(IFlag<TYPE> flag, WaitForFlagChange.IAccept<TYPE> waitingFor)
           
 
Method Summary
 TYPE await()
          Note that you may call only await() from one thread! If the instance is already in used it may produce unwanted behavior (e.g.
 TYPE await(long timeout, java.util.concurrent.TimeUnit timeUnit)
          Note that you may call only await() from one thread! If the instance is already in used it may produce unwanted behavior.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WaitForFlagChange

public WaitForFlagChange(IFlag<TYPE> flag)
Wait for the next flag change.

Parameters:
flag -

WaitForFlagChange

public WaitForFlagChange(IFlag<TYPE> flag,
                         WaitForFlagChange.IAccept<TYPE> waitingFor)

WaitForFlagChange

public WaitForFlagChange(IFlag<TYPE> flag,
                         TYPE waitingFor)

WaitForFlagChange

public WaitForFlagChange(IFlag<TYPE> flag,
                         TYPE[] waitingFor)

WaitForFlagChange

public WaitForFlagChange(IFlag<TYPE> flag,
                         java.util.Collection<TYPE> waitingFor)
Method Detail

await

public TYPE await()
           throws PogamutInterruptedException
Note that you may call only await() from one thread! If the instance is already in used it may produce unwanted behavior (e.g. dead-lock).

Returns:
value from the flag that raised the latch
Throws:
java.lang.InterruptedException
PogamutInterruptedException

await

public TYPE await(long timeout,
                  java.util.concurrent.TimeUnit timeUnit)
           throws PogamutInterruptedException
Note that you may call only await() from one thread! If the instance is already in used it may produce unwanted behavior.

Returns null if desired value hasn't been set at the flag before timeout.

Parameters:
timeout -
timeUnit -
Returns:
value of the flag
Throws:
PogamutInterruptedException