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.
- Version:
- $Id: Promise.java,v 1.12.2.1 2007/11/20 08:37:24 belaban Exp $
- Author:
- Bela Ban
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetCond()
getLock()
getResult
(long timeout) Returns the result, but never throws a TimeoutException; returns null instead.getResultWithTimeout
(long timeout) Blocks until a result is available, or timeout milliseconds have elapsedboolean
Checks whether result is available.void
reset()
Causes all waiting threads to returnvoid
Sets the result and notifies any threads waiting for ittoString()
-
Constructor Details
-
Promise
public Promise()
-
-
Method Details
-
getLock
-
getCond
-
getResultWithTimeout
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)
-
getResult
-
getResult
Returns the result, but never throws a TimeoutException; returns null instead.- Parameters:
timeout
-- Returns:
- Object
-
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 -
toString
-