Package

de.knutwalker.akka

typed

Permalink

package typed

Compile-time wrapper for akka.actor.ActorRef to allow for same degree of type-safety on actors without requiring too much changes to the underlying system.

Example:

import akka.actor._
import de.knutwalker.akka.typed._

case class Ping(replyTo: ActorRef[Pong])
case class Pong(replyTo: ActorRef[Ping])

implicit val system = ActorSystem()

val ping: ActorRef[Ping] = ActorOf(PropsOf[Ping](new Actor {
  def receive: Receive = {
    case Ping(replyTo) ⇒ replyTo ! Pong(self.typed)
  }
}))
val pong: ActorRef[Pong] = ActorOf(PropsOf[Pong](new Actor {
  def receive: Receive = {
    case Pong(replyTo) ⇒ replyTo ! Ping(self.typed)
  }
}))

ping ! Ping(pong)


system.shutdown()
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. typed
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Type Members

  1. type ActorRef[A] = AnyRef { ... /* 2 definitions in type refinement */ }

    Permalink
  2. implicit final class ActorRefOps[A] extends AnyVal

    Permalink
  3. implicit final class ActorRefUnionedOps[U <: Union] extends AnyVal

    Permalink
  4. sealed trait ContainsSomeOf0 extends AnyRef

    Permalink
  5. sealed trait IsPartOf0 extends AnyRef

    Permalink
  6. sealed trait IsUnion[-A] extends AnyRef

    Permalink
    Annotations
    @implicitNotFound( ... )
  7. type Props[A] = AnyRef { ... /* 2 definitions in type refinement */ }

    Permalink
  8. final class PropsBuilder[A] extends AnyVal

    Permalink

    Type-curried creation of Props[A] to aid the type inference.

    Type-curried creation of Props[A] to aid the type inference.

    A

    the message type this actor is receiving

    See also

    de.knutwalker.akka.typed.PropsOf

  9. implicit final class PropsOps[A] extends AnyVal

    Permalink
  10. trait TypedActor extends Actor

    Permalink

    TypedActor base trait that should be extended by to create a typed 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.

  11. sealed trait Union extends AnyRef

    Permalink
  12. type UntypedActorRef = akka.actor.ActorRef

    Permalink
  13. implicit final class UntypedActorRefOps extends AnyVal

    Permalink
  14. type UntypedProps = akka.actor.Props

    Permalink
  15. implicit final class UntypedPropsOps extends AnyVal

    Permalink
  16. sealed trait containsAllOf[U <: Union, T <: Union] extends AnyRef

    Permalink
    Annotations
    @implicitNotFound( ... )
  17. sealed trait containsSomeOf[U <: Union, T <: Union] extends AnyRef

    Permalink
    Annotations
    @implicitNotFound( ... )
  18. sealed trait isNotA[A, B] extends AnyRef

    Permalink
  19. sealed trait isPartOf[A, +U <: Union] extends AnyRef

    Permalink
    Annotations
    @implicitNotFound( ... )
  20. sealed trait |[+A, +B] extends Union

    Permalink

Value Members

  1. def ActorOf[A](p: Props[A])(implicit factory: ActorRefFactory): ActorRef[A]

    Permalink

    Creates a new typed actor as a child of the implicit akka.actor.ActorRefFactory and give it an automatically generated name.

    Creates a new typed actor as a child of the implicit akka.actor.ActorRefFactory and give it an automatically generated name.

    A

    the message type this actor is receiving

    p

    see Props for details on how to obtain a Props object

    factory

    the factory to create the actor. Within an actor itself, this is its context. For a toplevel actor, you need to put the ActorSystem into the implicit scope.

    returns

    the typed ActorRef[A] for this actor

    Exceptions thrown

    akka.ConfigurationException if deployment, dispatcher or mailbox configuration is wrong

  2. def ActorOf[A](p: Props[A], name: String)(implicit factory: ActorRefFactory): ActorRef[A]

    Permalink

    Creates a new typed actor with the given name as a child of the implicit akka.actor.ActorRefFactory.

    Creates a new typed actor with the given name as a child of the implicit akka.actor.ActorRefFactory.

    A

    the message type this actor is receiving

    p

    see Props for details on how to obtain a Props object

    name

    the name of the actor. must not be null, empty or start with “$”. If the given name is already in use, an InvalidActorNameException is thrown.

    factory

    the factory to create the actor. Within an actor itself, this is its context. For a toplevel actor, you need to put the ActorSystem into the implicit scope.

    returns

    the typed ActorRef[A] for this actor

    Exceptions thrown

    akka.ConfigurationException if deployment, dispatcher or mailbox configuration is wrong

    akka.actor.InvalidActorNameException if the given name is invalid or already in use

  3. object IsUnion

    Permalink
  4. def Props[A](p: UntypedProps): Props[A]

    Permalink

    Creates a new typed Props that uses the given akka.actor.Props to create instances of this actor.

    Creates a new typed Props that uses the given akka.actor.Props to create instances of this actor.

    A

    the message type this actor is receiving

    p

    the Props to use

    returns

    a typed Props to create ActorRef[A]s for this actor

  5. def Props[A, T <: Actor](clazz: Class[T], args: Any*): Props[A]

    Permalink

    Creates a new typed Props that uses the given class and constructor arguments to create instances of this actor.

    Creates a new typed Props that uses the given class and constructor arguments to create instances of this actor.

    Wrapper for akka.actor.Props[T](Class[T], Any*).

    A

    the message type this actor is receiving

    T

    the actor type

    clazz

    the class of this actor

    args

    the constructor argumentes of this actor

    returns

    a typed Props to create ActorRef[A]s for this actor

  6. def Props[A, T <: Actor](creator: ⇒ T)(implicit arg0: ClassTag[T]): Props[A]

    Permalink

    Creates a new typed Props that uses the given creator function to create instances of this actor.

    Creates a new typed Props that uses the given creator function to create instances of this actor.

    CAVEAT: Required mailbox type cannot be detected when using anonymous mixin composition when creating the instance. For example, the following will not detect the need for DequeBasedMessageQueueSemantics as defined in Stash:

    Props(new Actor with Stash { ... })

    Instead you must create a named class that mixin the trait, e.g.

    class MyActor extends Actor with Stash

    Wrapper for akka.actor.Props[T](=> T).

    A

    the message type this actor is receiving

    T

    the actor type

    creator

    the thunk that create the new instance of this actor

    returns

    a typed Props to create ActorRef[A]s for this actor

  7. def Props[A, T <: Actor](implicit arg0: ClassTag[T]): Props[A]

    Permalink

    Creates a new typed Props that uses the default constructor of the given actor type to create new instances of this actor.

    Creates a new typed Props that uses the default constructor of the given actor type to create new instances of this actor.

    Wrapper for akka.actor.Props[T]

    A

    the message type this actor is receiving

    T

    the actor type

    returns

    a typed Props to create ActorRef[A]s for this actor

  8. def PropsFor[T <: TypedActor](clazz: Class[T], args: Any*): Props[typed.PropsFor.T.Message]

    Permalink

    Creates a new typed Props that uses the given class and constructor arguments to create instances of this typed actor.

    Creates a new typed Props that uses the given class and constructor arguments to create instances of this typed actor.

    The message type is derived from the given actor.

    T

    the typed actor

    clazz

    the class of this typed actor

    args

    the constructor argumentes of this actor

    returns

    a typed Props to create ActorRef[A]s for this actor

  9. def PropsFor[T <: TypedActor](creator: ⇒ T)(implicit arg0: ClassTag[T]): Props[typed.PropsFor.T.Message]

    Permalink

    Creates a new typed Props that uses the given creator function to create instances of this typed actor.

    Creates a new typed Props that uses the given creator function to create instances of this typed actor.

    The message type is derived from the given actor.

    T

    the typed actor

    creator

    the thunk that create the new instance of this typed actor

    returns

    a typed Props to create ActorRef[A]s for this actor

    See also

    Props for some caveat about this constructor.

  10. def PropsFor[T <: TypedActor](implicit arg0: ClassTag[T]): Props[typed.PropsFor.T.Message]

    Permalink

    Creates a new typed Props that uses the default constructor of the given actor to create new instances of this typed actor.

    Creates a new typed Props that uses the default constructor of the given actor to create new instances of this typed actor.

    The message type is derived from the given actor.

    T

    the typed actor

    returns

    a typed Props to create ActorRef[A]s for this actor

  11. def PropsOf[A]: PropsBuilder[A]

    Permalink

    Type-curried creation of Props[A] to aid type inference.

    Type-curried creation of Props[A] to aid type inference.

    A

    the message type this actor is receiving

    returns

    a class that created typed Props using one of the above methods

    Example:
    1. // message gets inferred as Nothing
      Props(new MyActor): Props[Nothing]
      // too verbose
      Props[MyMessage, MyActor](new MyActor): Props[MyMessage]
      // guided inference
      PropsOf[MyMessage](new MyActor): Props[MyMessage]
  12. object TypedActor

    Permalink
  13. val UntypedProps: Props.type

    Permalink
  14. object containsAllOf

    Permalink
  15. object containsSomeOf extends ContainsSomeOf0

    Permalink
  16. object isNotA

    Permalink
  17. object isPartOf extends IsPartOf0

    Permalink

Inherited from AnyRef

Inherited from Any

Ungrouped