Interface ValueTransformer<V,VR>
-
- Type Parameters:
V- value typeVR- transformed value type
public interface ValueTransformer<V,VR>TheValueTransformerinterface 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.ValueMapperfor stateless value transformation). Additionally, thisValueTransformercanschedulea method to becalled periodicallywith the provided context. IfValueTransformeris applied to aKeyValuepair record the record's key is preserved.Use
ValueTransformerSupplierto provide new instances ofValueTransformerto Kafka Stream's runtime.If a record's key and value should be modified
Transformercan be used.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description voidclose()Close this processor and clean up any resources.voidinit(ProcessorContext context)Initialize this transformer.VRpunctuate(long timestamp)Deprecated.Please usePunctuatorfunctional interface instead.VRtransform(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.The provided
contextcan be used to access topology and record meta data, toschedulea method to becalled periodicallyand to access attachedStateStores.Note that
ProcessorContextis 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),ProcessorContext.forward(Object, Object, int), orProcessorContext.forward(Object, Object, String)is not allowed within any method ofValueTransformerand will result in anexception.- Parameters:
context- the context- Throws:
java.lang.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, anyStateStorethat isattachedto this operator can be accessed and modified arbitrarily (cf.ProcessorContext.getStateStore(String)).Note, that using
ProcessorContext.forward(Object, Object),ProcessorContext.forward(Object, Object, int), andProcessorContext.forward(Object, Object, String)is not allowed withintransformand will result in anexception.- Parameters:
value- the value to be transformed- Returns:
- the new value
-
punctuate
@Deprecated VR punctuate(long timestamp)
Deprecated.Please usePunctuatorfunctional interface instead.Perform any periodic operations if this processorschedule itselfwith the context duringinitialization.It is not possible to return any new output records within
punctuate. UsingProcessorContext.forward(Object, Object),ProcessorContext.forward(Object, Object, int), orProcessorContext.forward(Object, Object, String)will result in anexception. Furthermore,punctuatemust returnnull.Note, that
punctuateis called base onstream time (i.e., time progress with regard to timestamps return by the usedTimestampExtractor) and not based on wall-clock time.- Parameters:
timestamp- the stream time whenpunctuateis being called- Returns:
- must return
null—otherwise, anexceptionwill be thrown
-
close
void close()
Close this processor and clean up any resources.It is not possible to return any new output records within
close(). UsingProcessorContext.forward(Object, Object),ProcessorContext.forward(Object, Object, int), orProcessorContext.forward(Object, Object, String)will result in anexception.
-
-