Package rx.subjects

Class 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.
    • Method Detail

      • 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
      • onError

        public void onError​(java.lang.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
      • 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