|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.dxfeed.api.DXFeedSubscription<T>
public final class DXFeedSubscription<T extends Event>
This class represents a subscription for a set of symbols and event types.
Symbols are represented by String
objects. Each event is represented by a concrete instance of
Event
class. Event type is represented by a Class<Event>
class literal. For example,
Quote.class
is an event type for a best market quote.
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 occuring events.
This class keeps a set of DXFeedSubscriptionChangeListener
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
DXFeedSubscriptionChangeListener
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.
DXFeedSubscriptionChangeListener
that is installed by DXFeed
when this subscrition 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 set of event types. |
Method Summary | |
---|---|
void |
addEventListener(DXFeedEventListener<T> listener)
Adds listener for events. |
void |
addSubscriptionChangeListener(DXFeedSubscriptionChangeListener listener)
Adds subscription change listener. |
void |
addSymbols(java.util.Collection<java.lang.String> symbols)
Adds a collection 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<? extends Event> 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<java.lang.String> |
getSymbols()
Returns a set of subscribed symbols. |
boolean |
isClosed()
Returns true if this subscription is closed. |
void |
processEvents(java.util.List<T> events)
Processes received events. |
void |
removeEventListener(DXFeedEventListener<T> listener)
Removes listener for events. |
void |
removeSubscriptionChangeListener(DXFeedSubscriptionChangeListener listener)
Removes subscription change listener. |
void |
removeSymbols(java.util.Collection<java.lang.String> symbols)
Removes a collection of symbols from the set of subscribed symbols. |
void |
setSymbols(java.util.Collection<java.lang.String> symbols)
Changes the set of subscribed symbols so that it contains just the symbols from the specified collection. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DXFeedSubscription(java.lang.Class<? extends T>... eventTypes)
eventTypes
- the set of event types.
java.lang.IllegalArgumentException
- if the set 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.
close()
public void close()
DXFeedSubscriptionChangeListener
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()
public boolean containsEventType(java.lang.Class<? extends Event> eventType)
true
if this subscription contains the corresponding event type.
public void clear()
setSymbols
(Collections.<String>emptyList())
public java.util.Set<java.lang.String> getSymbols()
public void setSymbols(java.util.Collection<java.lang.String> symbols)
DXFeedSubscriptionChangeListener
instances of any resulting changes in the set of
subscribed symbols while holding the lock for this subscription.
All registered event listeners will receive update on the last events for all
newly added symbols.
symbols
- the collection of symbols.public void addSymbols(java.util.Collection<java.lang.String> symbols)
DXFeedSubscriptionChangeListener
instances of any resulting changes in the set of
subscribed symbols while holding the lock for this subscription.
All registered event listeners will receive update on the last events for all
newly added symbols.
symbols
- the collection of symbols.public void removeSymbols(java.util.Collection<java.lang.String> symbols)
DXFeedSubscriptionChangeListener
instances of any resulting changes in the set of
subscribed symbols while holding the lock for this subscription.
symbols
- the collection of symbols.public void processEvents(java.util.List<T> events)
DXFeedEventListener.eventsReceived(java.util.List)
on all installed
event listeners.
events
- the list of received events.public void addEventListener(DXFeedEventListener<T> listener)
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 addSubscriptionChangeListener(DXFeedSubscriptionChangeListener listener)
DXFeedSubscriptionChangeListener.symbolsAdded(com.dxfeed.api.DXFeedSubscription>, java.util.Collection)
on the given listener while holding the lock for this
subscription. This way the given listener synchronously receives existing subscription state and and
is synchronosly notified on all changes in subscription afterwards.
listener
- the subscription change listener.
java.lang.NullPointerException
- if listener is null.public void removeSubscriptionChangeListener(DXFeedSubscriptionChangeListener listener)
DXFeedSubscriptionChangeListener.subscriptionClosed(com.dxfeed.api.DXFeedSubscription>)
on the given listener while
holding the lock for this subscription.
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 |