Rice Pastry API

rice
Class Continuation.MultiContinuation

java.lang.Object
  extended by rice.Continuation.MultiContinuation
Enclosing interface:
Continuation

public static class Continuation.MultiContinuation
extends java.lang.Object

This class represents a Continuation which is used when multiple results are expected, which can come back at different times. The prototypical example of its use is in an application like Past, where Insert messages are sent to a number of replicas and the responses come back at different times. Optionally, the creator can override the isDone() method, which is called each time an intermediate result comes in. This allows applications like Past to declare an insert successful after a certain number of results have come back successful.


Field Summary
protected  boolean done
           
protected  boolean[] haveResult
           
protected  Continuation parent
           
protected  java.lang.Object[] result
           
 
Constructor Summary
Continuation.MultiContinuation(Continuation parent, int num)
          Constructor which takes a parent continuation as well as the number of results which to expect.
 
Method Summary
 java.lang.Object getResult()
          Method which can also be overriden to change what result should be returned to the parent continuation.
 Continuation getSubContinuation(int index)
          Returns the continuation which should be used as the result continuation for the index-th result.
 boolean isDone()
          Method which returns whether or not we are done.
protected  void receive(int index, java.lang.Object o)
          Internal method which receives the results and determines if we are done with this task.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

result

protected java.lang.Object[] result

haveResult

protected boolean[] haveResult

parent

protected Continuation parent

done

protected boolean done
Constructor Detail

Continuation.MultiContinuation

public Continuation.MultiContinuation(Continuation parent,
                                      int num)
Constructor which takes a parent continuation as well as the number of results which to expect.

Parameters:
parent - The parent continuation
num - The number of results expected to come in
Method Detail

getSubContinuation

public Continuation getSubContinuation(int index)
Returns the continuation which should be used as the result continuation for the index-th result. This should be called exactly once for each int between 0 and num.

Parameters:
The - index of this continuation

receive

protected void receive(int index,
                       java.lang.Object o)
Internal method which receives the results and determines if we are done with this task. This method ignores multiple calls by the same client continuation.

Parameters:
index - The index the result is for
o - The result for that continuation

isDone

public boolean isDone()
               throws java.lang.Exception
Method which returns whether or not we are done. This is designed to be overridden by subclasses in order to allow for more advanced behavior. If we are done and the subclass wishes to return an exception to the calling application, it may throw an Exception, which will be caught and returned to the parent via the receiveException() method. This will cause this continaution to be permanently marked as done.

Throws:
java.lang.Exception

getResult

public java.lang.Object getResult()
Method which can also be overriden to change what result should be returned to the parent continuation. This defaults to the Object[] containing results or exceptions.

Returns:
The result which should be returned to the application

Rice Pastry API

Copyright © 2001-2005 - Rice Pastry.


Imprint-Dataprotection