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 ProcessorNode
currentNode
static java.lang.String
NONEXIST_TOPIC
protected ProcessorRecordContext
recordContext
-
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.String
applicationId()
Returns the application idjava.lang.String
applicationInternalStream()
Returns the application internal stream nameProcessorNode
currentNode()
ThreadCache
getCache()
Get the thread-global cacheorg.apache.kafka.common.header.Headers
headers()
Returns the headers of the current input record; could be null if it is not availablevoid
initialize()
Mark this context as being initializedorg.apache.kafka.common.serialization.Serde<?>
keySerde()
Returns the default key serdeStreamsMetricsImpl
metrics()
Returns Metrics instancelong
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)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)ProcessorRecordContext
recordContext()
Returns the currentRecordContext
void
register(StateStore store, StateRestoreCallback stateRestoreCallback)
Registers and possibly restores the specified storage engine.void
setCurrentNode(ProcessorNode currentNode)
void
setRecordContext(ProcessorRecordContext recordContext)
java.io.File
stateDir()
Returns the state directory for the partition.TaskId
taskId()
Returns the task idlong
timestamp()
Returns the current timestamp.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)void
uninitialize()
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
streamTime
-
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
-
-
Constructor Detail
-
AbstractProcessorContext
public AbstractProcessorContext(TaskId taskId, StreamsConfig config, StreamsMetricsImpl metrics, org.apache.kafka.streams.processor.internals.StateManager stateManager, ThreadCache cache)
-
-
Method Detail
-
applicationId
public java.lang.String applicationId()
Description copied from interface:ProcessorContext
Returns the application id- Specified by:
applicationId
in interfaceProcessorContext
- Returns:
- the application id
-
applicationInternalStream
public java.lang.String applicationInternalStream()
Description copied from interface:ProcessorContext
Returns the application internal stream name- Specified by:
applicationInternalStream
in interfaceProcessorContext
- Returns:
- the application internal stream
-
taskId
public TaskId taskId()
Description copied from interface:ProcessorContext
Returns the task id- Specified by:
taskId
in interfaceProcessorContext
- Returns:
- the task id
-
keySerde
public org.apache.kafka.common.serialization.Serde<?> keySerde()
Description copied from interface:ProcessorContext
Returns the default key serde- Specified by:
keySerde
in interfaceProcessorContext
- Returns:
- the key serializer
-
valueSerde
public org.apache.kafka.common.serialization.Serde<?> valueSerde()
Description copied from interface:ProcessorContext
Returns the default value serde- Specified by:
valueSerde
in interfaceProcessorContext
- Returns:
- the value serializer
-
stateDir
public java.io.File stateDir()
Description copied from interface:ProcessorContext
Returns the state directory for the partition.- Specified by:
stateDir
in interfaceProcessorContext
- Returns:
- the state directory
-
metrics
public StreamsMetricsImpl metrics()
Description copied from interface:ProcessorContext
Returns Metrics instance- Specified by:
metrics
in interfaceInternalProcessorContext
- Specified by:
metrics
in interfaceProcessorContext
- Returns:
- StreamsMetrics
-
register
public void register(StateStore store, StateRestoreCallback stateRestoreCallback)
Description copied from interface:ProcessorContext
Registers and possibly restores the specified storage engine.- Specified by:
register
in 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:ProcessorContext
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)- Specified by:
topic
in interfaceProcessorContext
- Returns:
- the topic name
- Throws:
java.lang.IllegalStateException
- if the task's record is null
-
partition
public int partition()
Description copied from interface:ProcessorContext
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)- Specified by:
partition
in interfaceProcessorContext
- Returns:
- the partition id
- Throws:
java.lang.IllegalStateException
- if partition is null
-
offset
public long offset()
Description copied from interface:ProcessorContext
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)- Specified by:
offset
in 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:ProcessorContext
Returns the headers of the current input record; could be null if it is not available- Specified by:
headers
in interfaceProcessorContext
- Returns:
- the headers
-
timestamp
public long timestamp()
Description copied from interface:ProcessorContext
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 fromConsumerRecord
byTimestampExtractor
. 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.- Specified by:
timestamp
in 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:ProcessorContext
Returns all the application config properties as key/value pairs. The config properties are defined in theStreamsConfig
object and associated to the ProcessorContext.The type of the values is dependent on the
type
of the property (e.g. the value ofDEFAULT_KEY_SERDE_CLASS_CONFIG
will be of typeClass
, even if it was specified as a String toStreamsConfig(Map)
).- Specified by:
appConfigs
in 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:ProcessorContext
Returns all the application config properties with the given key prefix, as key/value pairs stripping the prefix. The config properties are defined in theStreamsConfig
object and associated to the ProcessorContext.- Specified by:
appConfigsWithPrefix
in 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:
setRecordContext
in interfaceInternalProcessorContext
- Parameters:
recordContext
- theProcessorRecordContext
for the record about to be processes
-
recordContext
public ProcessorRecordContext recordContext()
Description copied from interface:InternalProcessorContext
Returns the currentRecordContext
- Specified by:
recordContext
in interfaceInternalProcessorContext
- Returns:
- the current
RecordContext
-
setCurrentNode
public void setCurrentNode(ProcessorNode currentNode)
- Specified by:
setCurrentNode
in interfaceInternalProcessorContext
- Parameters:
currentNode
- the currentProcessorNode
-
currentNode
public ProcessorNode currentNode()
- Specified by:
currentNode
in interfaceInternalProcessorContext
-
getCache
public ThreadCache getCache()
Description copied from interface:InternalProcessorContext
Get the thread-global cache- Specified by:
getCache
in interfaceInternalProcessorContext
-
initialize
public void initialize()
Description copied from interface:InternalProcessorContext
Mark this context as being initialized- Specified by:
initialize
in interfaceInternalProcessorContext
-
uninitialize
public void uninitialize()
Description copied from interface:InternalProcessorContext
Mark this context as being uninitialized- Specified by:
uninitialize
in interfaceInternalProcessorContext
-
-