Class CompositeSubscription

  • All Implemented Interfaces:
    Subscription

    public final class CompositeSubscription
    extends java.lang.Object
    implements Subscription
    Subscription that represents a group of Subscriptions that are unsubscribed together.

    All methods of this class are thread-safe.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(Subscription s)
      Adds a new Subscription to this CompositeSubscription if the CompositeSubscription is not yet unsubscribed.
      void addAll​(Subscription... subscriptions)
      Adds collection of Subscription to this CompositeSubscription if the CompositeSubscription is not yet unsubscribed.
      void clear()
      Unsubscribes any subscriptions that are currently part of this CompositeSubscription and remove them from the CompositeSubscription so that the CompositeSubscription is empty and able to manage new subscriptions.
      boolean hasSubscriptions()
      Returns true if this composite is not unsubscribed and contains subscriptions.
      boolean isUnsubscribed()
      Indicates whether this Subscription is currently unsubscribed.
      void remove​(Subscription s)
      Removes a Subscription from this CompositeSubscription, and unsubscribes the Subscription.
      void unsubscribe()
      Unsubscribes itself and all inner subscriptions.
      private static void unsubscribeFromAll​(java.util.Collection<Subscription> subscriptions)  
      • Methods inherited from class java.lang.Object

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

      • subscriptions

        private java.util.Set<Subscription> subscriptions
      • unsubscribed

        private volatile boolean unsubscribed
    • Constructor Detail

      • CompositeSubscription

        public CompositeSubscription()
        Constructs an empty Composite subscription.
      • CompositeSubscription

        public CompositeSubscription​(Subscription... 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 void add​(Subscription 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
      • addAll

        public void addAll​(Subscription... subscriptions)
        Adds collection of Subscription to this CompositeSubscription if the CompositeSubscription is not yet unsubscribed. If the CompositeSubscription is unsubscribed, addAll will indicate this by explicitly unsubscribing all Subscription in collection as well.
        Parameters:
        subscriptions - the collection of Subscription to add
      • clear

        public void clear()
        Unsubscribes any subscriptions that are currently part of this CompositeSubscription and remove them from the CompositeSubscription so that the CompositeSubscription is empty and able to manage new subscriptions.
      • unsubscribe

        public void unsubscribe()
        Unsubscribes itself and all inner subscriptions.

        After call of this method, new Subscriptions added to CompositeSubscription will be unsubscribed immediately.

        Specified by:
        unsubscribe in interface Subscription
      • unsubscribeFromAll

        private static void unsubscribeFromAll​(java.util.Collection<Subscription> subscriptions)
      • hasSubscriptions

        public boolean hasSubscriptions()
        Returns true if this composite is not unsubscribed and contains subscriptions.
        Returns:
        true if this composite is not unsubscribed and contains subscriptions.
        Since:
        1.0.7