Package com.fizzed.crux.util
Class ConcurrentBooleanLatch
- java.lang.Object
-
- com.fizzed.crux.util.ConcurrentBooleanLatch
-
public class ConcurrentBooleanLatch extends java.lang.ObjectSimilar to a CountDownLatch but allows another thread to open or close the latch (resettable). Unlike a semaphore this is a basic boolean.- Author:
- jjlauer
-
-
Constructor Summary
Constructors Constructor Description ConcurrentBooleanLatch()Creates a new instance in the "opened" initial state.ConcurrentBooleanLatch(boolean initialValue)Creates a new instance in the specified initial state
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidawait(boolean value)Will either proceed immediately or wait until the value is set.booleanawait(boolean value, long timeout, java.util.concurrent.TimeUnit tu)Will either proceed immediately or wait until the value is set.booleanawait(boolean value, long timeout, java.util.concurrent.TimeUnit tu, java.lang.Runnable willWait)Will either proceed immediately or wait until the value is set.voidawait(boolean value, java.lang.Runnable willWait)Will either proceed immediately or wait until the value is set.booleanget()voidset(boolean newValue)
-
-
-
Constructor Detail
-
ConcurrentBooleanLatch
public ConcurrentBooleanLatch()
Creates a new instance in the "opened" initial state.
-
ConcurrentBooleanLatch
public ConcurrentBooleanLatch(boolean initialValue)
Creates a new instance in the specified initial state- Parameters:
initialValue- The initial state
-
-
Method Detail
-
get
public boolean get()
-
set
public void set(boolean newValue)
-
await
public void await(boolean value) throws java.lang.InterruptedExceptionWill either proceed immediately or wait until the value is set.- Parameters:
value- The value we expect- Throws:
java.lang.InterruptedException
-
await
public void await(boolean value, java.lang.Runnable willWait) throws java.lang.InterruptedExceptionWill either proceed immediately or wait until the value is set.- Parameters:
value- The value we expectwillWait- Will be run only if waiting will be required- Throws:
java.lang.InterruptedException
-
await
public boolean await(boolean value, long timeout, java.util.concurrent.TimeUnit tu) throws java.lang.InterruptedExceptionWill either proceed immediately or wait until the value is set.- Parameters:
value- The value we expecttimeout- Amount of time to waittu- The unit for the timeout- Returns:
- True is the expected value was met or false if the timeout occurred
- Throws:
java.lang.InterruptedException
-
await
public boolean await(boolean value, long timeout, java.util.concurrent.TimeUnit tu, java.lang.Runnable willWait) throws java.lang.InterruptedExceptionWill either proceed immediately or wait until the value is set.- Parameters:
value- The value we expecttimeout- Amount of time to waittu- The unit for the timeoutwillWait- Will be run only if waiting will be required- Returns:
- True is the expected value was met or false if the timeout occurred
- Throws:
java.lang.InterruptedException
-
-