Interface Signal<T>

Type Parameters:
T - the value type
All Superinterfaces:
Consumer<Subscriber<? super T>>, Supplier<T>

public interface Signal<T> extends Supplier<T>, Consumer<Subscriber<? super T>>
A domain representation of a Reactive Stream signal. There are 4 distinct signals and their possible sequence is defined as such: onError | (onSubscribe onNext* (onError | onComplete)?)
Author:
Stephane Maldini
  • Method Details

    • complete

      static <T> Signal<T> complete()
      Creates and returns a Signal of variety Type.COMPLETE.

      Note that this variant associates an empty Context with the Signal.

      Type Parameters:
      T - the value type
      Returns:
      an OnCompleted variety of Signal
    • complete

      static <T> Signal<T> complete(Context context)
      Creates and returns a Signal of variety Type.COMPLETE, associated with a specific Context.
      Type Parameters:
      T - the value type
      Parameters:
      context - the Context associated with the completing source.
      Returns:
      an OnCompleted variety of Signal
    • error

      static <T> Signal<T> error(Throwable e)
      Creates and returns a Signal of variety Type.FAILED, which holds the error.

      Note that this variant associates an empty Context with the Signal.

      Type Parameters:
      T - the value type
      Parameters:
      e - the error associated to the signal
      Returns:
      an OnError variety of Signal
    • error

      static <T> Signal<T> error(Throwable e, Context context)
      Creates and returns a Signal of variety Type.FAILED, which holds the error and the Context associated with the erroring source.
      Type Parameters:
      T - the value type
      Parameters:
      e - the error associated to the signal
      context - the Context associated with the erroring source
      Returns:
      an OnError variety of Signal
    • next

      static <T> Signal<T> next(T t)
      Creates and returns a Signal of variety Type.NEXT, which holds the value.

      Note that this variant associates an empty Context with the Signal.

      Type Parameters:
      T - the value type
      Parameters:
      t - the value item associated to the signal
      Returns:
      an OnNext variety of Signal
    • next

      static <T> Signal<T> next(T t, Context context)
      Creates and returns a Signal of variety Type.NEXT, which holds the value and the Context associated with the emitting source.
      Type Parameters:
      T - the value type
      Parameters:
      t - the value item associated to the signal
      context - the Context associated with the emitting source
      Returns:
      an OnNext variety of Signal
    • subscribe

      static <T> Signal<T> subscribe(Subscription subscription)
      Creates and returns a Signal of variety Type.ON_SUBSCRIBE.

      Note that this variant associates an empty Context with the Signal.

      Type Parameters:
      T - the value type
      Parameters:
      subscription - the subscription
      Returns:
      an OnSubscribe variety of Signal
    • subscribe

      static <T> Signal<T> subscribe(Subscription subscription, Context context)
      Creates and returns a Signal of variety Type.ON_SUBSCRIBE, that holds the Context associated with the subscribed source.
      Type Parameters:
      T - the value type
      Parameters:
      subscription - the subscription
      context - the Context associated with the subscribed source
      Returns:
      an OnSubscribe variety of Signal
    • isComplete

      static boolean isComplete(Object o)
      Check if an arbitrary Object represents a COMPLETE Signal.
      Parameters:
      o - the object to check
      Returns:
      true if object represents the completion signal
    • isError

      static boolean isError(Object o)
      Check if a arbitrary Object represents an ERROR Signal.
      Parameters:
      o - the object to check
      Returns:
      true if object represents the error signal
    • getThrowable

      @Nullable Throwable getThrowable()
      Read the error associated with this (onError) signal.
      Returns:
      the Throwable associated with this (onError) signal, or null if not relevant
    • getSubscription

      @Nullable Subscription getSubscription()
      Read the subscription associated with this (onSubscribe) signal.
      Returns:
      the Subscription associated with this (onSubscribe) signal, or null if not relevant
    • get

      @Nullable T get()
      Retrieves the item associated with this (onNext) signal.
      Specified by:
      get in interface Supplier<T>
      Returns:
      the item associated with this (onNext) signal, or null if not relevant
    • hasValue

      default boolean hasValue()
      Has this signal an item associated with it ? (which only happens if it is an (onNext) signal)
      Returns:
      a boolean indicating whether or not this signal has an item associated with it
    • hasError

      default boolean hasError()
      Read whether this signal is on error and carries the cause.
      Returns:
      a boolean indicating whether this signal has an error
    • getType

      SignalType getType()
      Returns:
      the type of the signal
    • getContextView

      ContextView getContextView()
      Return the readonly ContextView that is accessible by the time this Signal was emitted.
      Returns:
      a readonly ContextView, or an empty one if no context is available.
    • isOnError

      default boolean isOnError()
      Indicates whether this signal represents an onError event.
      Returns:
      a boolean indicating whether this signal represents an onError event
    • isOnComplete

      default boolean isOnComplete()
      Indicates whether this signal represents an onComplete event.
      Returns:
      a boolean indicating whether this signal represents an onComplete event
    • isOnSubscribe

      default boolean isOnSubscribe()
      Indicates whether this signal represents an onSubscribe event.
      Returns:
      a boolean indicating whether this signal represents an onSubscribe event
    • isOnNext

      default boolean isOnNext()
      Indicates whether this signal represents an onNext event.
      Returns:
      a boolean indicating whether this signal represents an onNext event
    • accept

      default void accept(Subscriber<? super T> observer)
      Propagate the signal represented by this Signal instance to a given Subscriber.
      Specified by:
      accept in interface Consumer<T>
      Parameters:
      observer - the Subscriber to play the Signal on