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>
subscriptions
private boolean
unsubscribed
-
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 void
add(Subscription s)
Adds a newSubscription
to thisCompositeSubscription
if theCompositeSubscription
is not yet unsubscribed.void
addAll(Subscription... subscriptions)
Adds collection ofSubscription
to thisCompositeSubscription
if theCompositeSubscription
is not yet unsubscribed.void
clear()
Unsubscribes any subscriptions that are currently part of thisCompositeSubscription
and remove them from theCompositeSubscription
so that theCompositeSubscription
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 thisSubscription
is currently unsubscribed.void
remove(Subscription s)
void
unsubscribe()
Unsubscribes itself and all inner subscriptions.private static void
unsubscribeFromAll(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:Subscription
Indicates whether thisSubscription
is currently unsubscribed.- Specified by:
isUnsubscribed
in interfaceSubscription
- Returns:
true
if thisSubscription
is currently unsubscribed,false
otherwise
-
add
public void add(Subscription s)
Adds a newSubscription
to thisCompositeSubscription
if theCompositeSubscription
is not yet unsubscribed. If theCompositeSubscription
is unsubscribed,add
will indicate this by explicitly unsubscribing the newSubscription
as well.- Parameters:
s
- theSubscription
to add
-
addAll
public void addAll(Subscription... subscriptions)
Adds collection ofSubscription
to thisCompositeSubscription
if theCompositeSubscription
is not yet unsubscribed. If theCompositeSubscription
is unsubscribed,addAll
will indicate this by explicitly unsubscribing allSubscription
in collection as well.- Parameters:
subscriptions
- the collection ofSubscription
to add
-
remove
public void remove(Subscription s)
- Parameters:
s
- theSubscription
to remove
-
clear
public void clear()
Unsubscribes any subscriptions that are currently part of thisCompositeSubscription
and remove them from theCompositeSubscription
so that theCompositeSubscription
is empty and able to manage new subscriptions.
-
unsubscribe
public void unsubscribe()
Unsubscribes itself and all inner subscriptions.After call of this method, new
Subscription
s added toCompositeSubscription
will be unsubscribed immediately.- Specified by:
unsubscribe
in 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:
true
if this composite is not unsubscribed and contains subscriptions.- Since:
- 1.0.7
-
-