public abstract class DXPublisher extends Object
feeds
.
getInstance()
method.
It is created on the first use with default configuration properties that are explained in detail in
documentation for DXEndpoint
class in the "Default properties" section. In particular,
you can provide a default address to connect using
"dxpublisher.address
"
system property or by putting it into
"dxpublisher.properties
"
file on JVM classpath.
Quote
quote = new Quote("A:TEST"); quote.setBidPrice(100); quote.setAskPrice(101);DXPublisher
.getInstance
().publishEvents
(Arrays.asList(quote));
Profile
events and for any subscription
on the string symbols that end with ":TEST" string generates and publishes a profile.
finalDXPublisher
publisher =DXPublisher
.getInstance
(); publisher.getSubscription
(Profile
.class).addChangeListener
(newObservableSubscriptionChangeListener
() { public voidsymbolsAdded
(Set<?> symbols) { List<Profile> events = new ArrayList<Profile>(); for (Object symbol : symbols) { if (symbol instanceof String) { String s = (String) symbol; if (s.endsWith(":TEST")) { Profile profile = new Profile(s); profile.setDescription("Test symbol"); events.add(profile); } } } publisher.publishEvents
(events); } public void symbolsRemoved(Set<?> symbols) { // nothing to do here } public void subscriptionClosed() { // nothing to do here } });
Modifier | Constructor and Description |
---|---|
protected |
DXPublisher()
Protected constructor for implementations of this class only.
|
Modifier and Type | Method and Description |
---|---|
static DXPublisher |
getInstance()
Returns a default application-wide singleton instance of DXPublisher.
|
abstract <E> ObservableSubscription<E> |
getSubscription(Class<E> eventType)
Returns observable set of subscribed symbols for the specified event type.
|
abstract void |
publishEvents(Collection<?> events)
Publishes events to the corresponding feed.
|
protected DXPublisher()
public static DXPublisher getInstance()
DXEndpoint
.getInstance
(DXEndpoint.Role.PUBLISHER
).getPublisher
().public abstract void publishEvents(Collection<?> events)
endpoint
of this publisher has
role
of DXEndpoint.Role.PUBLISHER
and it is connected, the
published events will be delivered to the remote endpoints. Local feed
will
always receive published events.
This method serializes all events into internal representation, so that the instance of the collection as well as the instances of events can be reused after invocation of this method returns.
DXFeed
instances that are connected to this publisher either locally or via network
receive published events if and only if they are subscribed to the corresponding symbols, or
they are subscribed via WildcardSymbol.ALL
, or, in case of
TimeSeriesEvent
type, they are subscribed via DXFeedTimeSeriesSubscription
for
the corresponding symbol and time frame.
Published events are not stored and get immediately lost if there is no subscription.
Last published events of LastingEvent
types are cached as long as subscription to
them is maintained via a specific event symbol (WildcardSymbol.ALL
does not count)
and the cache is discarded as soon as subscription disappears.
events
- the collection of events to publish.public abstract <E> ObservableSubscription<E> getSubscription(Class<E> eventType)
ObservableSubscription
using instanceof
operation.
The set of subscribed symbols contains WildcardSymbol.ALL
if and
only if there is a subscription to this wildcard symbol.
If DXFeedTimeSeriesSubscription
is used
to subscribe to time-service of the events of this type, then instances of
TimeSeriesSubscriptionSymbol
class represent the corresponding subscription item.
The resulting observable subscription can generate repeated
symbolsAdded
notifications to
its listeners for the same symbols without the corresponding
symbolsRemoved
notifications in between them. It happens when subscription disappears, cached data is lost, and subscription
reappears again. On each symbolsAdded
notification data provider shall publish
the most recent events for
the corresponding symbols.
E
- the type of event.eventType
- the class of event.Copyright © 2002–2023 Devexperts LLC. All rights reserved.