public class RepositoryAsyncEventListener<T,ID>
extends java.lang.Object
implements org.apache.geode.cache.asyncqueue.AsyncEventListener
AsyncEventListener that uses a Spring Data CrudRepository to perform
data access operations to a backend, external data source asynchronously, triggered by cache operations.Function,
Operation,
AsyncEvent,
AsyncEventListener,
CrudRepository| Modifier and Type | Class and Description |
|---|---|
static class |
RepositoryAsyncEventListener.AbstractAsyncEventOperationRepositoryFunction<T,ID>
RepositoryAsyncEventListener.AbstractAsyncEventOperationRepositoryFunction is an abstract base class implementing the
RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction interface to provided a default template implementation
of the Function.apply(Object) method. |
static class |
RepositoryAsyncEventListener.AsyncEventError
RepositoryAsyncEventListener.AsyncEventError is a wrapper class encapsulating the AsyncEvent along with
the error that was thrown while processing the event. |
static interface |
RepositoryAsyncEventListener.AsyncEventErrorHandler
The
RepositoryAsyncEventListener.AsyncEventErrorHandler interface is a Function and FunctionalInterface used to
handle errors while processing AsyncEvents. |
static interface |
RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction<T,ID>
The
RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction interface is a Function and FunctionalInterface
that translates the AsyncEvent Operation into a Spring Data CrudRepository method
invocation. |
static class |
RepositoryAsyncEventListener.CreateUpdateAsyncEventRepositoryFunction<T,ID>
An
RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction capable of handling Operation.CREATE
and Operation.UPDATE AsyncEvents. |
static class |
RepositoryAsyncEventListener.RemoveAsyncEventRepositoryFunction<T,ID>
An
Function implementation capable of handling Operation.REMOVE AsyncEvents. |
| Modifier and Type | Field and Description |
|---|---|
protected static RepositoryAsyncEventListener.AsyncEventErrorHandler |
DEFAULT_ASYNC_EVENT_ERROR_HANDLER |
| Constructor and Description |
|---|
RepositoryAsyncEventListener(org.springframework.data.repository.CrudRepository<T,ID> repository)
Constructs a new instance of
RepositoryAsyncEventListener initialized with the given Spring Data
CrudRepository. |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
doProcessEvents(java.util.List<org.apache.geode.cache.asyncqueue.AsyncEvent> events) |
protected RepositoryAsyncEventListener.AsyncEventErrorHandler |
getAsyncEventErrorHandler()
Gets the configured
RepositoryAsyncEventListener.AsyncEventErrorHandler used to handle errors that may occur when this listener
is invoked with a batch of AsyncEvents. |
long |
getFiredCount()
Determines how many times this listener has been fired (triggered) by the GemFire/Geode AEQ system.
|
protected org.springframework.data.repository.CrudRepository<T,ID> |
getRepository()
Gets a reference to the configured Spring Data
CrudRepository used by this AsyncEventListener
to perform data access operations to a external, backend data source asynchronously when triggered by a cache
operation. |
protected java.util.List<RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction<T,ID>> |
getRepositoryFunctions()
Gets a
List of RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction objects used to process
AsyncEvents passed to this listener by inspecting the Operation
on the AsyncEvent and calling the appropriate CrudRepository method. |
boolean |
hasFired()
Determines whether this listener has (ever) been fired (triggered) by the GemFire/Geode AEQ system.
|
boolean |
hasFiredSinceLastCheck()
Determines whether this listener has been fired (triggered) by the GemFire/Geode AEQ system
since the last check.
|
boolean |
processEvents(java.util.List<org.apache.geode.cache.asyncqueue.AsyncEvent> events)
Processes each
AsyncEvent in order by first determining whether the AsyncEvent can be processed
by this listener and then invokes the appropriate Spring Data CrudRepository data access operation
corresponding to the AsyncEvent Operation. |
boolean |
register(RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction<T,ID> repositoryFunction)
Registers a
RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction capable of processing AsyncEvents
by Operation and invoking the appropriate Spring Data CrudRepository data access operation. |
void |
setAsyncEventErrorHandler(RepositoryAsyncEventListener.AsyncEventErrorHandler asyncEventErrorHandler)
Configures an
RepositoryAsyncEventListener.AsyncEventErrorHandler to handle errors that may occur when this listener is invoked with
a batch of AsyncEvents. |
boolean |
unregister(RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction<T,ID> repositoryFunction)
Unregisters the given
RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction from this listener. |
protected static final RepositoryAsyncEventListener.AsyncEventErrorHandler DEFAULT_ASYNC_EVENT_ERROR_HANDLER
public RepositoryAsyncEventListener(@NonNull
org.springframework.data.repository.CrudRepository<T,ID> repository)
RepositoryAsyncEventListener initialized with the given Spring Data
CrudRepository.repository - Spring Data CrudRepository used to perform data access operations to a backend,
external data source when triggered by a cache operation; must not be null.java.lang.IllegalArgumentException - if CrudRepository is null.CrudRepositorypublic boolean hasFired()
hasFiredSinceLastCheck()public boolean hasFiredSinceLastCheck()
hasFired()public long getFiredCount()
Long value indicating how many times this listener has been fired (triggered).public void setAsyncEventErrorHandler(@Nullable
RepositoryAsyncEventListener.AsyncEventErrorHandler asyncEventErrorHandler)
RepositoryAsyncEventListener.AsyncEventErrorHandler to handle errors that may occur when this listener is invoked with
a batch of AsyncEvents.
Since the processing of AsyncEvents is asynchronous, the RepositoryAsyncEventListener.AsyncEventErrorHandler gives
users the opportunity to respond to errors for each AsyncEvent as 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.asyncEventErrorHandler - RepositoryAsyncEventListener.AsyncEventErrorHandler used to handle errors while processing the batch of
AsyncEvents.RepositoryAsyncEventListener.AsyncEventErrorHandler@NonNull protected RepositoryAsyncEventListener.AsyncEventErrorHandler getAsyncEventErrorHandler()
RepositoryAsyncEventListener.AsyncEventErrorHandler used to handle errors that may occur when this listener
is invoked with a batch of AsyncEvents.
Defaults to an RepositoryAsyncEventListener.AsyncEventErrorHandler that always returns false on any error.RepositoryAsyncEventListener.AsyncEventErrorHandler; never null.RepositoryAsyncEventListener.AsyncEventErrorHandler@NonNull protected org.springframework.data.repository.CrudRepository<T,ID> getRepository()
CrudRepository used by this AsyncEventListener
to perform data access operations to a external, backend data source asynchronously when triggered by a cache
operation.CrudRepository; never null.CrudRepository@NonNull protected java.util.List<RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction<T,ID>> getRepositoryFunctions()
List of RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction objects used to process
AsyncEvents passed to this listener by inspecting the Operation
on the AsyncEvent and calling the appropriate CrudRepository method.List of RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction objects to process
the AsyncEvents; never null.RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunctionpublic final boolean processEvents(java.util.List<org.apache.geode.cache.asyncqueue.AsyncEvent> events)
AsyncEvent in order by first determining whether the AsyncEvent can be processed
by this listener and then invokes the appropriate Spring Data CrudRepository data access operation
corresponding to the AsyncEvent Operation.processEvents in interface org.apache.geode.cache.asyncqueue.AsyncEventListenerevents - List of AsyncEvents to process.AsyncEvents were processed successfully
by this listener.
If any AsyncEvent fails to be processed (just one), then this method will return false.
If any AsyncEvent cannot be handled, then this method will return false, even if other
AsyncEvents were successfully processed.AsyncEvent,
RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction,
getRepositoryFunctions(),
Listprotected boolean doProcessEvents(java.util.List<org.apache.geode.cache.asyncqueue.AsyncEvent> events)
processEvents(List)public boolean register(@NonNull
RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction<T,ID> repositoryFunction)
RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction capable of processing AsyncEvents
by Operation and invoking the appropriate Spring Data CrudRepository data access operation.
AsyncEventOperationRepositoryFunctions can be registered for
AsyncEvent Operations not currently handled by this listener. Alternatively, users can
override existing AsyncEventOperationRepositoryFunctions provided
by this listener to alter the default behavior, or effectively the Spring Data CrudRepository data access
operation invoked based on the AsyncEvent Operation. The repositoryFunction arguments are
prepended to the List of registered Functions to implement the override, where the first
Function found capable of handling the AsyncEvent Operation will be applied.repositoryFunction - RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction used to process
AsyncEvents by Operation invoking the appropriate Spring Data CrudRepository
data access operation; must not be null.RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction,
getRepositoryFunctions()public boolean unregister(@Nullable
RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction<T,ID> repositoryFunction)
RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction from this listener.repositoryFunction - RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction to unregister.RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction,
getRepositoryFunctions()