Interface ValueTransformerWithKey<K,V,VR>
- Type Parameters:
- K- key type
- V- value type
- VR- transformed value type
public interface ValueTransformerWithKey<K,V,VR>
ValueTransformerWithKey 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, 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. ValueMapper for stateless value transformation).
 Additionally, this ValueTransformerWithKey can
 schedule a method to be
 called periodically with the provided context.
 Note that the key is read-only and should not be modified, as this can lead to corrupt partitioning.
 If ValueTransformerWithKey is applied to a KeyValue pair record the record's key is preserved.
 
 Use ValueTransformerWithKeySupplier to provide new instances of ValueTransformerWithKey to
 Kafka Stream's runtime.
 
 If a record's key and value should be modified Transformer can be used.
- 
Method Summary
- 
Method Details- 
initInitialize 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, Object).Note that using ProcessorContext.forward(Object, Object)orProcessorContext.forward(Object, Object, To)is not allowed within any method ofValueTransformerWithKeyand will result in anexception.- Parameters:
- context- the context
- Throws:
- 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 [key and] 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)orProcessorContext.forward(Object, Object, To)is not allowed withintransformand will result in anexception.Note that if a ValueTransformerWithKeyis used in aKTable.transformValues(ValueTransformerWithKeySupplier, String...)(or any other overload ofKTable#transformValues(...)) operation, then the providedProcessorContextfrominit(ProcessorContext)does not guarantee that all context information will be available whentransform()is executed, as it might be executed "out-of-band" due to some internal optimizations applied by the Kafka Streams DSL.- Parameters:
- readOnlyKey- the read-only key
- value- the value to be transformed
- Returns:
- the new value
 
- 
closevoid 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)orProcessorContext.forward(Object, Object, To), will result in anexception.
 
-