Package rx

Class Subscriber<T>

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Subscriber()  
      protected Subscriber​(Subscriber<?> subscriber)
      Construct a Subscriber by using another Subscriber for backpressure and for holding the subscription list (when this.add(sub) is called this will in fact call subscriber.add(sub)).
      protected Subscriber​(Subscriber<?> subscriber, boolean shareSubscriptions)
      Construct a Subscriber by using another Subscriber for backpressure and optionally for holding the subscription list (if shareSubscriptions is true then when this.add(sub) is called this will in fact call subscriber.add(sub)).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(Subscription s)
      Adds a Subscription to this Subscriber's list of subscriptions if this list is not marked as unsubscribed.
      private void addToRequested​(long n)  
      boolean isUnsubscribed()
      Indicates whether this Subscriber has unsubscribed from its list of subscriptions.
      void onStart()
      This method is invoked when the Subscriber and Observable have been connected but the Observable has not yet begun to emit items or send notifications to the Subscriber.
      protected void request​(long n)
      Request a certain maximum number of emitted items from the Observable this Subscriber is subscribed to.
      void setProducer​(Producer p)
      If other subscriber is set (by calling constructor Subscriber(Subscriber) or Subscriber(Subscriber, boolean)) then this method calls setProducer on the other subscriber.
      void unsubscribe()
      Stops the receipt of notifications on the Subscriber that was registered when this Subscription was received.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Subscriber

        protected Subscriber()
      • Subscriber

        protected Subscriber​(Subscriber<?> subscriber)
        Construct a Subscriber by using another Subscriber for backpressure and for holding the subscription list (when this.add(sub) is called this will in fact call subscriber.add(sub)).
        Parameters:
        subscriber - the other Subscriber
      • Subscriber

        protected Subscriber​(Subscriber<?> subscriber,
                             boolean shareSubscriptions)
        Construct a Subscriber by using another Subscriber for backpressure and optionally for holding the subscription list (if shareSubscriptions is true then when this.add(sub) is called this will in fact call subscriber.add(sub)).

        To retain the chaining of subscribers when setting shareSubscriptions to false, add the created instance to subscriber via add(rx.Subscription).

        Parameters:
        subscriber - the other Subscriber
        shareSubscriptions - true to share the subscription list in subscriber with this instance
        Since:
        1.0.6
    • Method Detail

      • add

        public final void add​(Subscription s)
        Adds a Subscription to this Subscriber's list of subscriptions if this list is not marked as unsubscribed. If the list is marked as unsubscribed, add will indicate this by explicitly unsubscribing the new Subscription as well.
        Parameters:
        s - the Subscription to add
      • unsubscribe

        public final void unsubscribe()
        Description copied from interface: Subscription
        Stops the receipt of notifications on the Subscriber that was registered when this Subscription was received.

        This allows unregistering an Subscriber before it has finished receiving all events (i.e. before onCompleted is called).

        Specified by:
        unsubscribe in interface Subscription
      • isUnsubscribed

        public final boolean isUnsubscribed()
        Indicates whether this Subscriber has unsubscribed from its list of subscriptions.
        Specified by:
        isUnsubscribed in interface Subscription
        Returns:
        true if this Subscriber has unsubscribed from its subscriptions, false otherwise
      • onStart

        public void onStart()
        This method is invoked when the Subscriber and Observable have been connected but the Observable has not yet begun to emit items or send notifications to the Subscriber. Override this method to add any useful initialization to your subscription, for instance to initiate backpressure.
      • request

        protected final void request​(long n)
        Request a certain maximum number of emitted items from the Observable this Subscriber is subscribed to. This is a way of requesting backpressure. To disable backpressure, pass Long.MAX_VALUE to this method.

        Requests are additive but if a sequence of requests totals more than Long.MAX_VALUE then Long.MAX_VALUE requests will be actioned and the extras may be ignored. Arriving at Long.MAX_VALUE by addition of requests cannot be assumed to disable backpressure. For example, the code below may result in Long.MAX_VALUE requests being actioned only.

         request(100);
         request(Long.MAX_VALUE-1);
         
        Parameters:
        n - the maximum number of items you want the Observable to emit to the Subscriber at this time, or Long.MAX_VALUE if you want the Observable to emit items at its own pace
        Throws:
        java.lang.IllegalArgumentException - if n is negative
      • addToRequested

        private void addToRequested​(long n)
      • setProducer

        public void setProducer​(Producer p)
        If other subscriber is set (by calling constructor Subscriber(Subscriber) or Subscriber(Subscriber, boolean)) then this method calls setProducer on the other subscriber. If the other subscriber is not set and no requests have been made to this subscriber then p.request(Long.MAX_VALUE) is called. If the other subscriber is not set and some requests have been made to this subscriber then p.request(n) is called where n is the accumulated requests to this subscriber.
        Parameters:
        p - producer to be used by this subscriber or the other subscriber (or recursively its other subscriber) to make requests from