akka.actor

TypedActor

class TypedActor extends Actor with Proxyable

TypedActor is a type-safe actor made out of a POJO with interface. Void methods are turned into fire-forget messages. Non-void methods are turned into request-reply messages with the exception of methods returning a 'Future' which will be sent using request-reply-with-future semantics and need to return the result using the 'future(..)' method: 'return future(... future result ...);'. Methods returning akka.japi.Option will block until a timeout expires, if the implementation of the method returns "none", some(null) will be returned, "none" will only be returned when the method didn't respond within the timeout.

Here is an example of usage (in Java):

class TestActorImpl extends TypedActor implements TestActor {

  public void hit(int count) {
    Pong pong = (Pong) context().sender();
    pong.hit(count++);
  }

  public Future square(int x) {
    return future(x * x);
  }

  @Override
  public void preStart() {
    ... // optional initialization on start
  }

  @Override
  public void postStop() {
    ... // optional cleanup on stop
  }

  ... // more life-cycle callbacks if needed
}

// create the ping actor
TestActor actor = TypedActor.newInstance(TestActor.class, TestActorImpl.class);

actor.hit(1); // use the actor
actor.hit(1);

// This method will return immediately when called, caller should wait on the Future for the result
Future future = actor.square(10);
future.await();
Integer result = future.get();

// stop the actor
TypedActor.stop(actor);

Here is an example of usage (in Scala):

class TestActorImpl extends TypedActor with TestActor {

  def hit(count: Int) = {
    val pong = context.sender.asInstanceOf[Pong]
    pong.hit(count += 1)
  }

  def square(x: Int): Future[Integer] = future(x * x)

  override def preStart() = {
    ... // optional initialization on start
  }

  override def postStop() = {
    ... // optional cleanup on stop
  }

  ... // more life-cycle callbacks if needed
}

// create the ping actor
val ping = TypedActor.newInstance(classOf[Ping], classOf[PingImpl])

ping.hit(1) // use the actor
ping.hit(1)

// This method will return immediately when called, caller should wait on the Future for the result
val future = actor.square(10)
future.await
val result: Int = future.get

// stop the actor
TypedActor.stop(ping)

Attributes
abstract
Linear Supertypes
Proxyable, Actor, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. TypedActor
  2. Proxyable
  3. Actor
  4. AnyRef
  5. Any
Visibility
  1. Public
  2. All

Instance Constructors

  1. new TypedActor ()

Type Members

  1. type Receive = PartialFunction[Any, Unit]

    Type alias because traits cannot have companion objects.

    Type alias because traits cannot have companion objects.

    Definition Classes
    Actor

Value Members

  1. def != (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  2. def != (arg0: Any): Boolean

    Attributes
    final
    Definition Classes
    Any
  3. def ## (): Int

    Attributes
    final
    Definition Classes
    AnyRef → Any
  4. def == (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  5. def == (arg0: Any): Boolean

    Attributes
    final
    Definition Classes
    Any
  6. val DELEGATE_FIELD_NAME : String

  7. def asInstanceOf [T0] : T0

    Attributes
    final
    Definition Classes
    Any
  8. def become (behavior: Receive, discardOld: Boolean = true): Unit

    Changes the Actor's behavior to become the new 'Receive' (PartialFunction[Any, Unit]) handler.

    Changes the Actor's behavior to become the new 'Receive' (PartialFunction[Any, Unit]) handler. Puts the behavior on top of the hotswap stack. If "discardOld" is true, an unbecome will be issued prior to pushing the new behavior to the stack

    Definition Classes
    Actor
  9. def clone (): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  10. val context : TypedActorContext

    Holds RTTI (runtime type information) for the TypedActor, f.

    Holds RTTI (runtime type information) for the TypedActor, f.e. current 'sender' reference, the 'senderFuture' reference etc.

    This class does not contain static information but is updated by the runtime system at runtime.

    You can get a hold of the context using the 'context()' method from the 'TypedActor' base class.

    Here is an example of usage (in Java):

    class PingImpl extends TypedActor implements Ping {
      public void hit(int count) {
        Pong pong = (Pong) context().sender();
        pong.hit(count++);
      }
    }
    

    Here is an example of usage (in Scala):

    class PingImpl extends TypedActor with Ping {
      def hit(count: Int) = {
        val pong = context.sender.asInstanceOf[Pong]
        pong.hit(count += 1)
      }
    }
    

  11. def eq (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  12. def equals (arg0: Any): Boolean

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

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  14. def future [T] (value: T): Future[T]

    This method is used to resolve the Future for TypedActor methods that are defined to return a akka.actor.dispatch.Future .

    This method is used to resolve the Future for TypedActor methods that are defined to return a akka.actor.dispatch.Future .

    Here is an example:

      class MyTypedActorImpl extends TypedActor implements MyTypedActor {
        public Future square(int x) {
          return future(x * x);
       }
     }
    
     MyTypedActor actor = TypedActor.actorOf(MyTypedActor.class, MyTypedActorImpl.class);
    
     // This method will return immediately when called, caller should wait on the Future for the result
     Future future = actor.square(10);
     future.await();
     Integer result = future.get();
    

  15. def getClass (): java.lang.Class[_]

    Attributes
    final
    Definition Classes
    AnyRef
  16. def hashCode (): Int

    Definition Classes
    AnyRef → Any
  17. def isDefinedAt (message: Any): Boolean

    Is the actor able to handle the message passed in as arguments?

    Is the actor able to handle the message passed in as arguments?

    Definition Classes
    Actor
  18. def isInstanceOf [T0] : Boolean

    Attributes
    final
    Definition Classes
    Any
  19. def ne (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  20. def notify (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
  21. def notifyAll (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
  22. implicit def optionSelf : Option[ActorRef]

    Attributes
    implicit
    Definition Classes
    Actor
  23. def postRestart (reason: Throwable): Unit

    User overridable callback.

    User overridable callback.

    Is called right AFTER restart on the newly created Actor to allow reinitialization after an Actor crash.

    Definition Classes
    TypedActorActor
  24. def postStop (): Unit

    User overridable callback.

    User overridable callback.

    Is called when 'actor.stop()' is invoked.

    Definition Classes
    TypedActorActor
  25. def preRestart (reason: Throwable): Unit

    User overridable callback.

    User overridable callback.

    Is called on a crashed Actor right BEFORE it is restarted to allow clean up of resources before Actor is terminated.

    Definition Classes
    TypedActorActor
  26. def preStart (): Unit

    User overridable callback.

    User overridable callback.

    Is called when an Actor is started by invoking 'actor.start()'.

    Definition Classes
    TypedActorActor
  27. def receive : PartialFunction[Any, Unit]

    User overridable callback/setting.

    User overridable callback/setting.

    Partial function implementing the actor logic. To be implemented by concrete actor class.

    Example code:

      def receive = {
        case Ping =>
          println("got a 'Ping' message")
          self.reply("pong")
    
        case OneWay =>
          println("got a 'OneWay' message")
    
        case unknown =>
          println("unknown message: " + unknown)
    }
    

    Definition Classes
    TypedActorActor
  28. val self : ScalaActorRef

    The 'self' field holds the ActorRef for this actor.

    The 'self' field holds the ActorRef for this actor.

    Can be used to send messages to itself:

    self ! message
    
    Here you also find most of the Actor API.

    For example fields like:

    self.dispatcher = ...
    self.trapExit = ...
    self.faultHandler = ...
    self.lifeCycle = ...
    self.sender
    

    Here you also find methods like:

    self.reply(..)
    self.link(..)
    self.unlink(..)
    self.start(..)
    self.stop(..)
    

    Definition Classes
    Actor
  29. implicit val someSelf : Some[ActorRef]

    Attributes
    implicit
    Definition Classes
    Actor
  30. def synchronized [T0] (arg0: ⇒ T0): T0

    Attributes
    final
    Definition Classes
    AnyRef
  31. def toString (): String

    Definition Classes
    AnyRef → Any
  32. def unbecome (): Unit

    Reverts the Actor behavior to the previous one in the hotswap stack.

    Reverts the Actor behavior to the previous one in the hotswap stack.

    Definition Classes
    Actor
  33. def unhandled (msg: Any): Unit

    User overridable callback.

    User overridable callback.

    Is called when a message isn't handled by the current behavior of the actor by default it throws an UnhandledMessageException

    Definition Classes
    Actor
  34. def wait (): Unit

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

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

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()
  37. def getContext : TypedActorContext

    Deprecated

    'getContext()' is deprecated use 'context()'

Inherited from Proxyable

Inherited from Actor

Inherited from AnyRef

Inherited from Any