Package org.springframework.geode.cache
Class RepositoryAsyncEventListener.AbstractAsyncEventOperationRepositoryFunction<T,ID>
java.lang.Object
org.springframework.geode.cache.RepositoryAsyncEventListener.AbstractAsyncEventOperationRepositoryFunction<T,ID>
- Type Parameters:
T
-type
of the entity tied to the event.ID
-type
of the identifier of the entity.
- All Implemented Interfaces:
Function<org.apache.geode.cache.asyncqueue.AsyncEvent<ID,
,T>, Boolean> RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction<T,
ID>
- Direct Known Subclasses:
RepositoryAsyncEventListener.CreateUpdateAsyncEventRepositoryFunction
,RepositoryAsyncEventListener.RemoveAsyncEventRepositoryFunction
- Enclosing class:
- RepositoryAsyncEventListener<T,
ID>
public abstract static class RepositoryAsyncEventListener.AbstractAsyncEventOperationRepositoryFunction<T,ID>
extends Object
implements RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction<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.-
Constructor Summary
ConstructorDescriptionConstructs an new instance ofRepositoryAsyncEventListener.AbstractAsyncEventOperationRepositoryFunction
initialized with the given, requiredRepositoryAsyncEventListener
to which this function is associated. -
Method Summary
Modifier and TypeMethodDescriptionProcesses the givenAsyncEvent
by first determining whether the event can be processed by thisFunction
, and then proceeds to extract theentity
associated with the event to invoke the appropriate Spring DataCrudRepository
data access operation determined by theAsyncEvent
Operation
.protected abstract <R> R
doRepositoryOp
(T entity) Invokes the appropriate Spring DataCrudRepository
data access operation based on theAsyncEvent
Operation
as determined byGatewayQueueEvent.getOperation()
.protected RepositoryAsyncEventListener<T,
ID> Returns a reference to the associatedRepositoryAsyncEventListener
.protected T
resolveEntity
(org.apache.geode.cache.asyncqueue.AsyncEvent<ID, T> event) Resolves theentity
associated with theAsyncEvent
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.geode.cache.RepositoryAsyncEventListener.AsyncEventOperationRepositoryFunction
canProcess
-
Constructor Details
-
AbstractAsyncEventOperationRepositoryFunction
public AbstractAsyncEventOperationRepositoryFunction(@NonNull RepositoryAsyncEventListener<T, ID> listener) Constructs an new instance ofRepositoryAsyncEventListener.AbstractAsyncEventOperationRepositoryFunction
initialized with the given, requiredRepositoryAsyncEventListener
to which this function is associated.- Parameters:
listener
-RepositoryAsyncEventListener
processingAsyncEvents
by invoking thisFunction
to handle them.- Throws:
IllegalArgumentException
- ifRepositoryAsyncEventListener
is null.- See Also:
-
-
Method Details
-
getErrorHandler
Alias to theconfigured
RepositoryAsyncEventListener
RepositoryAsyncEventListener.AsyncEventErrorHandler
.- Returns:
- the configured
RepositoryAsyncEventListener.AsyncEventErrorHandler
; never null. - See Also:
-
getListener
Returns a reference to the associatedRepositoryAsyncEventListener
.- Returns:
- a reference to the associated
RepositoryAsyncEventListener
; never null. - See Also:
-
getRepository
- Returns:
- the configured
CrudRepository
; never null. - See Also:
-
CrudRepository
RepositoryAsyncEventListener.getRepository()
getListener()
-
apply
Processes the givenAsyncEvent
by first determining whether the event can be processed by thisFunction
, and then proceeds to extract theentity
associated with the event to invoke the appropriate Spring DataCrudRepository
data access operation determined by theAsyncEvent
Operation
. If anerror
is thrown while processing theAsyncEvent
, then theRepositoryAsyncEventListener.AsyncEventErrorHandler
is called to handle the error and perform any necessary/required post-processing actions.RepositoryAsyncEventListener.AsyncEventErrorHandler
can be implemented to retry the operation with incremental backoff, based on count or time, record the failure, perform resource cleanup actions, whatever is necessary and appropriate to the application use case.- Specified by:
apply
in interfaceFunction<T,
ID> - Parameters:
event
-AsyncEvent
to process.- Returns:
- a boolean value indicating whether the event was successfully processed.
- Throws:
IllegalStateException
- if the resolve entity is null.- See Also:
-
doRepositoryOp
Invokes the appropriate Spring DataCrudRepository
data access operation based on theAsyncEvent
Operation
as determined byGatewayQueueEvent.getOperation()
.- Type Parameters:
R
-type
of the Spring DataCrudRepository
data access operation return value.- Parameters:
entity
- entity to process.- Returns:
- the result of invoking the Spring Data
CrudRepository
data access operation. - See Also:
-
CrudRepository
-
resolveEntity
Resolves theentity
associated with theAsyncEvent
.- Parameters:
event
-AsyncEvent
from which to resolve the entity.- Returns:
- the resolve entity from the
AsyncEvent
. - Throws:
IllegalArgumentException
- ifAsyncEvent
is null.IllegalStateException
- if the resolvedentity
is null.- See Also:
-
GatewayQueueEvent.getDeserializedValue()
AsyncEvent
-