akka.pattern
Class AskSupport.AskableActorRef

java.lang.Object
  extended by akka.pattern.AskSupport.AskableActorRef
Enclosing interface:
AskSupport

public private static final class AskSupport.AskableActorRef
extends java.lang.Object

Implementation detail of the “ask” pattern enrichment of ActorRef


Constructor Summary
AskSupport.AskableActorRef(ActorRef actorRef)
           
 
Method Summary
 ActorRef actorRef()
           
 scala.concurrent.Future<java.lang.Object> ask(java.lang.Object message, Timeout timeout)
          Sends a message asynchronously and returns a Future holding the eventual reply message; this means that the target actor needs to send the result to the sender reference provided.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AskSupport.AskableActorRef

public AskSupport.AskableActorRef(ActorRef actorRef)
Method Detail

actorRef

public ActorRef actorRef()

ask

public scala.concurrent.Future<java.lang.Object> ask(java.lang.Object message,
                                                     Timeout timeout)
Sends a message asynchronously and returns a Future holding the eventual reply message; this means that the target actor needs to send the result to the sender reference provided. The Future will be completed with an AskTimeoutException after the given timeout has expired; this is independent from any timeout applied while awaiting a result for this future (i.e. in Await.result(..., timeout)).

Warning: When using future callbacks, inside actors you need to carefully avoid closing over the containing actor’s object, i.e. do not call methods or access mutable state on the enclosing actor from within the callback. This would break the actor encapsulation and may introduce synchronization bugs and race conditions because the callback will be scheduled concurrently to the enclosing actor. Unfortunately there is not yet a way to detect these illegal accesses at compile time.

Recommended usage:


   flow {
     val f = worker.ask(request)(timeout)
     EnrichedRequest(request, f())
   } pipeTo nextActor
 

See the Future companion object for a description of flow