org.jgroups.util

Class Promise


public class Promise
extends java.lang.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()

Method Details

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)
            throws TimeoutException
Blocks until a result is available, or timeout milliseconds have elapsed
Parameters:
timeout -
Returns:
An object

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 B) 1998-2005 Bela Ban. All Rights Reserved.