Package org.onlab.util
Class BlockingBoolean
- java.lang.Object
-
- java.util.concurrent.locks.AbstractOwnableSynchronizer
-
- java.util.concurrent.locks.AbstractQueuedSynchronizer
-
- org.onlab.util.BlockingBoolean
-
- All Implemented Interfaces:
Serializable
public class BlockingBoolean extends AbstractQueuedSynchronizer
Mutable boolean that allows threads to wait for a specified value.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.concurrent.locks.AbstractQueuedSynchronizer
AbstractQueuedSynchronizer.ConditionObject
-
-
Constructor Summary
Constructors Constructor Description BlockingBoolean(boolean value)Creates a new blocking boolean with the specified value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidawait(boolean value)Causes the current thread to wait until the boolean equals the specified value unless the thread is interrupted.booleanawait(boolean value, long timeout, TimeUnit unit)Causes the current thread to wait until the boolean equals the specified value unless the thread is interrupted, or the specified waiting time elapses.booleanget()Gets the value of the blocking boolean.voidset(boolean value)Sets the value of the blocking boolean.protected inttryAcquireShared(int acquires)protected booleantryReleaseShared(int releases)-
Methods inherited from class java.util.concurrent.locks.AbstractQueuedSynchronizer
acquire, acquireInterruptibly, acquireShared, acquireSharedInterruptibly, compareAndSetState, getExclusiveQueuedThreads, getFirstQueuedThread, getQueuedThreads, getQueueLength, getSharedQueuedThreads, getState, getWaitingThreads, getWaitQueueLength, hasContended, hasQueuedPredecessors, hasQueuedThreads, hasWaiters, isHeldExclusively, isQueued, owns, release, releaseShared, setState, toString, tryAcquire, tryAcquireNanos, tryAcquireSharedNanos, tryRelease
-
Methods inherited from class java.util.concurrent.locks.AbstractOwnableSynchronizer
getExclusiveOwnerThread, setExclusiveOwnerThread
-
-
-
-
Method Detail
-
await
public void await(boolean value) throws InterruptedExceptionCauses the current thread to wait until the boolean equals the specified value unless the thread is interrupted.- Parameters:
value- specified value- Throws:
InterruptedException- if interrupted while waiting
-
await
public boolean await(boolean value, long timeout, TimeUnit unit) throws InterruptedExceptionCauses the current thread to wait until the boolean equals the specified value unless the thread is interrupted, or the specified waiting time elapses.- Parameters:
value- specified valuetimeout- the maximum time to waitunit- the time unit of thetimeoutargument- Returns:
trueif the count reached zero andfalseif the waiting time elapsed before the count reached zero- Throws:
InterruptedException- if interrupted while waiting
-
tryAcquireShared
protected int tryAcquireShared(int acquires)
- Overrides:
tryAcquireSharedin classAbstractQueuedSynchronizer
-
set
public void set(boolean value)
Sets the value of the blocking boolean.- Parameters:
value- new value
-
get
public boolean get()
Gets the value of the blocking boolean.- Returns:
- current value
-
tryReleaseShared
protected boolean tryReleaseShared(int releases)
- Overrides:
tryReleaseSharedin classAbstractQueuedSynchronizer
-
-