Spring Boot for VMware GemFire
Package org.springframework.geode.cache
Class RepositoryAsyncEventListener<T,ID>
java.lang.Object
org.springframework.geode.cache.RepositoryAsyncEventListener<T,ID>
- All Implemented Interfaces:
org.apache.geode.cache.asyncqueue.AsyncEventListener,org.apache.geode.cache.CacheCallback,org.apache.geode.cache.Declarable
public class RepositoryAsyncEventListener<T,ID>
extends Object
implements org.apache.geode.cache.asyncqueue.AsyncEventListener
An Apache Geode
AsyncEventListener that uses a Spring Data CrudRepository to perform
data access operations to a backend, external data source asynchronously, triggered by cache operations.- Since:
- 1.4.0
- See Also:
-
FunctionOperationAsyncEventAsyncEventListenerCrudRepository
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepositoryAsyncEventListener.AbstractAsyncEventOperationRepositoryFunctionis an abstract base class implementing theRepositoryAsyncEventListener.AsyncEventOperationRepositoryFunctioninterface to provided a default template implementation of theFunction.apply(Object)method.static classRepositoryAsyncEventListener.AsyncEventErroris a wrapper class encapsulating theAsyncEventalong with theerrorthat was thrown while processing the event.static interfaceTheRepositoryAsyncEventListener.AsyncEventErrorHandlerinterface is aFunctionandFunctionalInterfaceused to handle errors while processingAsyncEvents.static interfaceTheRepositoryAsyncEventListener.AsyncEventOperationRepositoryFunctioninterface is aFunctionandFunctionalInterfacethat translates theAsyncEventOperationinto a Spring DataCrudRepositorymethod invocation.static classAnRepositoryAsyncEventListener.AsyncEventOperationRepositoryFunctioncapable of handlingOperation.CREATEandOperation.UPDATEAsyncEvents.static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final RepositoryAsyncEventListener.AsyncEventErrorHandler -
Constructor Summary
ConstructorsConstructorDescriptionRepositoryAsyncEventListener(org.springframework.data.repository.CrudRepository<T, ID> repository) Constructs a new instance ofRepositoryAsyncEventListenerinitialized with the given Spring DataCrudRepository. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleandoProcessEvents(List<org.apache.geode.cache.asyncqueue.AsyncEvent> events) Gets the configuredRepositoryAsyncEventListener.AsyncEventErrorHandlerused to handle errors that may occur when this listener is invoked with a batch ofAsyncEvents.longDetermines how many times this listener has been fired (triggered) by the GemFire/Geode AEQ system.Gets a reference to the configured Spring DataCrudRepositoryused by thisAsyncEventListenerto perform data access operations to a external, backend data source asynchronously when triggered by a cache operation.Gets aListofRepositoryAsyncEventListener.AsyncEventOperationRepositoryFunctionobjects used to processAsyncEventspassed to this listener by inspecting theOperationon theAsyncEventand calling the appropriateCrudRepositorymethod.booleanhasFired()Determines whether this listener has (ever) been fired (triggered) by the GemFire/Geode AEQ system.booleanDetermines whether this listener has been fired (triggered) by the GemFire/Geode AEQ system since the last check.final booleanprocessEvents(List<org.apache.geode.cache.asyncqueue.AsyncEvent> events) Processes eachAsyncEventin order by first determining whether theAsyncEventcan be processed by this listener and then invokes the appropriate Spring DataCrudRepositorydata access operation corresponding to theAsyncEventOperation.booleanregister(RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction<T, ID> repositoryFunction) Registers aRepositoryAsyncEventListener.AsyncEventOperationRepositoryFunctioncapable of processingAsyncEventsbyOperationand invoking the appropriate Spring DataCrudRepositorydata access operation.voidsetAsyncEventErrorHandler(RepositoryAsyncEventListener.AsyncEventErrorHandler asyncEventErrorHandler) Configures anRepositoryAsyncEventListener.AsyncEventErrorHandlerto handle errors that may occur when this listener is invoked with a batch ofAsyncEvents.booleanunregister(RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction<T, ID> repositoryFunction) Unregisters the givenRepositoryAsyncEventListener.AsyncEventOperationRepositoryFunctionfrom this listener.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.geode.cache.CacheCallback
closeMethods inherited from interface org.apache.geode.cache.Declarable
init, initialize
-
Field Details
-
DEFAULT_ASYNC_EVENT_ERROR_HANDLER
protected static final RepositoryAsyncEventListener.AsyncEventErrorHandler DEFAULT_ASYNC_EVENT_ERROR_HANDLER
-
-
Constructor Details
-
RepositoryAsyncEventListener
public RepositoryAsyncEventListener(@NonNull org.springframework.data.repository.CrudRepository<T, ID> repository) Constructs a new instance ofRepositoryAsyncEventListenerinitialized with the given Spring DataCrudRepository.- Parameters:
repository- Spring DataCrudRepositoryused to perform data access operations to a backend, external data source when triggered by a cache operation; must not be null.- Throws:
IllegalArgumentException- ifCrudRepositoryis null.- See Also:
-
CrudRepository
-
-
Method Details
-
hasFired
public boolean hasFired()Determines whether this listener has (ever) been fired (triggered) by the GemFire/Geode AEQ system.- Returns:
- a boolean value indicating whether this listener has been fired (triggered).
- See Also:
-
hasFiredSinceLastCheck
public boolean hasFiredSinceLastCheck()Determines whether this listener has been fired (triggered) by the GemFire/Geode AEQ system since the last check. A call to this method clears the flag.- Returns:
- a boolean value indicating whether this listener has been fired (triggered) since the last check.
- See Also:
-
getFiredCount
public long getFiredCount()Determines how many times this listener has been fired (triggered) by the GemFire/Geode AEQ system.- Returns:
- a
Longvalue indicating how many times this listener has been fired (triggered).
-
setAsyncEventErrorHandler
public void setAsyncEventErrorHandler(@Nullable RepositoryAsyncEventListener.AsyncEventErrorHandler asyncEventErrorHandler) Configures anRepositoryAsyncEventListener.AsyncEventErrorHandlerto handle errors that may occur when this listener is invoked with a batch ofAsyncEvents. Since the processing ofAsyncEventsis asynchronous, theRepositoryAsyncEventListener.AsyncEventErrorHandlergives users the opportunity to respond to errors for eachAsyncEventas it is is processed given this listener is designed to coordinate data/state changes occurring in an Apache Geode cache with an external data source.- Parameters:
asyncEventErrorHandler-RepositoryAsyncEventListener.AsyncEventErrorHandlerused to handle errors while processing the batch ofAsyncEvents.- See Also:
-
getAsyncEventErrorHandler
Gets the configuredRepositoryAsyncEventListener.AsyncEventErrorHandlerused to handle errors that may occur when this listener is invoked with a batch ofAsyncEvents. Defaults to anRepositoryAsyncEventListener.AsyncEventErrorHandlerthat always returns false on any error.- Returns:
- the configured
RepositoryAsyncEventListener.AsyncEventErrorHandler; never null. - See Also:
-
getRepository
Gets a reference to the configured Spring DataCrudRepositoryused by thisAsyncEventListenerto perform data access operations to a external, backend data source asynchronously when triggered by a cache operation.- Returns:
- a reference to the configured Spring Data
CrudRepository; never null. - See Also:
-
CrudRepository
-
getRepositoryFunctions
@NonNull protected List<RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction<T,ID>> getRepositoryFunctions()Gets aListofRepositoryAsyncEventListener.AsyncEventOperationRepositoryFunctionobjects used to processAsyncEventspassed to this listener by inspecting theOperationon theAsyncEventand calling the appropriateCrudRepositorymethod.- Returns:
- a
ListofRepositoryAsyncEventListener.AsyncEventOperationRepositoryFunctionobjects to process theAsyncEvents; never null. - See Also:
-
processEvents
Processes eachAsyncEventin order by first determining whether theAsyncEventcan be processed by this listener and then invokes the appropriate Spring DataCrudRepositorydata access operation corresponding to theAsyncEventOperation.- Specified by:
processEventsin interfaceorg.apache.geode.cache.asyncqueue.AsyncEventListener- Parameters:
events-ListofAsyncEventsto process.- Returns:
- a boolean value indicating whether all
AsyncEventswere processed successfully by this listener. If anyAsyncEventfails to be processed (just one), then this method will return false. If anyAsyncEventcannot be handled, then this method will return false, even if otherAsyncEventswere successfully processed. - See Also:
-
doProcessEvents
- See Also:
-
register
public boolean register(@NonNull RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction<T, ID> repositoryFunction) Registers aRepositoryAsyncEventListener.AsyncEventOperationRepositoryFunctioncapable of processingAsyncEventsbyOperationand invoking the appropriate Spring DataCrudRepositorydata access operation.AsyncEventOperationRepositoryFunctionscan be registered forAsyncEventOperationsnot currently handled by this listener. Alternatively, users can override existingAsyncEventOperationRepositoryFunctionsprovided by this listener to alter the default behavior, or effectively the Spring DataCrudRepositorydata access operation invoked based on theAsyncEventOperation. TherepositoryFunctionarguments are prepended to theListof registeredFunctionsto implement the override, where the firstFunctionfound capable of handling theAsyncEventOperationwill be applied.- Parameters:
repositoryFunction-RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunctionused to processAsyncEventsbyOperationinvoking the appropriate Spring DataCrudRepositorydata access operation; must not be null.- Returns:
- a boolean value indicating whether the registration was successful.
- See Also:
-
unregister
public boolean unregister(@Nullable RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction<T, ID> repositoryFunction) Unregisters the givenRepositoryAsyncEventListener.AsyncEventOperationRepositoryFunctionfrom this listener.- Parameters:
repositoryFunction-RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunctionto unregister.- Returns:
- a boolean value indicating whether the un-registration was successful.
- See Also:
-