K
- key typeV
- value typeR
- KeyValue
return type (both key and value type can be set
arbitrarily)public interface Transformer<K,V,R>
Transformer
interface for stateful mapping of an input record to zero, one, or multiple new output
records (both key and value type can be altered arbitrarily).
This is a stateful record-by-record operation, i.e, transform(Object, Object)
is invoked individually for
each record of a stream and can access and modify a state that is available beyond a single call of
transform(Object, Object)
(cf. KeyValueMapper
for stateless record transformation).
Additionally, this Transformer
can schedule
a method to be called periodically
with the provided context.
Use TransformerSupplier
to provide new instances of Transformer
to Kafka Stream's runtime.
If only a record's value should be modified ValueTransformer
can be used.
Modifier and Type | Method and Description |
---|---|
void |
close()
Close this processor and clean up any resources.
|
void |
init(ProcessorContext context)
Initialize this transformer.
|
R |
punctuate(long timestamp)
Deprecated.
Please use
Punctuator functional interface instead. |
R |
transform(K key,
V value)
Transform the record with the given key and value.
|
void init(ProcessorContext context)
The provided context
can be used to access topology and record meta data, to
schedule
a method to be
called periodically
and to access attached StateStore
s.
Note, that ProcessorContext
is updated in the background with the current record's meta data.
Thus, it only contains valid record meta data when accessed within transform(Object, Object)
.
context
- the contextR transform(K key, V value)
state
that is attached
to this operator can be accessed and modified
arbitrarily (cf. ProcessorContext.getStateStore(String)
).
If more than one output record should be forwarded downstream ProcessorContext.forward(Object, Object)
,
ProcessorContext.forward(Object, Object, int)
, and
ProcessorContext.forward(Object, Object, String)
can be used.
If not record should be forwarded downstream, transform
can return null
.
key
- the key for the recordvalue
- the value for the recordKeyValue
pair—if null
no key-value pair will
be forwarded to down stream@Deprecated R punctuate(long timestamp)
Punctuator
functional interface instead.KeyValue
pairs if this processor
schedules itself
with the context during
initialization
.
To generate new KeyValue
pairs ProcessorContext.forward(Object, Object)
,
ProcessorContext.forward(Object, Object, int)
, and
ProcessorContext.forward(Object, Object, String)
can be used.
Note that punctuate
is called based on TimestampExtractor
)
and not based on wall-clock time.
timestamp
- the stream time when punctuate
is being calledKeyValue
pair to be forwarded to down stream—if null
will not be forwardedvoid close()
To generate new KeyValue
pairs ProcessorContext.forward(Object, Object)
,
ProcessorContext.forward(Object, Object, int)
, and
ProcessorContext.forward(Object, Object, String)
can be used.