Class SubscriptionIndexedRingBuffer<T extends Subscription>

  • All Implemented Interfaces:
    Subscription


    public final class SubscriptionIndexedRingBuffer<T extends Subscription>
    extends Object
    implements Subscription
    Similar to CompositeSubscription but giving extra access to internals so we can reuse a datastructure.

    NOTE: This purposefully is leaking the internal data structure through the API for efficiency reasons to avoid extra object allocations.

    • Constructor Detail

      • SubscriptionIndexedRingBuffer

        public SubscriptionIndexedRingBuffer()
      • SubscriptionIndexedRingBuffer

        public SubscriptionIndexedRingBuffer(T... subscriptions)
    • Method Detail

      • isUnsubscribed

        public boolean isUnsubscribed()
        Description copied from interface: Subscription
        Indicates whether this Subscription is currently unsubscribed.
        Specified by:
        isUnsubscribed in interface  Subscription
        Returns:
        true if this Subscription is currently unsubscribed, false otherwise
      • add

        public int add(T s)
        Adds a new Subscription to this CompositeSubscription if the CompositeSubscription is not yet unsubscribed. If the CompositeSubscription is unsubscribed, add will indicate this by explicitly unsubscribing the new Subscription as well.
        Parameters:
        s - the Subscription to add
        Returns:
        int index that can be used to remove a Subscription
      • remove

        public void remove(int n)
        Uses the Node received from `add` to remove this Subscription.

        Unsubscribes the Subscription after removal

      • removeSilently

        public void removeSilently(int n)
        Uses the Node received from `add` to remove this Subscription.

        Does not unsubscribe the Subscription after removal.

      • unsubscribe

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

      • forEach

        public int forEach(Func1<T,Boolean> action,
                           int startIndex)
        Parameters:
        action -
        Returns:
        int of last index seen if forEach exited early