org.jgroups.util
Class Promise
public
class
Promise
extends Object
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.
Author: Bela Ban
Method Summary |
Object | getResult() |
Object | getResult(long timeout)
Returns the result, but never throws a TimeoutException; returns null instead. |
Object | getResultWithTimeout(long timeout)
Blocks until a result is available, or timeout milliseconds have elapsed |
boolean | hasResult()
Checks whether result is available. |
void | reset()
Causes all waiting threads to return |
void | setResult(Object obj)
Sets the result and notifies any threads
waiting for it |
String | toString() |
public Object getResult()
public Object getResult(long timeout)
Returns the result, but never throws a TimeoutException; returns null instead.
Parameters: timeout
Returns: Object
public Object getResultWithTimeout(long timeout)
Blocks until a result is available, or timeout milliseconds have elapsed
Parameters: timeout
Returns: An object
Throws: TimeoutException. If a timeout occurred (implies that timeout > 0)
public boolean hasResult()
Checks whether result is available. Does not block.
public void reset()
Causes all waiting threads to return
public void setResult(Object obj)
Sets the result and notifies any threads
waiting for it
public String toString()
Copyright ? 1998-2005 Bela Ban. All Rights Reserved.