public class Promise<T> extends java.lang.Object implements Condition
hasResult()
will always return true and getResult()
will return the
result. In order to block for a different result, reset()
has to be called first.Modifier and Type | Field and Description |
---|---|
protected CondVar |
cond |
protected boolean |
hasResult |
protected java.util.concurrent.locks.Lock |
lock |
protected T |
result |
Constructor and Description |
---|
Promise() |
Modifier and Type | Method and Description |
---|---|
protected T |
_getResultWithTimeout(long timeout)
Blocks until a result is available, or timeout milliseconds have elapsed.
|
T |
getResult() |
T |
getResult(long timeout)
Returns the result, but never throws a TimeoutException; returns null instead.
|
T |
getResult(long timeout,
boolean reset) |
T |
getResultWithTimeout(long timeout)
Blocks until a result is available, or timeout milliseconds have elapsed
|
T |
getResultWithTimeout(long timeout,
boolean reset) |
boolean |
hasResult()
Checks whether result is available.
|
boolean |
isMet()
Return true if the condition is met and false otherwise
|
void |
reset()
Causes all waiting threads to return
|
void |
reset(boolean signal) |
void |
setResult(T obj)
Sets the result and notifies any threads waiting for it
|
java.lang.String |
toString() |
protected final java.util.concurrent.locks.Lock lock
protected final CondVar cond
protected T result
protected volatile boolean hasResult
public boolean isMet()
Condition
public T getResultWithTimeout(long timeout) throws TimeoutException
timeout
- in msTimeoutException
- If a timeout occurred (implies that timeout > 0)public T getResultWithTimeout(long timeout, boolean reset) throws TimeoutException
TimeoutException
public T getResult()
public T getResult(long timeout)
timeout
- in mspublic T getResult(long timeout, boolean reset)
public boolean hasResult()
public void setResult(T obj)
public void reset()
public void reset(boolean signal)
public java.lang.String toString()
toString
in class java.lang.Object
protected T _getResultWithTimeout(long timeout) throws TimeoutException
timeout
- in msTimeoutException
- If a timeout occurred (implies that timeout > 0)Copyright © 1998-2020 Red Hat. All Rights Reserved.