Class AbstractOnSubscribe.SubscriptionState<T,S>

  • Type Parameters:
    T - the value type
    S - the per-subscriber user-defined state type
    Enclosing class:
    AbstractOnSubscribe < T , S>


    public static final class AbstractOnSubscribe.SubscriptionState<T,S>
    extends Object
    Represents a per-subscription state for the AbstractOnSubscribe operation. It supports phasing and counts the number of times a value was requested by the downstream.
    Since:
    (if this graduates from Experimental/Beta to supported, replace this parenthetical with the release number)
    • Method Summary

      Modifier and Type Method and Description
      protected boolean accept()
      Emits the onNext and/or the terminal value to the actual subscriber.
      void advancePhase()
      Advance the current phase by 1.
      void advancePhaseBy(int amount)
      Advance the current phase by the given amount (can be negative).
      long calls()
       
      protected void free()
      Release the state if there are no more interest in it and it is not in use.
      void onCompleted()
      Call this method to send an onCompleted to the subscriber and terminate all further activities.
      void onError(Throwable e)
      Call this method to send an onError to the subscriber and terminate all further activities.
      void onNext(T value)
      Call this method to offer the next onNext value for the subscriber.
      int phase()
       
      void phase(int newPhase)
      Sets a new phase value.
      S state()
       
      void stop()
      Signals that there won't be any further events.
      protected boolean stopRequested()
       
      protected void terminate()
      Terminates the state immediately and calls AbstractOnSubscribe.onTerminated(S) with the custom state.
      protected boolean use()
      Request the state to be used by onNext or returns false if the downstream has unsubscribed.
      protected boolean verify()
      Verify if the next() generated an event or requested a stop.
    • Method Detail

      • phase

        public int phase()
        Returns:
        the current phase value
      • phase

        public void phase(int newPhase)
        Sets a new phase value.
        Parameters:
        newPhase -
      • advancePhase

        public void advancePhase()
        Advance the current phase by 1.
      • advancePhaseBy

        public void advancePhaseBy(int amount)
        Advance the current phase by the given amount (can be negative).
        Parameters:
        amount - the amount to advance the phase
      • onNext

        public void onNext(T value)
        Call this method to offer the next onNext value for the subscriber.
        Parameters:
        value - the value to onNext
        Throws:
        IllegalStateException - if there is a value already offered but not taken or a terminal state is reached
      • onError

        public void onError(Throwable e)
        Call this method to send an onError to the subscriber and terminate all further activities. If there is a pending onNext, that value is emitted to the subscriber followed by this exception.
        Parameters:
        e - the exception to deliver to the client
        Throws:
        IllegalStateException - if the terminal state has been reached already
      • onCompleted

        public void onCompleted()
        Call this method to send an onCompleted to the subscriber and terminate all further activities. If there is a pending onNext, that value is emitted to the subscriber followed by this exception.
        Throws:
        IllegalStateException - if the terminal state has been reached already
      • stop

        public void stop()
        Signals that there won't be any further events.
      • accept

        protected boolean accept()
        Emits the onNext and/or the terminal value to the actual subscriber.
        Returns:
        true if the event was a terminal event
      • verify

        protected boolean verify()
        Verify if the next() generated an event or requested a stop.
        Returns:
        true if either event was generated or stop was requested
      • stopRequested

        protected boolean stopRequested()
        Returns:
        true if the next() requested a stop
      • use

        protected boolean use()
        Request the state to be used by onNext or returns false if the downstream has unsubscribed.
        Returns:
        true if the state can be used exclusively
        Throws:
        IllegalStateEception -
      • free

        protected void free()
        Release the state if there are no more interest in it and it is not in use.