Interface ProcessorContext
-
@Evolving public interface ProcessorContextProcessor context interface.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.Object>appConfigs()Returns all the application config properties as key/value pairs.java.util.Map<java.lang.String,java.lang.Object>appConfigsWithPrefix(java.lang.String prefix)Returns all the application config properties with the given key prefix, as key/value pairs stripping the prefix.java.lang.StringapplicationId()Returns the application idjava.lang.StringapplicationInternalStream()Returns the application internal stream namevoidcommit()Requests a commit<K,V>
voidforward(K key, V value)Forwards a key/value pair to the downstream processors<K,V>
voidforward(K key, V value, int childIndex)Forwards a key/value pair to one of the downstream processors designated by childIndex<K,V>
voidforward(K key, V value, java.lang.String childName)Forwards a key/value pair to one of the downstream processors designated by the downstream processor nameStateStoregetStateStore(java.lang.String name)Get the state store given the store name.org.apache.kafka.common.serialization.Serde<?>keySerde()Returns the default key serdeStreamsMetricsmetrics()Returns Metrics instancelongoffset()Returns the offset of the current input record; could be -1 if it is not available (for example, if this method is invoked from the punctuate call)intpartition()Returns the partition id of the current input record; could be -1 if it is not available (for example, if this method is invoked from the punctuate call)voidregister(StateStore store, boolean loggingEnabledIsDeprecatedAndIgnored, StateRestoreCallback stateRestoreCallback)Registers and possibly restores the specified storage engine.voidschedule(long interval)Deprecated.Please useschedule(long, PunctuationType, Punctuator)instead.Cancellableschedule(long intervalMs, PunctuationType type, Punctuator callback)Schedules a periodic operation for processors.java.io.FilestateDir()Returns the state directory for the partition.TaskIdtaskId()Returns the task idlongtimestamp()Returns the current timestamp.java.lang.Stringtopic()Returns the topic name of the current input record; could be null if it is not available (for example, if this method is invoked from the punctuate call)org.apache.kafka.common.serialization.Serde<?>valueSerde()Returns the default value serde
-
-
-
Method Detail
-
applicationId
java.lang.String applicationId()
Returns the application id- Returns:
- the application id
-
applicationInternalStream
java.lang.String applicationInternalStream()
Returns the application internal stream name- Returns:
- the application internal stream
-
taskId
TaskId taskId()
Returns the task id- Returns:
- the task id
-
keySerde
org.apache.kafka.common.serialization.Serde<?> keySerde()
Returns the default key serde- Returns:
- the key serializer
-
valueSerde
org.apache.kafka.common.serialization.Serde<?> valueSerde()
Returns the default value serde- Returns:
- the value serializer
-
stateDir
java.io.File stateDir()
Returns the state directory for the partition.- Returns:
- the state directory
-
metrics
StreamsMetrics metrics()
Returns Metrics instance- Returns:
- StreamsMetrics
-
register
void register(StateStore store, boolean loggingEnabledIsDeprecatedAndIgnored, StateRestoreCallback stateRestoreCallback)
Registers and possibly restores the specified storage engine.- Parameters:
store- the storage engineloggingEnabledIsDeprecatedAndIgnored- deprecated parameterloggingEnabledis ignored: if you want to enable logging on a state stores callStoreBuilder.withLoggingEnabled(Map)when creating the store- Throws:
java.lang.IllegalStateException- If store gets registered after initialized is already finishedStreamsException- if the store's change log does not contain the partition
-
getStateStore
StateStore getStateStore(java.lang.String name)
Get the state store given the store name.- Parameters:
name- The store name- Returns:
- The state store instance
-
schedule
Cancellable schedule(long intervalMs, PunctuationType type, Punctuator callback)
Schedules a periodic operation for processors. A processor may call this method duringinitializationorprocessingto 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 theTimestampExtractorin use. The first punctuation will be triggered by the first record that is processed. NOTE: Only advanced if messages arrivePunctuationType.WALL_CLOCK_TIME- uses system time (the wall-clock time), which is advanced at the polling interval (StreamsConfig.POLL_MS_CONFIG) 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:
intervalMs- the time interval between punctuations in millisecondstype- one of:PunctuationType.STREAM_TIME,PunctuationType.WALL_CLOCK_TIMEcallback- a function consuming timestamps representing the current stream or system time- Returns:
- a handle allowing cancellation of the punctuation schedule established by this method
-
schedule
@Deprecated void schedule(long interval)
Deprecated.Please useschedule(long, PunctuationType, Punctuator)instead.Schedules a periodic operation for processors. A processor may call this method duringinitializationto schedule a periodic call - called a punctuation - toProcessor.punctuate(long).- Parameters:
interval- the time interval between punctuations
-
forward
<K,V> void forward(K key, V value)Forwards a key/value pair to the downstream processors- Parameters:
key- keyvalue- value
-
forward
<K,V> void forward(K key, V value, int childIndex)Forwards a key/value pair to one of the downstream processors designated by childIndex- Parameters:
key- keyvalue- valuechildIndex- index in list of children of this node
-
forward
<K,V> void forward(K key, V value, java.lang.String childName)Forwards a key/value pair to one of the downstream processors designated by the downstream processor name- Parameters:
key- keyvalue- valuechildName- name of downstream processor
-
commit
void commit()
Requests a commit
-
topic
java.lang.String topic()
Returns the topic name of the current input record; could be null if it is not available (for example, if this method is invoked from the punctuate call)- Returns:
- the topic name
-
partition
int partition()
Returns the partition id of the current input record; could be -1 if it is not available (for example, if this method is invoked from the punctuate call)- Returns:
- the partition id
-
offset
long offset()
Returns the offset of the current input record; could be -1 if it is not available (for example, if this method is invoked from the punctuate call)- Returns:
- the offset
-
timestamp
long timestamp()
Returns the current timestamp. If it is triggered while processing a record streamed from the source processor, timestamp is defined as the timestamp of the current input record; the timestamp is extracted fromConsumerRecordbyTimestampExtractor. If it is triggered while processing a record generated not from the source processor (for example, if this method is invoked from the punctuate call), timestamp is defined as the current task's stream time, which is defined as the smallest among all its input stream partition timestamps.- Returns:
- the timestamp
-
appConfigs
java.util.Map<java.lang.String,java.lang.Object> appConfigs()
Returns all the application config properties as key/value pairs. The config properties are defined in theStreamsConfigobject 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
-
appConfigsWithPrefix
java.util.Map<java.lang.String,java.lang.Object> appConfigsWithPrefix(java.lang.String prefix)
Returns all the application config properties with the given key prefix, as key/value pairs stripping the prefix. The config properties are defined in theStreamsConfigobject and associated to the ProcessorContext.- Parameters:
prefix- the properties prefix- Returns:
- the key/values matching the given prefix from the StreamsConfig properties.
-
-