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:

Default mode. Writes data into a stream and truncates all the existing messages after the timestamp of the first new message.
//truncate
options.writeMode = WriteMode.TRUNCATE;

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 en 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.i. 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.