- Type Parameters:
V- value type
VR- transformed value type
public interface ValueTransformer<V,VR>
ValueTransformerinterface for stateful mapping of a value to a new value (with possible new type). This is a stateful record-by-record operation, i.e,
transform(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
ValueMapperfor stateless value transformation). Additionally, this
schedulea method to be
called periodicallywith the provided context. If
ValueTransformeris applied to a
KeyValuepair record the record's key is preserved.
ValueTransformerSupplier to provide new instances of
ValueTransformer to Kafka Stream's runtime.
If a record's key and value should be modified
Transformer can be used.
initvoid init(ProcessorContext context)Initialize this transformer. This is called once per instance when the topology gets initialized. When the framework is done with the transformer,
close()will be called on it; the framework may later re-use the transformer by calling
contextcan be used to access topology and record meta data, to
schedulea method to be
called periodicallyand to access attached
ProcessorContextis updated in the background with the current record's meta data. Thus, it only contains valid record meta data when accessed within
Note that using
ProcessorContext.forward(Object, Object, To)is not allowed within any method of
ValueTransformerand will result in an
context- the context
IllegalStateException- If store gets registered after initialization is already finished
StreamsException- if the store's change log does not contain the partition
transformTransform the given value to a new value. Additionally, any
attachedto this operator can be accessed and modified arbitrarily (cf.
Note, that using
ProcessorContext.forward(Object, Object, To)is not allowed within
transformand will result in an
value- the value to be transformed
- the new value
closevoid close()Close this transformer and clean up any resources. The framework may later re-use this transformer by calling
init(ProcessorContext)on it again.
It is not possible to return any new output records within
ProcessorContext.forward(Object, Object, To)will result in an