Interface PersistenceHandler
-
public interface PersistenceHandlerPersistenceHandlers are responsible for listening forPersistenceConsumerchannel 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{@Overridepublic 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@Configurationclass within your application that activates the channel bindings that thehandle(String)method relies on.- Author:
- Jeff Fischer
-
-
Field Summary
Fields Modifier and Type Field Description static org.slf4j.Loggerlog
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description com.fasterxml.jackson.databind.ObjectMappergetObjectMapper()Return theObjectMapperto use when handling the message json.String[]getSupportedSimpleTypeNames()The simple entity type names supported by this service.default voidhandle(String entityJson)Entry point for the handler.voidhook(String entityJson)Hook point for message listeners to bind to the input channel with@StreamListener.default booleanisValidType(String reportedType, String projectionType)Determine if the type (i.e.voidprocessStateChange(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_classparameter in the JSON against the generic type of the handler implementation.default voidvalidate(com.fasterxml.jackson.databind.JsonNode entityJson)Verify the signed JWT token and validate the user claims (especially authorities) against the consumption functionality.
-
-
-
Method Detail
-
hook
void hook(String entityJson)
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@InputannotatedSubscribableChannelinstance 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
default void handle(String entityJson)
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
default boolean isValidType(String reportedType, @Nullable String projectionType)
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 theObjectMapperto use when handling the message json. Typically, this would utilize an autowired bean instance.- Returns:
- the
ObjectMapperto 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_classparameter 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 anIllegalArgumentExceptionif 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
-
-