Class AbstractProcessorContext
- java.lang.Object
-
- org.apache.kafka.streams.processor.internals.AbstractProcessorContext
-
- All Implemented Interfaces:
InternalProcessorContext,ProcessorContext
- Direct Known Subclasses:
GlobalProcessorContextImpl,ProcessorContextImpl
public abstract class AbstractProcessorContext extends java.lang.Object implements InternalProcessorContext
-
-
Field Summary
Fields Modifier and Type Field Description protected ThreadCachecacheprotected ProcessorNode<?,?>currentNodestatic java.lang.StringNONEXIST_TOPICprotected ProcessorRecordContextrecordContext-
Fields inherited from interface org.apache.kafka.streams.processor.internals.InternalProcessorContext
BYTEARRAY_VALUE_SERIALIZER, BYTES_KEY_SERIALIZER
-
-
Constructor Summary
Constructors Constructor Description AbstractProcessorContext(TaskId taskId, StreamsConfig config, StreamsMetricsImpl metrics, org.apache.kafka.streams.processor.internals.StateManager stateManager, ThreadCache cache)
-
Method Summary
All Methods Instance Methods Concrete 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 id.java.lang.StringapplicationInternalStream()Returns the application internal stream nameThreadCachecache()Get the thread-global cacheProcessorNode<?,?>currentNode()Get the currentProcessorNodelongcurrentSystemTimeMs()org.apache.kafka.common.header.Headersheaders()Returns the headers of the current input record; could be null if it is not available (for example, if this method is invoked from the punctuate call).voidinitialize()Mark this context as being initializedorg.apache.kafka.common.serialization.Serde<?>keySerde()Returns the default key serde.StreamsMetricsImplmetrics()Returns Metrics instance.longoffset()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).ProcessorRecordContextrecordContext()Returns the currentRecordContextvoidregister(StateStore store, StateRestoreCallback stateRestoreCallback)Registers and possibly restores the specified storage engine.voidsetCurrentNode(ProcessorNode<?,?> currentNode)voidsetRecordContext(ProcessorRecordContext recordContext)voidsetSystemTimeMs(long timeMs)java.io.FilestateDir()Returns the state directory for the partition.TaskIdtaskId()Returns the task id.Task.TaskTypetaskType()longtimestamp()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).voiduninitialize()Mark this context as being uninitializedorg.apache.kafka.common.serialization.Serde<?>valueSerde()Returns the default value serde.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.kafka.streams.processor.internals.InternalProcessorContext
getStateStore, logChange, registerCacheFlushListener, transitionToActive, transitionToStandby
-
Methods inherited from interface org.apache.kafka.streams.processor.ProcessorContext
commit, forward, forward, forward, forward, getStateStore, schedule, schedule
-
-
-
-
Field Detail
-
NONEXIST_TOPIC
public static final java.lang.String NONEXIST_TOPIC
- See Also:
- Constant Field Values
-
recordContext
protected ProcessorRecordContext recordContext
-
currentNode
protected ProcessorNode<?,?> currentNode
-
cache
protected ThreadCache cache
-
-
Constructor Detail
-
AbstractProcessorContext
public AbstractProcessorContext(TaskId taskId, StreamsConfig config, StreamsMetricsImpl metrics, org.apache.kafka.streams.processor.internals.StateManager stateManager, ThreadCache cache)
-
-
Method Detail
-
setSystemTimeMs
public void setSystemTimeMs(long timeMs)
- Specified by:
setSystemTimeMsin interfaceInternalProcessorContext- Parameters:
timeMs- current wall-clock system timestamp in milliseconds
-
currentSystemTimeMs
public long currentSystemTimeMs()
- Specified by:
currentSystemTimeMsin interfaceInternalProcessorContext
-
applicationId
public java.lang.String applicationId()
Description copied from interface:ProcessorContextReturns the application id.- Specified by:
applicationIdin interfaceProcessorContext- Returns:
- the application id
-
applicationInternalStream
public java.lang.String applicationInternalStream()
Description copied from interface:ProcessorContextReturns the application internal stream name- Specified by:
applicationInternalStreamin interfaceProcessorContext- Returns:
- the application internal stream
-
taskId
public TaskId taskId()
Description copied from interface:ProcessorContextReturns the task id.- Specified by:
taskIdin interfaceProcessorContext- Returns:
- the task id
-
keySerde
public org.apache.kafka.common.serialization.Serde<?> keySerde()
Description copied from interface:ProcessorContextReturns the default key serde.- Specified by:
keySerdein interfaceProcessorContext- Returns:
- the key serializer
-
valueSerde
public org.apache.kafka.common.serialization.Serde<?> valueSerde()
Description copied from interface:ProcessorContextReturns the default value serde.- Specified by:
valueSerdein interfaceProcessorContext- Returns:
- the value serializer
-
stateDir
public java.io.File stateDir()
Description copied from interface:ProcessorContextReturns the state directory for the partition.- Specified by:
stateDirin interfaceProcessorContext- Returns:
- the state directory
-
metrics
public StreamsMetricsImpl metrics()
Description copied from interface:ProcessorContextReturns Metrics instance.- Specified by:
metricsin interfaceInternalProcessorContext- Specified by:
metricsin interfaceProcessorContext- Returns:
- StreamsMetrics
-
register
public void register(StateStore store, StateRestoreCallback stateRestoreCallback)
Description copied from interface:ProcessorContextRegisters and possibly restores the specified storage engine.- Specified by:
registerin interfaceProcessorContext- Parameters:
store- the storage enginestateRestoreCallback- the restoration callback logic for log-backed state stores upon restart
-
topic
public java.lang.String topic()
Description copied from interface:ProcessorContextReturns 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).- Specified by:
topicin interfaceProcessorContext- Returns:
- the topic name
- Throws:
java.lang.IllegalStateException- if the task's record is null
-
partition
public int partition()
Description copied from interface:ProcessorContextReturns 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).- Specified by:
partitionin interfaceProcessorContext- Returns:
- the partition id
- Throws:
java.lang.IllegalStateException- if partition is null
-
offset
public long offset()
Description copied from interface:ProcessorContextReturns 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).- Specified by:
offsetin interfaceProcessorContext- Returns:
- the offset
- Throws:
java.lang.IllegalStateException- if offset is null
-
headers
public org.apache.kafka.common.header.Headers headers()
Description copied from interface:ProcessorContextReturns the headers of the current input record; could be null if it is not available (for example, if this method is invoked from the punctuate call).- Specified by:
headersin interfaceProcessorContext- Returns:
- the headers
-
timestamp
public long timestamp()
Description copied from interface:ProcessorContextReturns 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 from
ConsumerRecordbyTimestampExtractor.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 largest timestamp of any record processed by the task.
- Specified by:
timestampin interfaceProcessorContext- Returns:
- the timestamp
- Throws:
java.lang.IllegalStateException- if timestamp is null
-
appConfigs
public java.util.Map<java.lang.String,java.lang.Object> appConfigs()
Description copied from interface:ProcessorContextReturns 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)).- Specified by:
appConfigsin interfaceProcessorContext- Returns:
- all the key/values from the StreamsConfig properties
-
appConfigsWithPrefix
public java.util.Map<java.lang.String,java.lang.Object> appConfigsWithPrefix(java.lang.String prefix)
Description copied from interface:ProcessorContextReturns 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.- Specified by:
appConfigsWithPrefixin interfaceProcessorContext- Parameters:
prefix- the properties prefix- Returns:
- the key/values matching the given prefix from the StreamsConfig properties.
-
setRecordContext
public void setRecordContext(ProcessorRecordContext recordContext)
- Specified by:
setRecordContextin interfaceInternalProcessorContext- Parameters:
recordContext- theProcessorRecordContextfor the record about to be processes
-
recordContext
public ProcessorRecordContext recordContext()
Description copied from interface:InternalProcessorContextReturns the currentRecordContext- Specified by:
recordContextin interfaceInternalProcessorContext- Returns:
- the current
RecordContext
-
setCurrentNode
public void setCurrentNode(ProcessorNode<?,?> currentNode)
- Specified by:
setCurrentNodein interfaceInternalProcessorContext- Parameters:
currentNode- the currentProcessorNode
-
currentNode
public ProcessorNode<?,?> currentNode()
Description copied from interface:InternalProcessorContextGet the currentProcessorNode- Specified by:
currentNodein interfaceInternalProcessorContext
-
cache
public ThreadCache cache()
Description copied from interface:InternalProcessorContextGet the thread-global cache- Specified by:
cachein interfaceInternalProcessorContext
-
initialize
public void initialize()
Description copied from interface:InternalProcessorContextMark this context as being initialized- Specified by:
initializein interfaceInternalProcessorContext
-
uninitialize
public void uninitialize()
Description copied from interface:InternalProcessorContextMark this context as being uninitialized- Specified by:
uninitializein interfaceInternalProcessorContext
-
taskType
public Task.TaskType taskType()
- Specified by:
taskTypein interfaceInternalProcessorContext- Returns:
- the type of task (active/standby/global) that this context corresponds to
-
-