Interface PersistenceHandler
public interface PersistenceHandler
PersistenceHandlers are responsible for listening for
PersistenceConsumer
channel events
associated with a specific repository domain type. These events are emitted in response to
persistence state change for entities and are delivered in the form of a JSON representation of
the latest state of the entity.
Generally, concrete implementations take a form similar to this.
public class TestPersistenceHandler implements PersistenceHandler
{@Override
public void processStateChange(String entityJson)
{ //do something interesting in reaction to the state change } }
Implementations of this interface assumes that you have @EnableBinding(Persistence.class)
in an @Configuration
class within your application that activates the channel bindings
that the handle(String)
method relies on.
- Author:
- Jeff Fischer
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptioncom.fasterxml.jackson.databind.ObjectMapper
Return theObjectMapper
to use when handling the message json.String[]
The simple entity type names supported by this service.default void
Entry point for the handler.void
Hook point for message listeners to bind to the input channel with@StreamListener
.default boolean
isValidType
(String reportedType, String projectionType) Determine if the type (i.e.void
processStateChange
(com.fasterxml.jackson.databind.JsonNode entityJson) Handle the entityJson representation of the change that has been deemed appropriate for this handler based on comparing the expected_class
parameter in the JSON against the generic type of the handler implementation.default void
validate
(com.fasterxml.jackson.databind.JsonNode entityJson) Verify the signed JWT token and validate the user claims (especially authorities) against the consumption functionality.
-
Field Details
-
log
static final org.slf4j.Logger log
-
-
Method Details
-
hook
Hook point for message listeners to bind to the input channel with@StreamListener
. Implementations of this method generally delegate tohandle(String)
. It is generally important that each input channel name is unique in order to guarantee other listeners will still process the persistence message, even if one or more other listeners throw exceptions. As a corollary, there will also generally be a unique@Input
annotatedSubscribableChannel
instance per listener tied to the unique input channel.- Parameters:
entityJson
- The JSON representation of the changed entity state coming in from the input channel
-
handle
Entry point for the handler. This method will review the entity json representation and evaluate suitability against thegetSupportedSimpleTypeNames()
types. If appropriate,processStateChange(JsonNode)
is called.- Parameters:
entityJson
- The JSON representation of the changed entity state
-
isValidType
Determine if the type (i.e. simple class name of the entity) of the incoming entity persistence message is appropriate for this handler.- Parameters:
reportedType
- The type of the incoming entity persistence messageprojectionType
- Optional. The projected domain type, if applicable. This is generally derived from entity types that advertise their projection type during JSON serialization.- Returns:
- Whether or not the type is supported
-
getObjectMapper
com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()Return theObjectMapper
to use when handling the message json. Typically, this would utilize an autowired bean instance.- Returns:
- the
ObjectMapper
to use when handling the message json
-
processStateChange
void processStateChange(com.fasterxml.jackson.databind.JsonNode entityJson) Handle the entityJson representation of the change that has been deemed appropriate for this handler based on comparing the expected_class
parameter in the JSON against the generic type of the handler implementation.- Parameters:
entityJson
- The JSON representing the last known state of the entity
-
getSupportedSimpleTypeNames
String[] getSupportedSimpleTypeNames()The simple entity type names supported by this service. This is not the fully qualified classname, rather the simple name - similar to what is returned byClass.getSimpleName()
.- Returns:
- The array of simple type names supported by this handler
-
validate
default void validate(com.fasterxml.jackson.databind.JsonNode entityJson) Verify the signed JWT token and validate the user claims (especially authorities) against the consumption functionality. Generally, throw anIllegalArgumentException
if the claims made in the JWT are deemed incorrect or inappropriate for the desired task.- Parameters:
entityJson
- Message instance capable of supplying a signed JWT token
-