Class UntypedAbstractActor

java.lang.Object
org.apache.pekko.actor.AbstractActor
org.apache.pekko.actor.UntypedAbstractActor
All Implemented Interfaces:
Actor
Direct Known Subclasses:
UntypedAbstractActorWithStash, UntypedAbstractActorWithTimers, UntypedAbstractActorWithUnboundedStash, UntypedAbstractActorWithUnrestrictedStash, UntypedAbstractLoggingActor

public abstract class UntypedAbstractActor extends AbstractActor
If the validation of the ReceiveBuilder match logic turns out to be a bottleneck for some of your actors you can consider to implement it at lower level by extending UntypedAbstractActor instead of AbstractActor. The partial functions created by the ReceiveBuilder consist of multiple lambda expressions for every match statement, where each lambda is referencing the code to be run. This is something that the JVM can have problems optimizing and the resulting code might not be as performant as the untyped version. When extending UntypedAbstractActor each message is received as an untyped Object and you have to inspect and cast it to the actual message type in other ways (instanceof checks).
  • Constructor Details

    • UntypedAbstractActor

      public UntypedAbstractActor()
  • Method Details

    • createReceive

      public final AbstractActor.Receive createReceive()
      Description copied from class: AbstractActor
      An actor has to define its initial receive behavior by implementing the createReceive method.
      Specified by:
      createReceive in class AbstractActor
    • onReceive

      public abstract void onReceive(Object message) throws Throwable
      To be implemented by concrete UntypedAbstractActor, this defines the behavior of the actor.
      Throws:
      Throwable
    • receive

      public scala.PartialFunction<Object,scala.runtime.BoxedUnit> receive()
      Description copied from interface: Actor
      Scala API: This defines the initial actor behavior, it must return a partial function with the actor logic.
      Specified by:
      receive in interface Actor
      Overrides:
      receive in class AbstractActor
    • unhandled

      public void unhandled(Object message)
      Recommended convention is to call this method if the message isn't handled in onReceive(java.lang.Object) (e.g. unknown message type). By default it fails with either a pekko.actor.DeathPactException (in case of an unhandled pekko.actor.Terminated message) or publishes an pekko.actor.UnhandledMessage to the actor's system's pekko.event.EventStream.