public abstract class OnDemandService extends Object
As single OnDemandService instance
is conceptually associated with each DXEndpoint endpoint instance with the role
of FEED or ON_DEMAND_FEED.
You can retrieve OnDemandService instance that is associated with a given
DXEndpoint using getInstance(endpoint) method.
For example, OnDemandService instance for a default DXFeed that is
featured in the documentation of DXFeed class and is retrieved via
DXFeed.getInstance() method can be acquired with the following code:
This instance can be used for on-demand historical tick data replay only when endpoint is connected to the on-demand data provider and the appropriate credentials are provided.DXEndpointendpoint =DXEndpoint.getInstance(); OnDemandService onDemand =getInstance(endpoint);
isReplaySupported returns true when it is so.
On-demand replay is started with replay method that takes time as a parameters.
DXFeed is then disconnected from other data providers, pre-buffers historical tick data for replay,
and starts replay of the data as if it was coming from the data feeds now. All the usual APIs that are
part of DXFeed like subscription and various models
can be used normally as with the ordinary real-time or delayed data feed.
Replay speed can be changed on the fly with setSpeed method or it can be set
initially when starting replay with a two-argument version of replay method.
pause() method is the same as setSpeed(0).
stopAndResume method stops data replay and resumes ordinary real-time or delayed data feed
that was used before replay method was invoked.
Endpoints with a role of
ON_DEMAND_FEED do not have an ordinary feed (they are essentially on-demand only)
and thus stopAndResume method works like stopAndClear for them.
isReplaySupported,
isReplay, getSpeed, and getTime methods. The changes
in those values can be tracked by installing PropertyChangeListener with
addPropertyChangeListener method.
All change notifications happen using executor that is configured for the
corresponding DXEndpoint with DXEndpoint.executor(...) method.
Implementation of this class is available only when the optional "dxfeed-ondemand.jar" is in the class-path.
| Modifier | Constructor and Description |
|---|---|
protected |
OnDemandService()
Protected constructor for implementations of
OnDemandService. |
| Modifier and Type | Method and Description |
|---|---|
abstract void |
addPropertyChangeListener(PropertyChangeListener listener)
Adds listener that is notified about changes in on-demand service properties.
|
abstract DXEndpoint |
getEndpoint()
Returns
DXEndpoint that is associated with this on-demand service. |
static OnDemandService |
getInstance()
Returns on-demand service for the default
DXEndpoint instance with
ON_DEMAND_FEED role that is
not connected to any other real-time or delayed data feed. |
static OnDemandService |
getInstance(DXEndpoint endpoint)
Returns on-demand service for the specified
DXEndpoint. |
abstract double |
getSpeed()
Returns on-demand historical data replay speed.
|
abstract Date |
getTime()
Returns current or last on-demand historical data replay time.
|
protected abstract void |
initImpl(DXEndpoint endpoint)
Protected initialization method to bind
OnDemandService instance to DXEndpoint instance. |
abstract boolean |
isClear()
Returns true when this on-demand historical data replay service is in clear mode.
|
abstract boolean |
isReplay()
Returns true when this on-demand historical data replay service is in replay mode.
|
abstract boolean |
isReplaySupported()
Returns
true when on-demand historical data replay mode is supported. |
abstract void |
pause()
Pauses on-demand historical data replay and keeps data snapshot.
|
abstract void |
removePropertyChangeListener(PropertyChangeListener listener)
Removes listener that is notified about changes in on-demand service properties.
|
void |
replay(Date time)
Turns on-demand historical data replay mode from a specified time with real-time speed.
|
abstract void |
replay(Date time,
double speed)
Turns on-demand historical data replay mode from a specified time and with a specified speed.
|
abstract void |
setSpeed(double speed)
Changes on-demand historical data replay speed while continuing replay at current
getTime() time}. |
abstract void |
stopAndClear()
Stops incoming data and clears it without resuming data updates.
|
abstract void |
stopAndResume()
Stops on-demand historical data replay and resumes ordinary data feed.
|
protected OnDemandService()
OnDemandService.public static OnDemandService getInstance()
DXEndpoint instance with
ON_DEMAND_FEED role that is
not connected to any other real-time or delayed data feed.
This method is a shortcut for:
OnDemandService.getInstance(DXEndpoint.getInstance(ON_DEMAND_FEED))
If you need an instance of OnDemandService to seamlessly switch from other real-time or delayed
data feed to on-demand historical tick data replay, then use
getInstance(endpoint) method for a specific endpoint that
you are using.
This method works only when the optional "dxfeed-ondemand.jar" is in the class-path.
DXEndpoint instance.UnsupportedOperationException - if "dxfeed-ondemand.jar" is not in the class-path.public static OnDemandService getInstance(DXEndpoint endpoint)
DXEndpoint.
Each DXEndpoint is conceptually associated with a single instance of on-demand service to
control its historic data replay and this method returns this instance.
The endpoint must have a role of
FEED or ON_DEMAND_FEED.
This method works only when the optional "dxfeed-ondemand.jar" is in the class-path.
endpoint - the endpoint.UnsupportedOperationException - if "dxfeed-ondemand.jar" is not in the class-path.IllegalArgumentException - if the specified endpoint has unsupported class or wrong role.protected abstract void initImpl(DXEndpoint endpoint)
OnDemandService instance to DXEndpoint instance.
This method is invoked in implementation-specific fashion under implementation specific lock.endpoint - the endpoint.public abstract DXEndpoint getEndpoint()
DXEndpoint that is associated with this on-demand service.DXEndpoint that is associated with this on-demand service.public abstract boolean isReplaySupported()
true when on-demand historical data replay mode is supported.
DXEndpoint should be connected
to an address with "(ondemand:<address>)" component that specifies an on-demand historical
data provider address.
When this method returns false, replay method throws
IllegalStateException.true when on-demand historical data replay mode is supported.public abstract boolean isReplay()
replay method and
before invocation stopAndResume or stopAndClear methods.public abstract boolean isClear()
stopAndClear() method and
before invocation stopAndResume or replay methods.public abstract Date getTime()
replay mode this is the time that is being currently replayed,
otherwise this is the last time that was replayed.
If replay was never started, then result is new Date(0).public abstract double getSpeed()
replay mode.
The speed is set when starting replay by replay(time, speed) method
and with setSpeed(speed) method during replay.public final void replay(Date time)
replay(time, 1);
This method can be used only when isReplaySupported() method returns true,
that is when DXEndpoint is connected
to an address with "(ondemand:<address>)" component that specifies an on-demand historical
data provider address.time - time to start replay from.IllegalStateException - when isReplaySupported() is false.NullPointerException - if time is null.replay(Date, double),
isReplaySupported()public abstract void replay(Date time, double speed)
isReplaySupported() method returns true,
that is when DXEndpoint is connected
to an address with "(ondemand:<address>)" component that specifies an on-demand historical
data provider address.
After invocation of this method:
isReplay() returns true.
isClear() returns false.
getTime() returns time that is currently being replayed.
getSpeed() returns speed.
time - time to start replay from.speed - speed to start replay with. Use 1 for real-time speed, >1 for faster than real-time speed,
<1 for slower than real-time speed, and 0 for pause.IllegalStateException - when isReplaySupported() is false.IllegalArgumentException - if speed < 0.NullPointerException - when if is null.isReplaySupported()public abstract void pause()
replay mode.
This is a shortcut for:
setSpeed(0);
This method atomically captures current replay time and pauses at it.
After invocation of this method:
isReplay() returns true.
isClear() returns false.
getTime() returns time where replay was paused at.
getSpeed() returns 0.
IllegalStateException - if on-demand service was not in replay mode.public abstract void stopAndResume()
replay mode.
After invocation of this method:
isReplay() returns false.
isClear() returns false.
getTime() returns last replayed time.
getSpeed() returns 0.
To stop on-demand historical data replay without resuming ordinary data feed use
either pause() to keep data snapshot or stopAndClear() to clear data.
Note, that endpoints with a role of
ON_DEMAND_FEED do not have an ordinary feed (they are essentially on-demand only)
and thus stopAndResume method works like stopAndClear for them.
public abstract void stopAndClear()
isReplay() returns false.
isClear() returns true.
getTime() returns last replayed time.
getSpeed() returns 0.
Ordinary data feed can be resumed with stopAndResume() method and on-demand historical data
replay can be continued with replay(...) method.
public abstract void setSpeed(double speed)
getTime() time}.
Speed is measured with respect to the real-time playback speed.
This method can only be called with non-zero speed in replay mode.speed - on-demand historical data replay speed.IllegalStateException - if on-demand service was not in replay mode and speed != 0.IllegalArgumentException - if speed < 0.public abstract void addPropertyChangeListener(PropertyChangeListener listener)
endpoint's executor.
The following properties are supported:
replaySupported,
replay,
clear,
speed, and
time.
Installed listener can be removed with
removePropertyChangeListener method.
listener - the listener to add.public abstract void removePropertyChangeListener(PropertyChangeListener listener)
addPropertyChangeListener method.listener - the listener to remove.Copyright © 2002–2023 Devexperts LLC. All rights reserved.