Package com.cognite.client.stream
Class RawPublisher
- java.lang.Object
-
- com.cognite.client.stream.RawPublisher
-
public abstract class RawPublisher extends Object
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 thepollingInterval(default every 5 sec.) and push the resulting batch ofRawRowto the registeredConsumer.
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.LoggerLOG
-
Constructor Summary
Constructors Constructor Description RawPublisher()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort()Aborts the current stream operation.static RawPublisherof(RawRows rawRows, String rawDbName, String rawTableName)For internal use.Future<Boolean>start()Starts the streaming job.RawPublisherwithConsumer(Consumer<List<com.cognite.client.dto.RawRow>> consumer)Add the consumer of the data stream.RawPublisherwithEndTime(Instant endTime)Sets the end time (i.e.RawPublisherwithPollingInterval(Duration interval)Sets the polling interval to check for updates to the source raw table.RawPublisherwithPollingOffset(Duration interval)Sets the polling offset.RawPublisherwithStartTime(Instant startTime)Sets the start time (i.e.
-
-
-
Method Detail
-
of
public static RawPublisher of(RawRows rawRows, String rawDbName, String rawTableName)
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
public RawPublisher withConsumer(Consumer<List<com.cognite.client.dto.RawRow>> consumer)
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
public RawPublisher withStartTime(Instant startTime)
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
public RawPublisher withEndTime(Instant endTime)
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
public RawPublisher withPollingInterval(Duration interval)
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
public RawPublisher withPollingOffset(Duration interval)
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
public Future<Boolean> 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.- 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.
-
abort
public void abort()
Aborts the current stream operation. It may take a few seconds for this operation to complete.
-
-