Trait/Object

de.knutwalker.akka.typed

TypedActor

Related Docs: object TypedActor | package typed

Permalink

trait TypedActor extends Actor

TypedActor base trait that should be extended by to create a typed Actor. This actor is designed to only receive one type of message in its lifetime. Typically, this is some ADT/sealed trait that defines the protocol for this actor.

The message type is defined by extending TypedActor.Of:

class ExampleActor extends TypeActor.Of[ExampleProtocol] {
  // ...
}

The TypedActor is just a regular actor, but if offers some methods that help you stay within the defined typed contract. TypedActor#typedSelf is the alternative to akka.actor.Actor.self to get the typed ActorRef for this actor. TypedActor#typedBecome is the alternative to context.become to check the receiving type while changing behavior. You can get exhausitveness checking for your receive block if you use TypedActor#Total as a wrapper around your receive block.

// error: match may not be exhaustive. It would fail on the following inputs: None
class ExampleActor extends TypedActor {
  type Message = Option[String]
  def typedReceive: TypedReceive = Total {
    case Some("foo") ⇒
  }
}

If you must go back to untyped land, use the TypedActor#Untyped wrapper.

See also

akka.actor.Actor for more about Actors in general.

Linear Supertypes
Actor, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. TypedActor
  2. Actor
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Type Members

  1. abstract type Message

    Permalink
  2. type Receive = PartialFunction[Any, Unit]

    Permalink
    Definition Classes
    Actor
  3. final type TypedReceive = PartialFunction[Message, Unit]

    Permalink

Abstract Value Members

  1. abstract def typedReceive: TypedReceive

    Permalink

    Defines the actors behavior.

    Defines the actors behavior. Unlike akka.actor.Actor#receive, this one is typed in its first parameter.

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def Total(f: (Message) ⇒ Unit)(implicit ct: ClassTag[Message]): TypedReceive

    Permalink

    Wraps a total receiver function and returns it as a TypedReceive.

    Wraps a total receiver function and returns it as a TypedReceive. Use this to get exhaustiveness checking for your receive block.

    // error: match may not be exhaustive. It would fail on the following inputs: None
    class ExampleActor extends TypedActor.Of[Option[String]] {
      def typedReceive: TypedReceive = Total {
        case Some("foo") ⇒
      }
    }
  5. final def Untyped(f: Receive): TypedReceive

    Permalink

    Wraps an untyped receiver and returns it as a TypedReceive.

    Wraps an untyped receiver and returns it as a TypedReceive. Use this to match for messages that are outside of your protocol, e.g. akka.actor.Terminated.

    class ExampleActor extends TypedActor.Of[ExampleMessage] {
      def typedReceive: TypedReceive = Untyped {
        case Terminated(ref) => println(s"$$ref terminated")
      }
    }
  6. def aroundPostRestart(reason: Throwable): Unit

    Permalink
    Attributes
    protected[akka]
    Definition Classes
    Actor
  7. def aroundPostStop(): Unit

    Permalink
    Attributes
    protected[akka]
    Definition Classes
    Actor
  8. def aroundPreRestart(reason: Throwable, message: Option[Any]): Unit

    Permalink
    Attributes
    protected[akka]
    Definition Classes
    Actor
  9. def aroundPreStart(): Unit

    Permalink
    Attributes
    protected[akka]
    Definition Classes
    Actor
  10. def aroundReceive(receive: akka.actor.Actor.Receive, msg: Any): Unit

    Permalink
    Attributes
    protected[akka]
    Definition Classes
    Actor
  11. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  12. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  13. implicit val context: ActorContext

    Permalink
    Definition Classes
    Actor
  14. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  15. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  16. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  17. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  18. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  19. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  20. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  21. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  22. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  23. def postRestart(reason: Throwable): Unit

    Permalink
    Definition Classes
    Actor
    Annotations
    @throws( classOf[java.lang.Exception] )
  24. def postStop(): Unit

    Permalink
    Definition Classes
    Actor
    Annotations
    @throws( classOf[java.lang.Exception] )
  25. def preRestart(reason: Throwable, message: Option[Any]): Unit

    Permalink
    Definition Classes
    Actor
    Annotations
    @throws( classOf[java.lang.Exception] )
  26. def preStart(): Unit

    Permalink
    Definition Classes
    Actor
    Annotations
    @throws( classOf[java.lang.Exception] )
  27. def receive: Receive

    Permalink

    TypedActors delegate to typedReceive.

    TypedActors delegate to typedReceive.

    Definition Classes
    TypedActor → Actor
    See also

    akka.actor.Actor#receive

  28. implicit final val self: akka.actor.ActorRef

    Permalink
    Definition Classes
    Actor
  29. final def sender(): akka.actor.ActorRef

    Permalink
    Definition Classes
    Actor
  30. def supervisorStrategy: SupervisorStrategy

    Permalink
    Definition Classes
    Actor
  31. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  32. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  33. final def typedBecome(f: TypedReceive): Unit

    Permalink

    Typed variant of context.become.

  34. final val typedSelf: ActorRef[Message]

    Permalink

    Typed variant of self.

  35. def unhandled(message: Any): Unit

    Permalink
    Definition Classes
    Actor
  36. final def untypedFromTyped(f: TypedReceive): Receive

    Permalink

    Wraps a typed receive and returns it as an untyped receive.

    Wraps a typed receive and returns it as an untyped receive. Use this only if you have to mix with other traits that override receive, where you need to repeat the implementation of this typed actors default receive method.

    Attributes
    protected
  37. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  38. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  39. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Actor

Inherited from AnyRef

Inherited from Any

Ungrouped