Class UnicastSubject<T>

  • All Implemented Interfaces:
    Observer<T>


    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.
        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.

        Parameters:
        capacityHint - the capacity hint for the internal queue
        Returns:
        the created BufferUntilSubscriber instance
      • 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