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 TotalUnion(implicit ev: IsUnion[Message]): MkTotalUnionReceiveEmpty[Out]

    Permalink

    Builds final receive out of sub-receives if this TypedActor is for a Union message type.

    Builds final receive out of sub-receives if this TypedActor is for a Union message type. This mirrors a Total receive, i.e. you must provide all cases.

    class ExampleActor extends TypedActor.Of[Foo | Bar | Baz] {
      def typedReceive: TypedReceive = TotalUnion
        .on[Foo]{ case Foo() => println("foo") }
        .on[Bar]{ case Bar() => println("bar") }
        .on[Bax]{ case Bax() => println("bax") }
        .apply
      }
    }
  6. final def Union(implicit ev: IsUnion[Message]): MkPartialUnionReceive[Out, Empty]

    Permalink

    Builds final receive out of sub-receives if this TypedActor is for a Union message type.

    Builds final receive out of sub-receives if this TypedActor is for a Union message type. This mirrors a TypedReceive, i.e. you must not cover all cases.

    class ExampleActor extends TypedActor.Of[Foo | Bar | Baz] {
      def typedReceive: TypedReceive = Union
        .on[Foo]{ case Foo() => println("foo") }
        .on[Bar]{ case Bar() => println("bar") }
        .apply
      }
    }
  7. 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")
      }
    }
  8. def aroundPostRestart(reason: Throwable): Unit

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Permalink

    TypedActors delegate to typedReceive.

    TypedActors delegate to typedReceive.

    Definition Classes
    TypedActor → Actor
    See also

    akka.actor.Actor#receive

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

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

    Permalink
    Definition Classes
    Actor
  32. def supervisorStrategy: SupervisorStrategy

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

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

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

    Permalink

    Typed variant of context.become.

  36. final val typedSelf: ActorRef[Message]

    Permalink

    Typed variant of self.

  37. def unhandled(message: Any): Unit

    Permalink
    Definition Classes
    Actor
  38. final def unionBecome(implicit ev: IsUnion[Message]): TypedBecomeOnAux[Out]

    Permalink

    context.become for a given subtype if this actor is of a union type.

  39. 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
  40. final def wait(): Unit

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

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

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

Inherited from Actor

Inherited from AnyRef

Inherited from Any

Ungrouped