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:
java.io.Serializable
public class BlockingBoolean extends java.util.concurrent.locks.AbstractQueuedSynchronizer
Mutable boolean that allows threads to wait for a specified value.- See Also:
- Serialized Form
-
-
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 void
await(boolean value)
Causes the current thread to wait until the boolean equals the specified value unless the thread is interrupted.boolean
await(boolean value, long timeout, java.util.concurrent.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.boolean
get()
Gets the value of the blocking boolean.void
set(boolean value)
Sets the value of the blocking boolean.protected int
tryAcquireShared(int acquires)
protected boolean
tryReleaseShared(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
-
-
-
-
Method Detail
-
await
public void await(boolean value) throws java.lang.InterruptedException
Causes the current thread to wait until the boolean equals the specified value unless the thread is interrupted.- Parameters:
value
- specified value- Throws:
java.lang.InterruptedException
- if interrupted while waiting
-
await
public boolean await(boolean value, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
Causes 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 thetimeout
argument- Returns:
true
if the count reached zero andfalse
if the waiting time elapsed before the count reached zero- Throws:
java.lang.InterruptedException
- if interrupted while waiting
-
tryAcquireShared
protected int tryAcquireShared(int acquires)
- Overrides:
tryAcquireShared
in classjava.util.concurrent.locks.AbstractQueuedSynchronizer
-
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:
tryReleaseShared
in classjava.util.concurrent.locks.AbstractQueuedSynchronizer
-
-