org.jgroups.util
Class Promise

java.lang.Object
  extended byorg.jgroups.util.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.


Constructor Summary
Promise()
           
 
Method Summary
 java.lang.Object checkForResult()
          Checks whether result is available.
 java.lang.Object getResult(long timeout)
          Gets result.
 void reset()
          Causes all waiting threads to return
 void setResult(java.lang.Object obj)
          Sets the result and notifies any threads waiting for it
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Promise

public Promise()
Method Detail

getResult

public java.lang.Object getResult(long timeout)
Gets result. If result was already submitted, returns it immediately (resetting it), else blocks until results get available.

Parameters:
timeout - Max time to wait for result. If it is 0, we wait indefinitely

checkForResult

public java.lang.Object checkForResult()
Checks whether result is available. Does not block.


setResult

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


reset

public void reset()
Causes all waiting threads to return


toString

public java.lang.String toString()


Copyright © 2001,2002 www.jgroups.com . All Rights Reserved.