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 Object implements InternalProcessorContext
-
-
Field Summary
Fields Modifier and Type Field Description protected ThreadCache
cache
protected ProcessorNode<?,?>
currentNode
static String
NONEXIST_TOPIC
protected ProcessorRecordContext
recordContext
-
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 Map<String,Object>
appConfigs()
Returns all the application config properties as key/value pairs.Map<String,Object>
appConfigsWithPrefix(String prefix)
Returns all the application config properties with the given key prefix, as key/value pairs stripping the prefix.String
applicationId()
Returns the application id.String
applicationInternalStream()
Returns the application internal stream nameThreadCache
cache()
Get the thread-global cacheProcessorNode<?,?>
currentNode()
Get the currentProcessorNode
long
currentSystemTimeMs()
Headers
headers()
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).void
initialize()
Mark this context as being initializedSerde<?>
keySerde()
Returns the default key serde.StreamsMetricsImpl
metrics()
Returns Metrics instance.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).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)
void
setSystemTimeMs(long timeMs)
File
stateDir()
Returns the state directory for the partition.TaskId
taskId()
Returns the task id.Task.TaskType
taskType()
long
timestamp()
Returns the current timestamp.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 uninitializedSerde<?>
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 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:
setSystemTimeMs
in interfaceInternalProcessorContext
- Parameters:
timeMs
- current wall-clock system timestamp in milliseconds
-
currentSystemTimeMs
public long currentSystemTimeMs()
- Specified by:
currentSystemTimeMs
in interfaceInternalProcessorContext
-
applicationId
public String applicationId()
Description copied from interface:ProcessorContext
Returns the application id.- Specified by:
applicationId
in interfaceProcessorContext
- Returns:
- the application id
-
applicationInternalStream
public 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 Serde<?> keySerde()
Description copied from interface:ProcessorContext
Returns the default key serde.- Specified by:
keySerde
in interfaceProcessorContext
- Returns:
- the key serializer
-
valueSerde
public Serde<?> valueSerde()
Description copied from interface:ProcessorContext
Returns the default value serde.- Specified by:
valueSerde
in interfaceProcessorContext
- Returns:
- the value serializer
-
stateDir
public 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 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:
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:
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:
IllegalStateException
- if offset is null
-
headers
public Headers headers()
Description copied from interface:ProcessorContext
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).- 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 from
ConsumerRecord
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 largest timestamp of any record processed by the task.
- Specified by:
timestamp
in interfaceProcessorContext
- Returns:
- the timestamp
- Throws:
IllegalStateException
- if timestamp is null
-
appConfigs
public Map<String,Object> appConfigs()
Description copied from interface:ProcessorContext
Returns all the application config properties as key/value pairs.The config properties are defined in the
StreamsConfig
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 Map<String,Object> appConfigsWithPrefix(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 the
StreamsConfig
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()
Description copied from interface:InternalProcessorContext
Get the currentProcessorNode
- Specified by:
currentNode
in interfaceInternalProcessorContext
-
cache
public ThreadCache cache()
Description copied from interface:InternalProcessorContext
Get the thread-global cache- Specified by:
cache
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
-
taskType
public Task.TaskType taskType()
- Specified by:
taskType
in interfaceInternalProcessorContext
- Returns:
- the type of task (active/standby/global) that this context corresponds to
-
-