E- the type of events.
public class IndexedEventModel<E extends IndexedEvent<?>> extends AbstractIndexedEventModel<E,AbstractIndexedEventModel.Entry<E>>
IndexedEventclass and arranges incoming events into a
listordered by their
index. Note, that
IndexedEventin such a way, that this ordering also orders time-series event by
time. However, there is a time-series aware class
TimeSeriesEventModelthat provides a more convenient way to subscribe to time-series.
The view of the current list of events is available via
Model change notifications are provided via
method of this list. It accepts an instance of
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 indexed events directly via low-level
dxFeed API comes with a set of samples.
DXFeedTimeAndSales sample is a very simple UI application
that shows how to use this model with
TimeAndSale event, for example, concentrating your
effort on data representation logic, while delegating all the data-handling logic to this model.
It also showcases some of the advanced methods of this model like
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.
You must query the state of
attached model only from
inside of the notification invocations or from within the thread that performs
ObservableListModelListener instances are invoked from a separate thread via the executor.
Default executor for all models is configured with
method. Each model can individually override its executor with
method. The corresponding
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.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
DXFeedSubscription class documentation.
|Constructor and Description|
Creates new model.
|Modifier and Type||Method and Description|
Closes this model and makes it permanently detached.
Creates new concrete entry to represent an event in this model.
Returns the view of the current list of events in this model.
Invoked on the change of this model.
attach, clear, detach, entryListIterator, get, getExecutor, getSizeLimit, getSymbol, isClosed, isSnapshotEnd, listIterator, listIterator, setExecutor, setSizeLimit, setSymbol, size
AbstractIndexedEventModel.setSymbol(java.lang.Object)to specify subscription symbol 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 close()
This method ensures that model can be safely garbage-collected when all outside references to it are lost.
public ObservableListModel<E> getEventsList()
protected AbstractIndexedEventModel.Entry<E> createEntry()
This implementation creates an new instance of
protected void modelChanged(List<AbstractIndexedEventModel.Entry<E>> changedEntries)
changedflag set to
trueand the new values of incoming events are available via
Entry.getNewValuemethod. The changed flags is cleared after return from this method by
Entry.commitChangemethod, which can also be invoked during this method, if needed.
Copyright © 2002-2021 Devexperts LLC. All Rights Reserved.