public class ActorDSL
extends java.lang.Object
For the communication of non-actor code with actors, you may use anonymous actors tailored to this job:
import ActorDSL._
import scala.concurrent.util.duration._
implicit val system: ActorSystem = ...
implicit val i = inbox()
someActor ! someMsg // replies will go to `i`
val reply = i.receive()
val transformedReply = i.select(5 seconds) {
case x: Int => 2 * x
}
The receive
and select
methods are synchronous, i.e. they block the
calling thread until an answer from the actor is received or the timeout
expires. The default timeout is taken from configuration item
akka.actor.dsl.default-timeout
.
When defining actors in the REPL, say, you may want to have a look at the
Act
trait:
import ActorDSL._
val system: ActorSystem = ...
val a = actor(system, "fred")(new Act {
val b = actor("barney")(new Act {
...
})
become {
case msg => ...
}
})
Note that actor
can be used with an implicit ActorRefFactory
as shown with "barney"
(where the ActorContext
serves this
purpose), but since nested declarations share the same
lexical context "fred"
’s ActorContext would be ambiguous
if the ActorSystem
were declared implicit
(this could also
be circumvented by shadowing the name system
within "fred"
).
Note: If you want to use an Act with Stash
, you should use the
ActWithStash
trait in order to have the actor get the necessary deque-based
mailbox setting.
Modifier and Type | Class and Description |
---|---|
protected static class |
ActorDSL.Extension |
protected static class |
ActorDSL.Extension$ |
Constructor and Description |
---|
ActorDSL() |
Modifier and Type | Method and Description |
---|---|
static <T extends Actor> |
actor(ActorRefFactory factory,
scala.Function0<T> ctor,
scala.reflect.ClassTag<T> evidence$4) |
static <T extends Actor> |
actor(ActorRefFactory factory,
java.lang.String name,
scala.Function0<T> ctor,
scala.reflect.ClassTag<T> evidence$3) |
static <T extends Actor> |
actor(scala.Function0<T> ctor,
scala.reflect.ClassTag<T> evidence$1,
ActorRefFactory factory) |
static <T extends Actor> |
actor(java.lang.String name,
scala.Function0<T> ctor,
scala.reflect.ClassTag<T> evidence$2,
ActorRefFactory factory) |
protected abstract static void |
akka$actor$dsl$Inbox$_setter_$akka$actor$dsl$Inbox$$deadlineOrder_$eq(scala.math.Ordering<Inbox.Query> x$1) |
protected abstract static void |
akka$actor$dsl$Inbox$_setter_$akka$actor$dsl$Inbox$$extraTime_$eq(scala.concurrent.duration.FiniteDuration x$1) |
static scala.math.Ordering<Inbox.Query> |
akka$actor$dsl$Inbox$$deadlineOrder() |
static scala.concurrent.duration.FiniteDuration |
akka$actor$dsl$Inbox$$extraTime() |
static Inbox.Inbox |
inbox(ActorSystem system) |
static ActorRef |
senderFromInbox(Inbox.Inbox inbox) |
public static scala.math.Ordering<Inbox.Query> akka$actor$dsl$Inbox$$deadlineOrder()
public static scala.concurrent.duration.FiniteDuration akka$actor$dsl$Inbox$$extraTime()
public static Inbox.Inbox inbox(ActorSystem system)
public static ActorRef senderFromInbox(Inbox.Inbox inbox)
protected abstract static void akka$actor$dsl$Inbox$_setter_$akka$actor$dsl$Inbox$$deadlineOrder_$eq(scala.math.Ordering<Inbox.Query> x$1)
protected abstract static void akka$actor$dsl$Inbox$_setter_$akka$actor$dsl$Inbox$$extraTime_$eq(scala.concurrent.duration.FiniteDuration x$1)
public static <T extends Actor> ActorRef actor(scala.Function0<T> ctor, scala.reflect.ClassTag<T> evidence$1, ActorRefFactory factory)
public static <T extends Actor> ActorRef actor(java.lang.String name, scala.Function0<T> ctor, scala.reflect.ClassTag<T> evidence$2, ActorRefFactory factory)
public static <T extends Actor> ActorRef actor(ActorRefFactory factory, java.lang.String name, scala.Function0<T> ctor, scala.reflect.ClassTag<T> evidence$3)
public static <T extends Actor> ActorRef actor(ActorRefFactory factory, scala.Function0<T> ctor, scala.reflect.ClassTag<T> evidence$4)