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
ObjectgetResult()
ObjectgetResult(long timeout)
Returns the result, but never throws a TimeoutException; returns null instead.
ObjectgetResultWithTimeout(long timeout)
Blocks until a result is available, or timeout milliseconds have elapsed
booleanhasResult()
Checks whether result is available.
voidreset()
Causes all waiting threads to return
voidsetResult(Object obj)
Sets the result and notifies any threads waiting for it
StringtoString()

Method Detail

getResult

public Object getResult()

getResult

public Object getResult(long timeout)
Returns the result, but never throws a TimeoutException; returns null instead.

Parameters: timeout

Returns: Object

getResultWithTimeout

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)

hasResult

public boolean hasResult()
Checks whether result is available. Does not block.

reset

public void reset()
Causes all waiting threads to return

setResult

public void setResult(Object obj)
Sets the result and notifies any threads waiting for it

toString

public String toString()
Copyright ? 1998-2005 Bela Ban. All Rights Reserved.