Class BlockingReference<V>
- java.lang.Object
-
- org.javacord.core.util.concurrent.BlockingReference<V>
-
- Type Parameters:
V
- The type of object referred to by this reference.
public class BlockingReference<V> extends java.lang.Object
An object reference that has the ability to block a thread until a value is available if one is not present.
-
-
Constructor Summary
Constructors Constructor Description BlockingReference()
Creates a new BlockingReference instance with no initial value.BlockingReference(V initialValue)
Creates a new BlockingReference instance with the given initial value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description V
get()
Gets the current value or blocks the thread until one is present.V
get(long timeout, java.util.concurrent.TimeUnit unit)
Gets the current value or blocks the thread until one is present.boolean
hasValue()
Checks whether this reference currently holds a value.void
set(V value)
Sets the current value and notifies any waitingget()
calls.
-
-
-
Constructor Detail
-
BlockingReference
public BlockingReference(V initialValue)
Creates a new BlockingReference instance with the given initial value.- Parameters:
initialValue
- The initial value.
-
BlockingReference
public BlockingReference()
Creates a new BlockingReference instance with no initial value.
-
-
Method Detail
-
hasValue
public boolean hasValue()
Checks whether this reference currently holds a value.- Returns:
- Whether this reference currently holds a value.
-
get
public V get() throws java.lang.InterruptedException
Gets the current value or blocks the thread until one is present.- Returns:
- The current value.
- Throws:
java.lang.InterruptedException
- if interrupted while waiting.
-
get
public V get(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
Gets the current value or blocks the thread until one is present.- Parameters:
timeout
- The amount of time to wait in the given time unit before unblocking the thread and returning null.unit
- The TimeUnit to use to interpret timeout- Returns:
- The current value or null if the specified timeout elapses.
- Throws:
java.lang.InterruptedException
- if interrupted while waiting.
-
-