|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.dxfeed.api.DXFeedSubscription<T>
public class DXFeedSubscription<T>
This class represents a subscription for a set of symbols and event types.
Symbols are represented by objects, simple keys are represented by String
objects,
complex ones use specialized object as described in the corresponding event types.
Each event is represented by a concrete instance of
event class. Event type is represented by a class literal. For example,
Quote.class
is an event type for a best market quote.
Event
class for a list of all built-in event classes.
The set of subscribed symbols and the set of subscribed event types are maintained separately.
The subscription is considered to be interested in the cross-product of these sets. That is, subscription
is interested in any event whose type is in the set of subscribed event types and whose symbol is in the
set of subscribed symbols.
The set of event types is specified when subscription is created and cannot be changed afterward.
The set of symbols can be modified with
setSymbols
, addSymbols
, removeSymbols
,
and clear
methods.
DXFeedEventListener
instances that are notified on any events.
It is important to install all event listeners before changing the set of subscribed symbols.
When the set of subscribed symbols changes all registered event listeners receive update on the
last events for all newly added symbols. Listeners that are installed after that will receive only
newly occurring events.
This class keeps a set of ObservableSubscriptionChangeListener
instances that are notified on any
change in subscription. These listeners are installed by DXFeed
to keep
track of the subscription state and communicate subscription upstream to data providers.
DXFeed.attachSubscription
method.
Subscription that is created via DXFeed.createSubscription
is attached to the
corresponding feed. The feed tracks all changes in subscription by installing
ObservableSubscriptionChangeListener
and invokes
processEvents
for all received events.
Subscription can be detached from the feed with
DXFeed.detachSubscription
method.
Subscription can be attached to multiple feeds at the same time. In this case it receives events from
all feeds but there is no way distinguish which feed the corresponding event came from.
close
method. Closed subscription
becomes permanently detached from all feeds, removes all its listeners and is guaranteed to be reclaimable by the garbage
collector as soon as all external references to it are cleared.
ObservableSubscriptionChangeListener
that is installed by DXFeed
when this subscription is attached is not serializable.
Thus, freshly deserialized instance of this class will be detached. It has to be attached
to the feed after deserialization in order for it to start receiving events.
Constructor Summary | |
---|---|
DXFeedSubscription(java.lang.Class<? extends T>... eventTypes)
Creates detached subscription for the given list of event types. |
|
DXFeedSubscription(java.lang.Class<? extends T> eventType)
Creates detached subscription for a single event type. |
Method Summary | |
---|---|
void |
addChangeListener(ObservableSubscriptionChangeListener listener)
Adds subscription change listener. |
void |
addEventListener(DXFeedEventListener<T> listener)
Adds listener for events. |
void |
addSymbols(java.util.Collection<?> symbols)
Adds the specified collection of symbols to the set of subscribed symbols. |
void |
addSymbols(java.lang.Object... symbols)
Adds the specified array of symbols to the set of subscribed symbols. |
void |
clear()
Clears the set of subscribed symbols. |
void |
close()
Closes this subscription and makes it permanently detached. |
boolean |
containsEventType(java.lang.Class<?> eventType)
Returns true if this subscription contains the corresponding event type. |
java.util.Set<java.lang.Class<? extends T>> |
getEventTypes()
Returns a set of subscribed event types. |
java.util.Set<?> |
getSymbols()
Returns a set of subscribed symbols. |
boolean |
isClosed()
Returns true if this subscription is closed. |
void |
removeChangeListener(ObservableSubscriptionChangeListener listener)
Removes subscription change listener. |
void |
removeEventListener(DXFeedEventListener<T> listener)
Removes listener for events. |
void |
removeSymbols(java.util.Collection<?> symbols)
Removes the specified collection of symbols from the set of subscribed symbols. |
void |
removeSymbols(java.lang.Object... symbols)
Removes the specified array of symbols from the set of subscribed symbols. |
void |
setSymbols(java.util.Collection<?> symbols)
Changes the set of subscribed symbols so that it contains just the symbols from the specified collection. |
void |
setSymbols(java.lang.Object... symbols)
Changes the set of subscribed symbols so that it contains just the symbols from the specified array. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DXFeedSubscription(java.lang.Class<? extends T> eventType)
eventType
- the event types.
java.lang.NullPointerException
- if event type is null.public DXFeedSubscription(java.lang.Class<? extends T>... eventTypes)
eventTypes
- the list of event types.
java.lang.IllegalArgumentException
- if the list of event types is empty.
java.lang.NullPointerException
- if any event type is null.Method Detail |
---|
public boolean isClosed()
true
if this subscription is closed.
isClosed
in interface ObservableSubscription<T>
close()
public void close()
ObservableSubscriptionChangeListener
instances by invoking
subscriptionClosed
while holding the lock for this subscription. This method clears lists of all installed
event listeners and subscription change listeners and makes sure that no more listeners
can be added.
This method ensures that subscription can be safely garbage-collected when all outside references
to it are lost.
public java.util.Set<java.lang.Class<? extends T>> getEventTypes()
getEventTypes
in interface ObservableSubscription<T>
public boolean containsEventType(java.lang.Class<?> eventType)
true
if this subscription contains the corresponding event type.
containsEventType
in interface ObservableSubscription<T>
public void clear()
setSymbols
(Collections.EMPTY_LIST)
public java.util.Set<?> getSymbols()
public void setSymbols(java.util.Collection<?> symbols)
setSymbols(Object... symbols)
method.
All registered event listeners will receive update on the last events for all
newly added symbols.
ObservableSubscriptionChangeListener
instances of any resulting changes in the set of
subscribed symbols while holding the lock for this subscription.
This implementation decorates symbols via protected decorateSymbol(Object)
method,
that can be overridden in subclasses of DXFeedSubscription
. Installed
ObservableSubscriptionChangeListener
instances receive decorated symbols.
symbols
- the collection of symbols.public void setSymbols(java.lang.Object... symbols)
setSymbols(Collection> symbols)
method.
All registered event listeners will receive update on the last events for all
newly added symbols.
ObservableSubscriptionChangeListener
instances of any resulting changes in the set of
subscribed symbols while holding the lock for this subscription.
This implementation decorates symbols via protected decorateSymbol(Object)
method,
that can be overridden in subclasses of DXFeedSubscription
. Installed
ObservableSubscriptionChangeListener
instances receive decorated symbols.
symbols
- the array of symbols.public void addSymbols(java.util.Collection<?> symbols)
addSymbols(Object... symbols)
method.
All registered event listeners will receive update on the last events for all
newly added symbols.
ObservableSubscriptionChangeListener
instances of any resulting changes in the set of
subscribed symbols while holding the lock for this subscription.
This implementation decorates symbols via protected decorateSymbol(Object)
method,
that can be overridden in subclasses of DXFeedSubscription
. Installed
ObservableSubscriptionChangeListener
instances receive decorated symbols.
symbols
- the collection of symbols.public void addSymbols(java.lang.Object... symbols)
addSymbols(Collection> symbols)
method.
All registered event listeners will receive update on the last events for all
newly added symbols.
ObservableSubscriptionChangeListener
instances of any resulting changes in the set of
subscribed symbols while holding the lock for this subscription.
This implementation decorates symbols via protected decorateSymbol(Object)
method
that can be overridden in subclasses of DXFeedSubscription
. Installed
ObservableSubscriptionChangeListener
instances receive decorated symbols.
symbols
- the array of symbols.public void removeSymbols(java.util.Collection<?> symbols)
removeSymbols(Object... symbols)
method.
ObservableSubscriptionChangeListener
instances of any resulting changes in the set of
subscribed symbols while holding the lock for this subscription.
This implementation decorates symbols via protected decorateSymbol(Object)
method,
that can be overridden in subclasses of DXFeedSubscription
. Installed
ObservableSubscriptionChangeListener
instances receive decorated symbols.
symbols
- the collection of symbols.public void removeSymbols(java.lang.Object... symbols)
removeSymbols(Collection> symbols)
method.
ObservableSubscriptionChangeListener
instances of any resulting changes in the set of
subscribed symbols while holding the lock for this subscription.
This implementation decorates symbols via protected decorateSymbol(Object)
method,
that can be overridden in subclasses of DXFeedSubscription
. Installed
ObservableSubscriptionChangeListener
instances receive decorated symbols.
symbols
- the array of symbols.public void addEventListener(DXFeedEventListener<T> listener)
LastingEvent
interface
are sent to newly added listeners only for symbols added to subscription after
invocation of this method.
This method does nothing if this subscription is closed.
listener
- the event listener.
java.lang.NullPointerException
- if listener is null.public void removeEventListener(DXFeedEventListener<T> listener)
listener
- the event listener.
java.lang.NullPointerException
- if listener is null.public void addChangeListener(ObservableSubscriptionChangeListener listener)
ObservableSubscriptionChangeListener.symbolsAdded(java.util.Set>)
on the given listener while holding the lock for this
subscription. This way the given listener synchronously receives existing subscription state and and
is synchronously notified on all changes in subscription afterwards.
addChangeListener
in interface ObservableSubscription<T>
listener
- the subscription change listener.
java.lang.NullPointerException
- if listener is null.public void removeChangeListener(ObservableSubscriptionChangeListener listener)
ObservableSubscriptionChangeListener.subscriptionClosed()
on the given listener while
holding the lock for this subscription.
removeChangeListener
in interface ObservableSubscription<T>
listener
- the subscription change listener.
java.lang.NullPointerException
- if listener is null.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |