Class Behavior<T>

    • Constructor Detail

      • Behavior

        public Behavior()
    • Method Detail

      • same

        public static <T> Behavior<T> same()
        Return this behavior from message processing in order to advise the system to reuse the previous behavior. This is provided in order to avoid the allocation overhead of recreating the current behavior where that is not necessary.
        Returns:
        (undocumented)
      • unhandled

        public static <T> Behavior<T> unhandled()
        Return this behavior from message processing in order to advise the system to reuse the previous behavior, including the hint that the message has not been handled. This hint may be used by composite behaviors that delegate (partial) handling to other behaviors.
        Returns:
        (undocumented)
      • stopped

        public static <T> Behavior<T> stopped()
        Return this behavior from message processing to signal that this actor shall terminate voluntarily. If this actor has created child actors then these will be stopped as part of the shutdown procedure.

        The PostStop signal that results from stopping this actor will be passed to the current behavior. All other messages and signals will effectively be ignored.

        Returns:
        (undocumented)
      • stopped

        public static <T> Behavior<T> stopped​(Behavior<T> postStop)
        Return this behavior from message processing to signal that this actor shall terminate voluntarily. If this actor has created child actors then these will be stopped as part of the shutdown procedure.

        The PostStop signal that results from stopping this actor will be passed to the given postStop behavior. All other messages and signals will effectively be ignored.

        Parameters:
        postStop - (undocumented)
        Returns:
        (undocumented)
      • empty

        public static <T> Behavior<T> empty()
        A behavior that treats every incoming message as unhandled.
        Returns:
        (undocumented)
      • ignore

        public static <T> Behavior<T> ignore()
        A behavior that ignores every incoming message and returns &ldquo;same&rdquo;.
        Returns:
        (undocumented)
      • failed

        public static <T> Behavior<T> failed​(java.lang.Throwable cause)
        INTERNAL API
        Parameters:
        cause - (undocumented)
        Returns:
        (undocumented)
      • unhandledSignal

        public static scala.PartialFunction<scala.Tuple2<TypedActorContext<scala.runtime.Nothing$>,​Signal>,​Behavior<scala.runtime.Nothing$>> unhandledSignal()
        INTERNAL API
        Returns:
        (undocumented)
      • canonicalize

        public static <T> Behavior<T> canonicalize​(Behavior<T> behavior,
                                                   Behavior<T> current,
                                                   TypedActorContext<T> ctx)
        Given a possibly special behavior (same or unhandled) and a &ldquo;current&rdquo; behavior (which defines the meaning of encountering a same behavior) this method computes the next behavior, suitable for passing a message or signal.
        Parameters:
        behavior - (undocumented)
        current - (undocumented)
        ctx - (undocumented)
        Returns:
        (undocumented)
      • wrap

        public static <T,​U> Behavior<U> wrap​(Behavior<?> currentBehavior,
                                                   Behavior<T> nextBehavior,
                                                   TypedActorContext<T> ctx,
                                                   scala.Function1<Behavior<T>,​Behavior<U>> f)
        INTERNAL API

        Return special behaviors as is, start deferred, if behavior is "non-special" apply the wrap function f to get and return the result from that. Useful for cases where a Behavior implementation that is decorating another behavior has processed a message and needs to re-wrap the resulting behavior with itself.

        Parameters:
        currentBehavior - (undocumented)
        nextBehavior - (undocumented)
        ctx - (undocumented)
        f - (undocumented)
        Returns:
        (undocumented)
      • start

        public static <T> Behavior<T> start​(Behavior<T> behavior,
                                            TypedActorContext<T> ctx)
        Starts deferred behavior and nested deferred behaviors until all deferred behaviors in the stack are started and then the resulting behavior is returned.
        Parameters:
        behavior - (undocumented)
        ctx - (undocumented)
        Returns:
        (undocumented)
      • existsInStack

        public static <T> boolean existsInStack​(Behavior<T> behavior,
                                                scala.Function1<Behavior<T>,​java.lang.Object> p)
        Go through the behavior stack and apply a predicate to see if any nested behavior satisfies it. The stack must not contain any unstarted deferred behavior or an IllegalArgumentException will be thrown.
        Parameters:
        behavior - (undocumented)
        p - (undocumented)
        Returns:
        (undocumented)
      • validateAsInitial

        public static <T> Behavior<T> validateAsInitial​(Behavior<T> behavior)
        Validate the given behavior as a suitable initial actor behavior; most notably the behavior can neither be same nor unhandled. Starting out with a Stopped behavior is allowed, though.
        Parameters:
        behavior - (undocumented)
        Returns:
        (undocumented)
      • isAlive

        public static <T> boolean isAlive​(Behavior<T> behavior)
        Returns true if the given behavior is not stopped.
        Parameters:
        behavior - (undocumented)
        Returns:
        (undocumented)
      • isUnhandled

        public static <T> boolean isUnhandled​(Behavior<T> behavior)
        Returns true if the given behavior is the special unhandled marker.
        Parameters:
        behavior - (undocumented)
        Returns:
        (undocumented)
      • isDeferred

        public static <T> boolean isDeferred​(Behavior<T> behavior)
        Returns true if the given behavior is the special Unhandled marker.
        Parameters:
        behavior - (undocumented)
        Returns:
        (undocumented)
      • interpretMessage

        public static <T> Behavior<T> interpretMessage​(Behavior<T> behavior,
                                                       TypedActorContext<T> ctx,
                                                       T msg)
        Execute the behavior with the given message
        Parameters:
        behavior - (undocumented)
        ctx - (undocumented)
        msg - (undocumented)
        Returns:
        (undocumented)
      • interpretSignal

        public static <T> Behavior<T> interpretSignal​(Behavior<T> behavior,
                                                      TypedActorContext<T> ctx,
                                                      Signal signal)
        Execute the behavior with the given signal
        Parameters:
        behavior - (undocumented)
        ctx - (undocumented)
        signal - (undocumented)
        Returns:
        (undocumented)
      • interpretMessages

        public static <T> Behavior<T> interpretMessages​(Behavior<T> behavior,
                                                        TypedActorContext<T> ctx,
                                                        scala.collection.Iterator<T> messages)
        INTERNAL API

        Execute the behavior with the given messages (or signals). The returned Behavior from each processed message is used for the next message.

        Parameters:
        behavior - (undocumented)
        ctx - (undocumented)
        messages - (undocumented)
        Returns:
        (undocumented)
      • narrow

        public final <U extends TBehavior<U> narrow()
        Narrow the type of this Behavior, which is always a safe operation. This method is necessary to implement the contravariant nature of Behavior (which cannot be expressed directly due to type inference problems).
        Returns:
        (undocumented)
      • unsafeCast

        public final <U> Behavior<U> unsafeCast()
        INTERNAL API

        Unsafe utility method for changing the type accepted by this Behavior; provided as an alternative to the universally available asInstanceOf, which casts the entire type rather than just the type parameter. Typically used to upcast a type, for instance from Nothing to some type U. Use it with caution, it may lead to a ClassCastException when you send a message to the resulting {@link Behavior[U}].

        Returns:
        (undocumented)
      • orElse

        public final Behavior<T> orElse​(Behavior<T> that)
        Composes this Behavior with a fallback Behavior which is used when this Behavior doesn't handle the message or signal, i.e. when unhandled is returned.

        Parameters:
        that - the fallback Behavior
        Returns:
        (undocumented)