Packages

o

akka.actor

ActorDSL

object ActorDSL extends actor.dsl.Inbox with Creators

This object contains elements which make writing actors and related code more concise, e.g. when trying out actors in the REPL.

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 akka.actor.ActorRefFactory as shown with "barney" (where the akka.actor.ActorContext serves this purpose), but since nested declarations share the same lexical context "fred"’s ActorContext would be ambiguous if the akka.actor.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.

Annotations
@deprecated
Deprecated

(Since version 2.5.0) deprecated Use the normal actorOf methods defined on ActorSystem and ActorContext to create Actors instead.

Source
ActorDSL.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ActorDSL
  2. Creators
  3. Inbox
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. class Extension extends actor.Extension with InboxExtension
    Attributes
    protected
  2. trait Act extends Actor

    This trait provides a DSL for writing the inner workings of an actor, e.g.

    This trait provides a DSL for writing the inner workings of an actor, e.g. for quickly trying things out in the REPL. It makes the following keywords available:

    • become mapped to context.become(_, discardOld = true)
    • becomeStacked mapped to context.become(_, discardOld = false)
    • unbecome mapped to context.unbecome
    • setup for implementing preStart()
    • whenFailing for implementing preRestart()
    • whenRestarted for implementing postRestart()
    • teardown for implementing postStop

    Using the life-cycle keywords multiple times results in replacing the content of the respective hook.

    Definition Classes
    Creators
  3. trait ActWithStash extends ActorDSL.Act with Stash

    Use this trait when defining an akka.actor.Actor with akka.actor.Stash, since just using actor()(new Act with Stash{}) will not be able to see the Stash component due to type erasure.

    Use this trait when defining an akka.actor.Actor with akka.actor.Stash, since just using actor()(new Act with Stash{}) will not be able to see the Stash component due to type erasure.

    Definition Classes
    Creators
  4. class Inbox extends actor.Inbox
    Definition Classes
    Inbox
  5. trait InboxExtension extends AnyRef
    Attributes
    protected
    Definition Classes
    Inbox

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def actor[T <: Actor](factory: ActorRefFactory)(ctor: ⇒ T)(implicit arg0: ClassTag[T]): ActorRef

    Create an actor with an automatically generated name from the given thunk which must produce an akka.actor.Actor.

    Create an actor with an automatically generated name from the given thunk which must produce an akka.actor.Actor.

    factory

    is an implicit akka.actor.ActorRefFactory, which can either be an akka.actor.ActorSystem or an akka.actor.ActorContext, where the latter is always implicitly available within an akka.actor.Actor.

    ctor

    is a by-name argument which captures an akka.actor.Actor factory; do not make the generated object accessible to code outside and do not return the same object upon subsequent invocations.

    Definition Classes
    Creators
  5. def actor[T <: Actor](factory: ActorRefFactory, name: String)(ctor: ⇒ T)(implicit arg0: ClassTag[T]): ActorRef

    Create an actor from the given thunk which must produce an akka.actor.Actor.

    Create an actor from the given thunk which must produce an akka.actor.Actor.

    factory

    is an implicit akka.actor.ActorRefFactory, which can either be an akka.actor.ActorSystem or an akka.actor.ActorContext, where the latter is always implicitly available within an akka.actor.Actor.

    name

    is the name, which must be unique within the context of its parent; defaults to null which will assign a name automatically.

    ctor

    is a by-name argument which captures an akka.actor.Actor factory; do not make the generated object accessible to code outside and do not return the same object upon subsequent invocations.

    Definition Classes
    Creators
  6. def actor[T <: Actor](name: String)(ctor: ⇒ T)(implicit arg0: ClassTag[T], factory: ActorRefFactory): ActorRef

    Create an actor from the given thunk which must produce an akka.actor.Actor.

    Create an actor from the given thunk which must produce an akka.actor.Actor.

    name

    is the name, which must be unique within the context of its parent.

    ctor

    is a by-name argument which captures an akka.actor.Actor factory; do not make the generated object accessible to code outside and do not return the same object upon subsequent invocations.

    factory

    is an implicit akka.actor.ActorRefFactory, which can either be an akka.actor.ActorSystem or an akka.actor.ActorContext, where the latter is always implicitly available within an akka.actor.Actor.

    Definition Classes
    Creators
  7. def actor[T <: Actor](ctor: ⇒ T)(implicit arg0: ClassTag[T], factory: ActorRefFactory): ActorRef

    Create an actor from the given thunk which must produce an akka.actor.Actor.

    Create an actor from the given thunk which must produce an akka.actor.Actor.

    ctor

    is a by-name argument which captures an akka.actor.Actor factory; do not make the generated object accessible to code outside and do not return the same object upon subsequent invocations.

    factory

    is an implicit akka.actor.ActorRefFactory, which can either be an akka.actor.ActorSystem or an akka.actor.ActorContext, where the latter is always implicitly available within an akka.actor.Actor.

    Definition Classes
    Creators
  8. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  9. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate() @throws( ... )
  10. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  12. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  13. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  14. def inbox()(implicit system: ActorSystem): Inbox

    Create a new actor which will internally queue up messages it gets so that they can be interrogated with the akka.actor.dsl.Inbox!.Inbox!.receive and akka.actor.dsl.Inbox!.Inbox!.select methods.

    Create a new actor which will internally queue up messages it gets so that they can be interrogated with the akka.actor.dsl.Inbox!.Inbox!.receive and akka.actor.dsl.Inbox!.Inbox!.select methods. It will be created as a system actor in the ActorSystem which is implicitly (or explicitly) supplied.

    Definition Classes
    Inbox
  15. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  16. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  17. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  18. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  19. implicit def senderFromInbox(implicit inbox: Inbox): ActorRef
    Definition Classes
    Inbox
  20. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  21. def toString(): String
    Definition Classes
    AnyRef → Any
  22. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  24. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  25. object Extension extends ExtensionId[Extension] with ExtensionIdProvider
    Attributes
    protected

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @Deprecated @deprecated @throws( classOf[java.lang.Throwable] )
    Deprecated

    (Since version ) see corresponding Javadoc for more information.

Inherited from Creators

Inherited from dsl.Inbox

Inherited from AnyRef

Inherited from Any

Ungrouped