Package rx.subscriptions
Class CompositeSubscription
- java.lang.Object
-
- rx.subscriptions.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.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<Subscription>subscriptionsprivate booleanunsubscribed
-
Constructor Summary
Constructors Constructor Description CompositeSubscription()Constructs an empty Composite subscription.CompositeSubscription(Subscription... subscriptions)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Subscription s)Adds a newSubscriptionto thisCompositeSubscriptionif theCompositeSubscriptionis not yet unsubscribed.voidaddAll(Subscription... subscriptions)Adds collection ofSubscriptionto thisCompositeSubscriptionif theCompositeSubscriptionis not yet unsubscribed.voidclear()Unsubscribes any subscriptions that are currently part of thisCompositeSubscriptionand remove them from theCompositeSubscriptionso that theCompositeSubscriptionis empty and able to manage new subscriptions.booleanhasSubscriptions()Returns true if this composite is not unsubscribed and contains subscriptions.booleanisUnsubscribed()Indicates whether thisSubscriptionis currently unsubscribed.voidremove(Subscription s)voidunsubscribe()Unsubscribes itself and all inner subscriptions.private static voidunsubscribeFromAll(java.util.Collection<Subscription> subscriptions)
-
-
-
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:SubscriptionIndicates whether thisSubscriptionis currently unsubscribed.- Specified by:
isUnsubscribedin interfaceSubscription- Returns:
trueif thisSubscriptionis currently unsubscribed,falseotherwise
-
add
public void add(Subscription s)
Adds a newSubscriptionto thisCompositeSubscriptionif theCompositeSubscriptionis not yet unsubscribed. If theCompositeSubscriptionis unsubscribed,addwill indicate this by explicitly unsubscribing the newSubscriptionas well.- Parameters:
s- theSubscriptionto add
-
addAll
public void addAll(Subscription... subscriptions)
Adds collection ofSubscriptionto thisCompositeSubscriptionif theCompositeSubscriptionis not yet unsubscribed. If theCompositeSubscriptionis unsubscribed,addAllwill indicate this by explicitly unsubscribing allSubscriptionin collection as well.- Parameters:
subscriptions- the collection ofSubscriptionto add
-
remove
public void remove(Subscription s)
- Parameters:
s- theSubscriptionto remove
-
clear
public void clear()
Unsubscribes any subscriptions that are currently part of thisCompositeSubscriptionand remove them from theCompositeSubscriptionso that theCompositeSubscriptionis 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 toCompositeSubscriptionwill be unsubscribed immediately.- Specified by:
unsubscribein interfaceSubscription
-
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:
trueif this composite is not unsubscribed and contains subscriptions.- Since:
- 1.0.7
-
-