Package com.cognite.client.stream
Class RawPublisher
java.lang.Object
com.cognite.client.stream.AbstractPublisher
com.cognite.client.stream.RawPublisher
This class produces a continuous data stream of rows from a raw table. The raw table is monitored for changes and
all new or changed rows are streamed.
The publisher polls Raw for updates at the
pollingInterval (default every 5 sec.) and push the resulting
batch of RawRow to the registered Consumer.-
Field Summary
Fields inherited from class com.cognite.client.stream.AbstractPublisher
abortStream, DEFAULT_POLLING_INTERVAL, LOG, MAX_END_TIME, MAX_POLLING_INTERVAL, MAX_POLLING_OFFSET, MIN_POLLING_INTERVAL, MIN_POLLING_OFFSET, MIN_START_TIME, state -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic RawPublisherFor internal use.start()Starts the streaming job.withConsumer(Consumer<List<RawRow>> consumer) Add the consumer of the data stream.withEndTime(Instant endTime) Sets the end time (i.e.withPollingInterval(Duration interval) Sets the polling interval to check for updates to the source raw table.withPollingOffset(Duration interval) Sets the polling offset.withStartTime(Instant startTime) Sets the start time (i.e.Methods inherited from class com.cognite.client.stream.AbstractPublisher
abort, getEndTime, getPollingInterval, getPollingOffset, getStartTime
-
Constructor Details
-
RawPublisher
public RawPublisher()
-
-
Method Details
-
of
For internal use. Configures a publisher to stream rows from the specified raw table.- Parameters:
rawRows- The read raw rows api to use for querying Raw.rawDbName- The raw database to read from.rawTableName- The raw table to read from.- Returns:
- The configured
RawPublisher
-
withConsumer
Add the consumer of the data stream. The consumer will be called for each batch ofRawRow. This is potentially a blocking operation, so you should take care to process the batch efficiently (or spin off processing to a separate thread).- Parameters:
consumer- The function to call for each batch ofRawRow.- Returns:
- The
RawPublisherwith the consumer configured.
-
withStartTime
Sets the start time (i.e. the earliest possible created/changed time of the CDF Raw Row) of the data stream. The default start time is at Unix epoch. I.e. the publisher will read all existing rows (if any) in the raw table.- Parameters:
startTime- The start time instant- Returns:
- The
RawPublisherwith the consumer configured.
-
withEndTime
Sets the end time (i.e. the latest possible created/changed time of the CDF Raw Row) of the data stream. The default end time isInstant.MAX. I.e. the publisher will stream data indefinitely, or until aborted.- Parameters:
endTime- The end time instant- Returns:
- The
RawPublisherwith the consumer configured.
-
withPollingInterval
Sets the polling interval to check for updates to the source raw table. The default polling interval is every 5 seconds. You can configure a more or less frequent interval, down to every 0.5 seconds.- Parameters:
interval- The interval to check the source raw table for updates.- Returns:
- The
RawPublisherwith the consumer configured.
-
withPollingOffset
Sets the polling offset. The offset is a time window "buffer" subtracted from the current time when polling for data from CDF Raw. It is intended as a safeguard for clock differences between the client (running this publisher) and the CDF service. For example, if the polling offset is 2 seconds, then this publisher will look for data updates up to (and including) T-2 seconds. That is, data will be streamed with a 2 second fixed latency/delay.- Parameters:
interval- The interval to check the source raw table for updates.- Returns:
- The
RawPublisherwith the consumer configured.
-
start
Starts the streaming job. The job is executed on a separate thread and this method will immediately return to the caller. It returns aFuturethat you can use to block the execution of your own code if you want to explicitly wait for completion of the streaming job.- Overrides:
startin classAbstractPublisher- Returns:
- A Future hosting the end state of the streaming job. The future returns
truewhen the polling loop completes (at its specified end time).falseif the job is aborted before the specified end time.
-