Package net.officefloor.frame.test
Class ThreadSafeClosure<T>
- java.lang.Object
-
- net.officefloor.frame.test.ThreadSafeClosure<T>
-
public class ThreadSafeClosure<T> extends java.lang.ObjectThreadsafe capture of a free variable for closure state of aFunction.- Author:
- Daniel Sagenschneider
-
-
Constructor Summary
Constructors Constructor Description ThreadSafeClosure()Initialise withnull.ThreadSafeClosure(T initialValue)Initialise with initial value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfailure(java.lang.Throwable cause)Flags a failure.Tget()Obtains current value.voidset(T value)Sets the value.TwaitAndGet()Convenience method to wait 3 seconds and then get value.TwaitAndGet(long timeout)Obtains the value.
-
-
-
Constructor Detail
-
ThreadSafeClosure
public ThreadSafeClosure()
Initialise withnull.
-
ThreadSafeClosure
public ThreadSafeClosure(T initialValue)
Initialise with initial value.- Parameters:
initialValue- Initial value.
-
-
Method Detail
-
set
public void set(T value)
Sets the value.- Parameters:
value- Value.
-
failure
public void failure(java.lang.Throwable cause)
Flags a failure.- Parameters:
cause- Cause of the failure.
-
get
public T get()
Obtains current value.- Returns:
- Value or
null.
-
waitAndGet
public T waitAndGet()
Convenience method to wait 3 seconds and then get value.- Returns:
- Value.
-
waitAndGet
public T waitAndGet(long timeout)
Obtains the value.- Parameters:
timeout- Timeout to wait for the value.- Returns:
- Value.
-
-