Interface ProcessingContext
- All Known Subinterfaces:
- FixedKeyProcessorContext<KForward,,- VForward> - ProcessorContext<KForward,- VForward> 
- All Known Implementing Classes:
- MockProcessorContext
- 
Method SummaryModifier and TypeMethodDescriptionReturns all the application config properties as key/value pairs.appConfigsWithPrefix(String prefix) Return all the application config properties with the given key prefix, as key/value pairs stripping the prefix.Return the application id.voidcommit()Request a commit.longReturn the current stream-time in milliseconds.longReturn the current system timestamp (also called wall-clock time) in milliseconds.<S extends StateStore>
 SgetStateStore(String name) Get the state store given the store name.Serde<?>keySerde()Return the default key serde.metrics()Return Metrics instance.Return the metadata of the current record if available.schedule(Duration interval, PunctuationType type, Punctuator callback) Schedule a periodic operation for processors.stateDir()Return the state directory for the partition.taskId()Return the task id.Serde<?>Return the default value serde.
- 
Method Details- 
applicationIdString applicationId()Return the application id.- Returns:
- the application id
 
- 
taskIdTaskId taskId()Return the task id.- Returns:
- the task id
 
- 
recordMetadataOptional<RecordMetadata> recordMetadata()Return the metadata of the current record if available. Processors may be invoked to process a source record from an input topic, to run a scheduled punctuation (seeschedule(Duration, PunctuationType, Punctuator)), or because a parent processor calledforward(Record).In the case of a punctuation, there is no source record, so this metadata would be undefined. Note that when a punctuator invokes forward(Record), downstream processors will receive the forwarded record as a regularProcessor.process(Record)orFixedKeyProcessor.process(FixedKeyRecord)invocation. In other words, it wouldn't be apparent to downstream processors whether the record being processed came from an input topic or punctuation and therefore whether this metadata is defined. This is why the return type of this method isOptional.If there is any possibility of punctuators upstream, any access to this field should consider the case of " recordMetadata().isPresent() == false". Of course, it would be safest to always guard this condition.
- 
keySerdeSerde<?> keySerde()Return the default key serde.- Returns:
- the key serializer
 
- 
valueSerdeSerde<?> valueSerde()Return the default value serde.- Returns:
- the value serializer
 
- 
stateDirFile stateDir()Return the state directory for the partition.- Returns:
- the state directory
 
- 
metricsStreamsMetrics metrics()Return Metrics instance.- Returns:
- StreamsMetrics
 
- 
getStateStoreGet the state store given the store name.- Type Parameters:
- S- The type or interface of the store to return
- Parameters:
- name- The store name
- Returns:
- The state store instance
- Throws:
- ClassCastException- if the return type isn't a type or interface of the actual returned store.
 
- 
scheduleSchedule a periodic operation for processors. A processor may call this method duringinitialization,processing,initialization, orprocessingto schedule a periodic callback — called a punctuation — toPunctuator.punctuate(long). The type parameter controls what notion of time is used for punctuation:- PunctuationType.STREAM_TIME— uses "stream time", which is advanced by the processing of messages in accordance with the timestamp as extracted by the- TimestampExtractorin use. The first punctuation will be triggered by the first record that is processed. NOTE: Only advanced if messages arrive
- PunctuationType.WALL_CLOCK_TIME— uses system time (the wall-clock time), which is advanced independent of whether new messages arrive. The first punctuation will be triggered after interval has elapsed. NOTE: This is best effort only as its granularity is limited by how long an iteration of the processing loop takes to complete
 - with PunctuationType.STREAM_TIME, when stream time advances more than interval
- with PunctuationType.WALL_CLOCK_TIME, on GC pause, too short interval, ...
 - Parameters:
- interval- the time interval between punctuations (supported minimum is 1 millisecond)
- type- one of:- PunctuationType.STREAM_TIME,- PunctuationType.WALL_CLOCK_TIME
- callback- a function consuming timestamps representing the current stream or system time
- Returns:
- a handle allowing cancellation of the punctuation schedule established by this method
- Throws:
- IllegalArgumentException- if the interval is not representable in milliseconds
 
- 
commitvoid commit()Request a commit. Note that callingcommit()is only a request for a commit, but it does not execute one. Hence, whencommit()returns, no commit was executed yet. However, Kafka Streams will commit as soon as possible, instead of waiting for nextcommit.interval.msto pass.
- 
appConfigsReturns all the application config properties as key/value pairs.The config properties are defined in the StreamsConfigobject and associated to the ProcessorContext.The type of the values is dependent on the typeof the property (e.g. the value ofDEFAULT_KEY_SERDE_CLASS_CONFIGwill be of typeClass, even if it was specified as a String toStreamsConfig(Map)).- Returns:
- all the key/values from the StreamsConfig properties
 
- 
appConfigsWithPrefixReturn all the application config properties with the given key prefix, as key/value pairs stripping the prefix.The config properties are defined in the StreamsConfigobject and associated to the ProcessorContext.- Parameters:
- prefix- the properties prefix
- Returns:
- the key/values matching the given prefix from the StreamsConfig properties.
 
- 
currentSystemTimeMslong currentSystemTimeMs()Return the current system timestamp (also called wall-clock time) in milliseconds.Note: this method returns the internally cached system timestamp from the Kafka Stream runtime. Thus, it may return a different value compared to System.currentTimeMillis().- Returns:
- the current system timestamp in milliseconds
 
- 
currentStreamTimeMslong currentStreamTimeMs()Return the current stream-time in milliseconds.Stream-time is the maximum observed record timestampso far (including the currently processed record), i.e., it can be considered a high-watermark. Stream-time is tracked on a per-task basis and is preserved across restarts and during task migration.Note: this method is not supported for global processors (cf. Topology.addGlobalStore(org.apache.kafka.streams.state.StoreBuilder<?>, java.lang.String, org.apache.kafka.common.serialization.Deserializer<K>, org.apache.kafka.common.serialization.Deserializer<V>, java.lang.String, java.lang.String, org.apache.kafka.streams.processor.ProcessorSupplier<K, V>)(...) andStreamsBuilder.addGlobalStore(org.apache.kafka.streams.state.StoreBuilder<?>, java.lang.String, org.apache.kafka.streams.kstream.Consumed<K, V>, org.apache.kafka.streams.processor.ProcessorSupplier<K, V>)(...), because there is no concept of stream-time for this case. Calling this method in a global processor will result in anUnsupportedOperationException.- Returns:
- the current stream-time in milliseconds
 
 
-