Interface Cascade.Stage.Actor.Builder<I,O>

Type Parameters:
I - is the type of messages the actor will consume.
O - is the type of messages the actor will produce.
Enclosing interface:
Cascade.Stage.Actor<I,O>

public static interface Cascade.Stage.Actor.Builder<I,O>
Actor Builder.
  • Method Details

    • withContextScript

      <X, Y> Cascade.Stage.Actor.Builder<X,Y> withContextScript(Cascade.Stage.Actor.ContextScript<X,Y> script)
      Define the normal behavior of the actor.

      If a script was already defined, then the given script will replace the previously defined one.

      If the only instance of the script is held by a single actor, then the script will only ever handle one exception at a time. Thus, the code contained in the script is intrinsically thread-safe.

      Warning: If two actors share the same script object, then that script may be executed concurrently by the independent actors in order to process messages received independently by each. Thus, in that case, the script is not intrinsically thread-safe.

      Type Parameters:
      X - is the type of messages the actor will consume.
      Y - is the type of messages the actor will produce.
      Parameters:
      script - defines the message-handling behavior of the actor.
      Returns:
      a modified copy of this builder.
    • withFunctionScript

      default <X, Y> Cascade.Stage.Actor.Builder<X,Y> withFunctionScript(Cascade.Stage.Actor.FunctionScript<X,Y> script)
      Define the normal behavior of the actor.

      If a script was already defined, then the given script will replace the previously defined one.

      If the only instance of the script is held by a single actor, then the script will only ever handle one exception at a time. Thus, the code contained in the script is intrinsically thread-safe.

      Warning: If two actors share the same script object, then that script may be executed concurrently by the independent actors in order to process messages received independently by each. Thus, in that case, the script is not intrinsically thread-safe.

      Type Parameters:
      X - is the type of messages the actor will consume.
      Y - is the type of messages the actor will produce.
      Parameters:
      script - defines the message-handling behavior of the actor.
      Returns:
      a modified copy of this builder.
    • withConsumerScript

      default <X> Cascade.Stage.Actor.Builder<X,X> withConsumerScript(Cascade.Stage.Actor.ConsumerScript<X> script)
      Define the normal behavior of the actor.

      If a script was already defined, then the given script will replace the previously defined one.

      If the only instance of the script is held by a single actor, then the script will only ever handle one exception at a time. Thus, the code contained in the script is intrinsically thread-safe.

      Warning: If two actors share the same script object, then that script may be executed concurrently by the independent actors in order to process messages received independently by each. Thus, in that case, the script is not intrinsically thread-safe.

      Type Parameters:
      X - is the type of messages the actor will consume.
      Parameters:
      script - defines the message-handling behavior of the actor.
      Returns:
      a modified copy of this builder.
    • withContextErrorHandler

      Define how the actor responds to unhandled exceptions.

      If an error-handler was already defined, then that error-handler and the given error-handler will be composed to form a new (third) error-handler that executes both error-handlers in sequence. In effect, this method appends the given error-handler onto the list of error-handlers that the actor will use. When an unhandled exception occurs, all of the handlers will execute.

      If the only instance of the error-handler is held by a single actor, then the error-handler will only ever handle one exception at a time. Thus, the code contained in the error-handler is intrinsically thread-safe.

      Warning: If two actors share the same error-handler object, then that error-handler may be executed concurrently by the independent actors in order to handle distinct exceptions. Thus, in that case, the error-handler is not intrinsically thread-safe.

      If the error-handler itself throws an exception, then that exception will be silently dropped.

      Parameters:
      handler - defines the error-handling behavior of the actor.
      Returns:
      a modified copy of this builder.
    • withConsumerErrorHandler

      default Cascade.Stage.Actor.Builder<I,O> withConsumerErrorHandler(Cascade.Stage.Actor.ConsumerErrorHandler handler)
      Define how the actor responds to unhandled exceptions.

      Equivalent: withContextErrorHandler((context, message, cause) -> handler.onError(cause))

      Parameters:
      handler - defines the error-handling behavior of the actor.
      Returns:
      a modified copy of this builder.
    • withMailbox

      Cause the actor to use the given mailbox to store incoming messages.

      Warning: The mailbox must ensure thread-safety.

      Parameters:
      queue - will store incoming messages as they await processing.
      Returns:
      a modified copy of this builder.
    • create

      Construct the actor and add it to the stage.
      Returns:
      the newly created actor.