Package rx.subjects

Class UnicastSubject<T>

java.lang.Object
rx.Observable<T>
rx.subjects.Subject<T,T>
rx.subjects.UnicastSubject<T>
Type Parameters:
T - the input and output value type
All Implemented Interfaces:
Observer<T>

@Experimental public final class UnicastSubject<T> extends Subject<T,T>
A Subject variant which buffers events until a single Subscriber arrives and replays them to it and potentially switches to direct delivery once the Subscriber caught up and requested an unlimited amount. In this case, the buffered values are no longer retained. If the Subscriber requests a limited amount, queueing is involved and only those values are retained which weren't requested by the Subscriber at that time.
  • Field Details

  • Constructor Details

  • Method Details

    • create

      public static <T> UnicastSubject<T> create()
      Constructs an empty UnicastSubject instance with the default capacity hint of 16 elements.
      Type Parameters:
      T - the input and output value type
      Returns:
      the created UnicastSubject instance
    • create

      public static <T> UnicastSubject<T> create(int capacityHint)
      Constructs an empty UnicastSubject instance with a capacity hint.

      The capacity hint determines the internal queue's island size: the larger it is the less frequent allocation will happen if there is no subscriber or the subscriber hasn't caught up.

      Type Parameters:
      T - the input and output value type
      Parameters:
      capacityHint - the capacity hint for the internal queue
      Returns:
      the created BufferUntilSubscriber instance
    • create

      public static <T> UnicastSubject<T> create(int capacityHint, Action0 onTerminated)
      Constructs an empty UnicastSubject instance with a capacity hint and an Action0 instance to call if the subject reaches its terminal state or the single Subscriber unsubscribes mid-sequence.

      The capacity hint determines the internal queue's island size: the larger it is the less frequent allocation will happen if there is no subscriber or the subscriber hasn't caught up.

      Type Parameters:
      T - the input and output value type
      Parameters:
      capacityHint - the capacity hint for the internal queue
      onTerminated - the optional callback to call when subject reaches its terminal state or the single Subscriber unsubscribes mid-sequence. It will be called at most once.
      Returns:
      the created BufferUntilSubscriber instance
    • onNext

      public void onNext(T t)
      Description copied from interface: Observer
      Provides the Observer with a new item to observe.

      The Observable may call this method 0 or more times.

      The Observable will not call this method again after it calls either Observer.onCompleted() or Observer.onError(java.lang.Throwable).

      Parameters:
      t - the item emitted by the Observable
    • onError

      public void onError(Throwable e)
      Description copied from interface: Observer
      Notifies the Observer that the Observable has experienced an error condition.

      If the Observable calls this method, it will not thereafter call Observer.onNext(T) or Observer.onCompleted().

      Parameters:
      e - the exception encountered by the Observable
    • onCompleted

      public void onCompleted()
      Description copied from interface: Observer
      Notifies the Observer that the Observable has finished sending push-based notifications.

      The Observable will not call this method if it calls Observer.onError(java.lang.Throwable).

    • hasObservers

      public boolean hasObservers()
      Description copied from class: Subject
      Indicates whether the Subject has Observers subscribed to it.
      Specified by:
      hasObservers in class Subject<T,T>
      Returns:
      true if there is at least one Observer subscribed to this Subject, false otherwise