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()
Source
package.scala
Linear Supertypes
AnyRef, Any
Content Hierarchy Learn more about scaladoc diagrams
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 Typed

    Permalink

    A shapeless-powered, typed variant of the actor/props creation.

    A shapeless-powered, typed variant of the actor/props creation. This is an alternative over constructors, that use the Class[A], Any* overload to create actors.

    You must use TypedActors and these actors must be case classes for this to work.

    Example:

    case class ExampleActor(foo: Option[String]) extends TypedActor.Of[String] {
      def typedReceive: TypedReceive = ???
    }
    
    // runtime error (IllegalArgumentException: no matching constructor found):
    val runtimeError: ActorRef[String] =
      ActorOf(PropsOf[String](classOf[ExampleActor1], "wrong type"))
    
    // compiletime error:
    //   found   : String("wrong type") :: HNil
    //   required: Option[String] :: HNil
    val compiletimeError: ActorRef[String] =
      Typed[ExampleActor2].create("wrong type")
    Usage

    Use apply with the TypedActor as the type parameter and then call either create or props with the appropriate constructor parameters to create either an ActorRef or a Props.

  13. object TypedActor

    Permalink
  14. val UntypedProps: Props.type

    Permalink
  15. object containsAllOf

    Permalink
  16. object containsSomeOf extends ContainsSomeOf0

    Permalink
  17. object isNotA

    Permalink
  18. object isPartOf extends IsPartOf0

    Permalink

Inherited from AnyRef

Inherited from Any

Ungrouped