Package net.officefloor.frame.test
Class ThreadSafeClosure<T>
- java.lang.Object
-
- net.officefloor.frame.test.ThreadSafeClosure<T>
-
public class ThreadSafeClosure<T> extends java.lang.Object
Thread
safe 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 void
failure(java.lang.Throwable cause)
Flags a failure.T
get()
Obtains current value.void
set(T value)
Sets the value.T
waitAndGet()
Convenience method to wait 3 seconds and then get value.T
waitAndGet(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.
-
-