Class Record<K,V>
- java.lang.Object
-
- org.apache.kafka.streams.processor.api.Record<K,V>
-
- Type Parameters:
K
- The type of the keyV
- The type of the value
public class Record<K,V> extends Object
A data class representing an incoming record for processing in aProcessor
or a record to forward to downstream processors viaProcessorContext
. This class encapsulates all the data attributes of a record: the key and value, but also the timestamp of the record and any record headers. This class is immutable, though the objects referenced in the attributes of this class may themselves be mutable.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
int
hashCode()
Headers
headers()
The headers of the record.K
key()
The key of the record.long
timestamp()
The timestamp of the record.String
toString()
V
value()
The value of the record.Record<K,V>
withHeaders(Headers headers)
A convenient way to produce a new record if you only need to change the headers.<NewK> Record<NewK,V>
withKey(NewK key)
A convenient way to produce a new record if you only need to change the key.Record<K,V>
withTimestamp(long timestamp)
A convenient way to produce a new record if you only need to change the timestamp.<NewV> Record<K,NewV>
withValue(NewV value)
A convenient way to produce a new record if you only need to change the value.
-
-
-
Constructor Detail
-
Record
public Record(K key, V value, long timestamp, Headers headers)
The full constructor, specifying all the attributes of the record. Note: this constructor makes a copy of the headers argument. SeeProcessorContext.forward(Record)
for considerations around mutability of keys, values, and headers.- Parameters:
key
- The key of the record. May be null.value
- The value of the record. May be null.timestamp
- The timestamp of the record. May not be negative.headers
- The headers of the record. May be null, which will cause subsequent calls toheaders()
to return a non-null, empty,Headers
collection.- Throws:
IllegalArgumentException
- if the timestamp is negative.- See Also:
ProcessorContext.forward(Record)
-
Record
public Record(K key, V value, long timestamp)
Convenience constructor in case you do not wish to specify any headers. Subsequent calls toheaders()
will return a non-null, empty,Headers
collection.- Parameters:
key
- The key of the record. May be null.value
- The value of the record. May be null.timestamp
- The timestamp of the record. May not be negative.- Throws:
IllegalArgumentException
- if the timestamp is negative.
-
-
Method Detail
-
key
public K key()
The key of the record. May be null.
-
value
public V value()
The value of the record. May be null.
-
timestamp
public long timestamp()
The timestamp of the record. Will never be negative.
-
headers
public Headers headers()
The headers of the record. Never null.
-
withKey
public <NewK> Record<NewK,V> withKey(NewK key)
A convenient way to produce a new record if you only need to change the key. Copies the attributes of this record with the key replaced.- Type Parameters:
NewK
- The type of the new record's key.- Parameters:
key
- The key of the result record. May be null.- Returns:
- A new Record instance with all the same attributes (except that the key is replaced).
-
withValue
public <NewV> Record<K,NewV> withValue(NewV value)
A convenient way to produce a new record if you only need to change the value. Copies the attributes of this record with the value replaced.- Type Parameters:
NewV
- The type of the new record's value.- Parameters:
value
- The value of the result record.- Returns:
- A new Record instance with all the same attributes (except that the value is replaced).
-
withTimestamp
public Record<K,V> withTimestamp(long timestamp)
A convenient way to produce a new record if you only need to change the timestamp. Copies the attributes of this record with the timestamp replaced.- Parameters:
timestamp
- The timestamp of the result record.- Returns:
- A new Record instance with all the same attributes (except that the timestamp is replaced).
-
withHeaders
public Record<K,V> withHeaders(Headers headers)
A convenient way to produce a new record if you only need to change the headers. Copies the attributes of this record with the headers replaced. Also makes a copy of the provided headers. SeeProcessorContext.forward(Record)
for considerations around mutability of keys, values, and headers.- Parameters:
headers
- The headers of the result record.- Returns:
- A new Record instance with all the same attributes (except that the headers are replaced).
-
-