Interface PersistentActor

    • Method Detail

      • defer

        <A> void defer​(A event,
                       scala.Function1<A,​scala.runtime.BoxedUnit> handler)
        Defer the handler execution until all pending handlers have been executed. It is guaranteed that no new commands will be received by a persistent actor between a call to defer and the execution of its handler. Allows to define logic within the actor, which will respect the invocation-order-guarantee in respect to persistAsync or persist calls. That is, if persistAsync or persist was invoked before defer, the corresponding handlers will be invoked in the same order as they were registered in.

        This call will NOT result in event being persisted, use persist or persistAsync instead if the given event should possible to replay.

        If there are no pending persist handler calls, the handler will be called immediately.

        If persistence of an earlier event fails, the persistent actor will stop, and the handler will not be run.

        Parameters:
        event - event to be handled in the future, when preceding persist operations have been processes
        handler - handler for the given event
      • deferAsync

        <A> void deferAsync​(A event,
                            scala.Function1<A,​scala.runtime.BoxedUnit> handler)
        Defer the handler execution until all pending handlers have been executed. Allows to define logic within the actor, which will respect the invocation-order-guarantee in respect to persistAsync or persist calls. That is, if persistAsync or persist was invoked before deferAsync, the corresponding handlers will be invoked in the same order as they were registered in.

        This call will NOT result in event being persisted, use persist or persistAsync instead if the given event should possible to replay.

        If there are no pending persist handler calls, the handler will be called immediately.

        If persistence of an earlier event fails, the persistent actor will stop, and the handler will not be run.

        Parameters:
        event - event to be handled in the future, when preceding persist operations have been processes
        handler - handler for the given event
      • persist

        <A> void persist​(A event,
                         scala.Function1<A,​scala.runtime.BoxedUnit> handler)
        Asynchronously persists event. On successful persistence, handler is called with the persisted event. It is guaranteed that no new commands will be received by a persistent actor between a call to persist and the execution of its handler. This also holds for multiple persist calls per received command. Internally, this is achieved by stashing new commands and unstashing them when the event has been persisted and handled. The stash used for that is an internal stash which doesn't interfere with the inherited user stash.

        An event handler may close over persistent actor state and modify it. The sender of a persisted event is the sender of the corresponding command. This means that one can reply to a command sender within an event handler.

        Within an event handler, applications usually update persistent actor state using persisted event data, notify listeners and reply to command senders.

        If persistence of an event fails, Eventsourced.onPersistFailure(java.lang.Throwable, java.lang.Object, long) will be invoked and the actor will unconditionally be stopped. The reason that it cannot resume when persist fails is that it is unknown if the event was actually persisted or not, and therefore it is in an inconsistent state. Restarting on persistent failures will most likely fail anyway, since the journal is probably unavailable. It is better to stop the actor and after a back-off timeout start it again.

        Parameters:
        event - event to be persisted
        handler - handler for each persisted event
      • persistAll

        <A> void persistAll​(scala.collection.immutable.Seq<A> events,
                            scala.Function1<A,​scala.runtime.BoxedUnit> handler)
        Asynchronously persists events in specified order. This is equivalent to calling persist[A](event: A)(handler: A => Unit) multiple times with the same handler, except that events are persisted atomically with this method.

        Parameters:
        events - events to be persisted
        handler - handler for each persisted events
      • persistAllAsync

        <A> void persistAllAsync​(scala.collection.immutable.Seq<A> events,
                                 scala.Function1<A,​scala.runtime.BoxedUnit> handler)
        Asynchronously persists events in specified order. This is equivalent to calling persistAsync[A](event: A)(handler: A => Unit) multiple times with the same handler, except that events are persisted atomically with this method.

        Parameters:
        events - events to be persisted
        handler - handler for each persisted events
      • persistAsync

        <A> void persistAsync​(A event,
                              scala.Function1<A,​scala.runtime.BoxedUnit> handler)
        Asynchronously persists event. On successful persistence, handler is called with the persisted event.

        Unlike persist the persistent actor will continue to receive incoming commands between the call to persist and executing it's handler. This asynchronous, non-stashing, version of of persist should be used when you favor throughput over the "command-2 only processed after command-1 effects' have been applied" guarantee, which is provided by the plain persist method.

        An event handler may close over persistent actor state and modify it. The sender of a persisted event is the sender of the corresponding command. This means that one can reply to a command sender within an event handler.

        If persistence of an event fails, Eventsourced.onPersistFailure(java.lang.Throwable, java.lang.Object, long) will be invoked and the actor will unconditionally be stopped. The reason that it cannot resume when persist fails is that it is unknown if the event was actually persisted or not, and therefore it is in an inconsistent state. Restarting on persistent failures will most likely fail anyway, since the journal is probably unavailable. It is better to stop the actor and after a back-off timeout start it again.

        Parameters:
        event - event to be persisted
        handler - handler for each persisted event
      • receive

        scala.PartialFunction<java.lang.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