Package org.jgroups.util
Class Promise<T>
java.lang.Object
org.jgroups.util.Promise<T>
Allows a thread to submit an asynchronous request and to wait for the result. The caller may choose to check
for the result at a later time, or immediately and it may block or not. Both the caller and responder have to
know the promise.
When the result is available, 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.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected T_getResultWithTimeout(long timeout) Blocks until a result is available, or timeout milliseconds have elapsed.Returns when the result is available (blocking until tthe result is available)getResult(long timeout) Returns the result, but never throws a TimeoutException; returns null instead.getResult(long timeout, boolean reset) getResultWithTimeout(long timeout) Blocks until a result is available, or timeout milliseconds have elapsedgetResultWithTimeout(long timeout, boolean reset) booleanChecks whether result is available.voidreset()Causes all waiting threads to returnvoidreset(boolean signal) voidSets the result and notifies any threads waiting for ittoString()
-
Field Details
-
lock
-
cond
-
result
-
hasResult
protected volatile boolean hasResult
-
-
Constructor Details
-
Promise
public Promise()
-
-
Method Details
-
getResultWithTimeout
Blocks until a result is available, or timeout milliseconds have elapsed- Parameters:
timeout- in ms- Returns:
- An object
- Throws:
TimeoutException- If a timeout occurred (implies that timeout > 0)
-
getResultWithTimeout
- Throws:
TimeoutException
-
getResult
Returns when the result is available (blocking until tthe result is available) -
getResult
Returns the result, but never throws a TimeoutException; returns null instead.- Parameters:
timeout- in ms- Returns:
- T
-
getResult
-
hasResult
public boolean hasResult()Checks whether result is available. Does not block. -
setResult
Sets the result and notifies any threads waiting for it -
reset
public void reset()Causes all waiting threads to return -
reset
public void reset(boolean signal) -
toString
-
_getResultWithTimeout
Blocks until a result is available, or timeout milliseconds have elapsed. Needs to be called with lock held- Parameters:
timeout- in ms- Returns:
- An object
- Throws:
TimeoutException- If a timeout occurred (implies that timeout > 0)
-