Skip to main content

TickLoader API

Writing Messages

Use TickLoader API to create loaders write into TimeBase streams.

  • Pass loadingOptions() and call createLoader(). Refer to public repository to learn more about loading options.
  • Use loader.send() method to send your messages to the loader.
  • Call loader.close() function once writing is completed.
Create a loader
LoadingOptions options = new LoadingOptions();
try (TickLoader<InstrumentMessage> loader = changeStream.createLoader(options)) {
loader.send(message);
}
info

Refer to code samples to view more examples.

Writing Raw Data

Loaders can write messages already bound to native classes or raw messages (unbound).

Loading option Raw
options.raw = true;
info

Refer to Data Encoding for more information about encoding and decoding messages.

Writing Modes

TimeBase can be seen as a chronologically arranged pieces of data. In relation to that, TimeBase offers several different data writing modes that can be set in LoadingOptions.writeMode when creating a new loader:

info

Stream truncation - operation that removes all messages with timestamps that are either equal or newer than the timestamp of the incoming message.

Default writing mode.
When you start writing, the stream is always truncated by the timestamp of the first incoming message (which may have an out of sequence timestamp).
To write all the following messages into a stream, they must go in a chronological order (e.g. T1, T2. T3 ...).
//rewrite
options.writeMode = WriteMode.REWRITE;

//append
options.writeMode = WriteMode.APPEND;

//truncate
options.writeMode = WriteMode.TRUNCATE;

//insert
options.writeMode = WriteMode.INSERT;

Writing Into Spaces

In case you plan to work with data that is not chronologically arranged, you can create dedicated data partitions (spaces) to physically distribute TS files based on their time range or other criteria.

Populate loading option to create a Space
options.space = "mySpace";
info
  • Refer to Data Distribution for more information about working with spaces.
  • Refer to TickCursor API for more information about reading from spaces.
  • Refer to How To to learn more about spaces and how to work with them.

Event Listener

Loaders write messages asynchronously. loader.send() will not therefore, tell whether a specific message has been recorded successfully or not. You can add an Event Listener to a loader to get (track) possible errors.

Adding an event listener to the loader
loader.addEventListener((e) -> System.out.println(e.getMessage()));

Use Error Actions to set a behavior for specific error types:

  • NotifyAndContinue - throw exception in case of an error. Writing continues. Default behavior.
  • NotifyAndAbort - throw exception in case of an error. Writing is aborted.
  • Continue - continue writing in case of an error.
addErrorAction() as loading option
options.addErrorAction(LoadingError.class, LoadingOptions.ErrorAction.NotifyAndAbort);
options.addErrorAction(OutOfSequenceMessageException.class, LoadingOptions.ErrorAction.NotifyAndContinue);
options.addErrorAction(SkipMessageException.class, LoadingOptions.ErrorAction.Continue);

To remove event listener:

loader.removeEventListener(listener);

Subscription Listener

Subscription listener notifies loaders about changes in cursors' subscriptions on the specific stream the loader is writing into.

loader.addSubscriptionListener(listener);
loader.removeSubscriptionListener(listener);
info

Refer to Dynamic Subscription Change for more information about working with cursors' subscriptions.

On-Demand Data Flushing

In some rare cases, e.g. when data is written to a stream throughout an extensive time period, you can use loader.flush() to save all written data on disk. Data flushing is a sync operation.