E
- the type of events.public class TimeSeriesEventModel<E extends TimeSeriesEvent<?>> extends IndexedEventModel<E>
TimeSeriesEvent
class and
arranges incoming events into a list
ordered by their time
.
The model must be configured with symbol
and fromTime
to subscribe and attached
to a DXFeed
instance to start operation.
The view of the current list of events is available via getEventsList
method.
Model change notifications are provided via addListener
method of this list. It accepts an instance of ObservableListModelListener
class.
Users of this model only see the list of events in a consistent state. This model delays incoming events which
are part of incomplete snapshot or ongoing transaction until snapshot is complete or transaction has ended.
These pending events cannot be seen neither via list nor via listener calls, and so
eventFlags
of events in the model are set to zero.
The eventFlags are only used and must be taken into account when processing time-series events directly via low-level
DXFeedSubscription
or DXFeedTimeSeriesSubscription
classes.
dxFeed API comes with a set of samples. DXFeedCandleChart
sample is a very simple UI application
that shows how to use this model with Candle
event to paint a simple candle chart, concentrating your
effort on data representation (painting) logic, while delegating all the data-handling logic to this model.
The convenient way to detach model from the feed is to call its close
method. Closed model
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.
attach
, detach
and close
.
You must query the state of attached
model only from
inside of the notification invocations or from within the thread that performs
those notifications.
Installed ObservableListModelListener
instances are invoked from a separate thread via the executor.
Default executor for all models is configured with DXEndpoint.executor
method. Each model can individually override its executor with setExecutor
method. The corresponding
modelChanged
notification is guaranteed to never be concurrent, even though it may happen from different
threads if executor is multi-threaded.
In practice, it means that is UI applications you must
install UI-thread-bound execution to your DXEndpoint
via
DXEndpoint.executor
method, so that you
can freely use all methods of this model from UI thread.
Custom executor can be used by backend applications that do not need to immediately update this model on
arrival of new events, but want to update the model at a later time, for example, from inside of a servlet request.
This approach is explained with code samples in
Threads and locks
section of DXFeedSubscription
class documentation.
AbstractIndexedEventModel.Entry<V>
Constructor and Description |
---|
TimeSeriesEventModel(Class<? extends E> eventType)
Creates new model.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears subscription symbol and sets
fromTime to Long.MAX_VALUE ,
subsequently, all events in this model are cleared. |
long |
getFromTime()
Returns the time from which to subscribe for time-series, or
Long.MAX_VALUE is not subscribed
(this is a default value). |
Object |
getSymbol()
Returns model subscription symbol, or
null is not subscribed
(this is a default value). |
void |
setFromTime(long fromTime)
Changes the time from which to subscribe for time-series, use
Long.MAX_VALUE to unsubscribe. |
void |
setSymbol(Object symbol)
Changes symbol for this model to subscribe for.
|
close, createEntry, getEventsList, modelChanged
attach, detach, entryListIterator, get, getExecutor, getSizeLimit, isClosed, isSnapshotEnd, listIterator, listIterator, setExecutor, setSizeLimit, size
public TimeSeriesEventModel(Class<? extends E> eventType)
setSymbol(java.lang.Object)
to specify subscription symbol, setFromTime(long)
to specify subscription time, and
AbstractIndexedEventModel.attach(com.dxfeed.api.DXFeed)
method to specify feed to start receiving events.eventType
- the event type.NullPointerException
- if event type is null.public void clear()
fromTime
to Long.MAX_VALUE
,
subsequently, all events in this model are cleared.clear
in class AbstractIndexedEventModel<E extends TimeSeriesEvent<?>,AbstractIndexedEventModel.Entry<E extends TimeSeriesEvent<?>>>
public Object getSymbol()
null
is not subscribed
(this is a default value).getSymbol
in class AbstractIndexedEventModel<E extends TimeSeriesEvent<?>,AbstractIndexedEventModel.Entry<E extends TimeSeriesEvent<?>>>
public void setSymbol(Object symbol)
setSymbol
in class AbstractIndexedEventModel<E extends TimeSeriesEvent<?>,AbstractIndexedEventModel.Entry<E extends TimeSeriesEvent<?>>>
symbol
- model subscription symbol, use null
to unsubscribe.public long getFromTime()
Long.MAX_VALUE
is not subscribed
(this is a default value).public void setFromTime(long fromTime)
Long.MAX_VALUE
to unsubscribe.fromTime
- the time from which to subscribe for time-series, use Long.MAX_VALUE
to unsubscribe.Copyright © 2002–2023 Devexperts LLC. All rights reserved.