Interface ValueTransformer<V,VR>
-
- Type Parameters:
V
- value typeVR
- transformed value type
public interface ValueTransformer<V,VR>
TheValueTransformer
interface 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 oftransform(Object)
(cf.ValueMapper
for stateless value transformation). Additionally, thisValueTransformer
canschedule
a method to becalled periodically
with the provided context. IfValueTransformer
is applied to aKeyValue
pair record the record's key is preserved.Use
ValueTransformerSupplier
to provide new instances ofValueTransformer
to Kafka Stream's runtime.If a record's key and value should be modified
Transformer
can be used.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
Close this transformer and clean up any resources.void
init(ProcessorContext context)
Initialize this transformer.VR
transform(V value)
Transform the given value to a new value.
-
-
-
Method Detail
-
init
void 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 callinginit(ProcessorContext)
again.The provided
context
can be used to access topology and record meta data, toschedule
a method to becalled periodically
and to access attachedStateStore
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 withintransform(Object)
.Note that using
ProcessorContext.forward(Object, Object)
orProcessorContext.forward(Object, Object, To)
is not allowed within any method ofValueTransformer
and will result in anexception
.- Parameters:
context
- the context- Throws:
IllegalStateException
- If store gets registered after initialization is already finishedStreamsException
- if the store's change log does not contain the partition
-
transform
VR transform(V value)
Transform the given value to a new value. Additionally, anyStateStore
that isattached
to this operator can be accessed and modified arbitrarily (cf.ProcessorContext.getStateStore(String)
).Note, that using
ProcessorContext.forward(Object, Object)
orProcessorContext.forward(Object, Object, To)
is not allowed withintransform
and will result in anexception
.- Parameters:
value
- the value to be transformed- Returns:
- the new value
-
close
void close()
Close this transformer and clean up any resources. The framework may later re-use this transformer by callinginit(ProcessorContext)
on it again.It is not possible to return any new output records within
close()
. UsingProcessorContext.forward(Object, Object)
orProcessorContext.forward(Object, Object, To)
will result in anexception
.
-
-