|
![]() |
An Automatic Continuation is due to the propagation of a future outside the activity that has sent the corresponding request.
Automatic Continuations allow to pass in parameter or return as a result future objects(or objects containing a future) without blocking to wait the result object of the future. When the result is available on the object that originated the creation of the future, this object must update the result in all objects to which it passed the future.
Automatic Continuations can occur when sending a request (parameter of the request is a future or contains a future) or when sending a reply (the result is a future or contains a future).
Outgoing futures are registered in the FuturePool of the Active Object sending this future(request or reply). Registration for couple(Future,BodyDestination) as an Automatic Continuation occurs when the future is serialized(indeed every request or reply are serialized before being sent, and the future is part of the request or the reply). More precisely, a thread T sending the message(request or reply)---therefore the thread doing the serialization---, keeps in a static table (FuturePool.bodyDestination) a reference of the destination body. Hence when a future F is serialized by the same thread T(since futures are part of request or reply, it is the same thread serializing the request --or reply-- and the future), it looks up in the static table, if there is a destination D registered for the thread T. If true, the future notifies its FuturePool (that it is going to leave), which in turn registers couple (F,D) as an Automatic Continuation
When value V is available for the future F, V is propagated to all objects that received the fututre F. This Update is realized by a particular thread located in the FuturePool.
When a message is received(request or reply) by an Active Object, this message can contain a future. So the Active Object registers this future in the FuturePool to be able to update it when the value will be available. This registration takes place in two steps:
The following piece of code shows both cases: passing a future as parameter or as a result.
class C{ .... public static void main(String[] args){ ...... A a = newActive(A); A b = newActive(B); Result r1 = a.foo(); //r1 is a future Result r2 = b.bar(r1); //r1 is passed as parameter Result r3 = b.bar2(); // see ** ........ } //end of main ... } //end of class C
where
class A { ... public Result foo(){ ... } ... } //end of class A class B{ ... public Result bar (Result r) { ... } public Result bar2 () { A a = newActive(A); return a.foo(); // ** future is sent as a result } } //end of class B