Interface TableViewMessageMapper<T,V>
- Type Parameters:
T- the message schema typeV- the type of the values stored in the table view
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
TableView created with
TableViewBuilder.createMapped(TableViewMessageMapper) or
TableViewBuilder.createMappedAsync(TableViewMessageMapper).
The interface is functional: createMapped(msg -> msg.getProperty("region")) maps each message
to a value, and createMapped(msg -> msg) builds a TableView<Message<T>> that exposes the
complete messages. Implement the interface as a class to customize onMappingError(Message, Throwable).
The table view invokes both methods on the client's internal thread, one message at a time in the order
the messages are read. They must not block. Message pooling is disabled for mapped table views, so the
Message passed to the mapper may be retained by the value.
Later versions may add further callbacks as default methods that do nothing unless overridden.
-
Method Summary
Modifier and TypeMethodDescriptionMaps a message to the value stored in the table view for the message key.default booleanonMappingError(Message<T> message, Throwable error) Called whenmap(Message)throws for a message.
-
Method Details
-
map
Maps a message to the value stored in the table view for the message key.The mapper is only called for keyed messages with a non-empty payload. A keyed message with an empty payload is a tombstone: the key is removed from the view without calling the mapper, so a mapper that derives the value from the key or the properties alone never sees such a message. Returning
nullhas the same effect as a tombstone.If the mapper throws, the message is skipped: the key keeps its previous value in the view (or stays absent), listeners are not notified, and
onMappingError(Message, Throwable)is called.- Parameters:
message- the message to map, never a tombstone- Returns:
- the value to store for the message key, or
nullto remove the key - Throws:
Exception- if the message cannot be mapped, in which case the message is skipped
-
onMappingError
Called whenmap(Message)throws for a message. The message has already been skipped and the view is unchanged for its key; this callback cannot alter that outcome. It exists to report the failure the way the application needs, for instance to record a metric or to signal another thread that the view can no longer be trusted. An implementation must not block and must not close the table view from this thread.The default implementation returns
false, which makes the table view log the failure atERRORlevel together with the topic, key and message id. Returntrueto indicate that the failure has been handled and must not be logged. Exceptions thrown by this method are logged and ignored.- Parameters:
message- the message that could not be mappederror- the exception thrown bymap(Message)- Returns:
trueif the failure has been handled,falseto let the table view log it
-