Class AbstractListenerImpl<T,L extends ListenerInvocation<T>>
java.lang.Object
org.infinispan.notifications.impl.AbstractListenerImpl<T,L>
- Type Parameters:
T
- Defines the type of event that will be used by the subclassL
- Defines the type of ListenerInvocations that the subclasses use
- Direct Known Subclasses:
CacheManagerNotifierImpl
,CacheNotifierImpl
Functionality common to both
CacheManagerNotifierImpl
and
CacheNotifierImpl
- Author:
- Manik Surtani, William Burns
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
protected class
Class that encapsulates a valid invocation for a given registered listener - containing a reference to the method to be invoked as well as the target object. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
canApply
(Set<Class<? extends Annotation>> filterAnnotations, Class<? extends Annotation> annotationClass) protected static AggregateCompletionStage
<Void> composeStageIfNeeded
(AggregateCompletionStage<Void> aggregateCompletionStage, CompletionStage<Void> stage) If the given stage is null or normally completed returns the provided aggregateCompletionStage as is.protected Set
<Class<? extends Annotation>> findListenerCallbacks
(Object listener) protected abstract Map
<Class<? extends Annotation>, Class<?>> getListenerCollectionForAnnotation
(Class<? extends Annotation> annotation) protected abstract org.infinispan.util.logging.Log
getLog()
protected void
boolean
hasListener
(Class<? extends Annotation> annotationClass) boolean
protected CompletionStage
<Void> invokeListeners
(T event, Collection<L> listeners) abstract CompletionStage
<Void> removeListenerAsync
(Object listener) protected void
removeListenerFromMaps
(Object listener) removeListenerInvocation
(Class<? extends Annotation> annotation, Object listener) protected abstract void
resumeIfNeeded
(jakarta.transaction.Transaction transaction) protected CompletionStage
<Void> resumeOnCPU
(CompletionStage<Void> stage, Object traceId) void
stop()
Removes all listeners from the notifierprotected abstract jakarta.transaction.Transaction
protected static Listener
testListenerClassValidity
(Class<?> listenerClass) Tests if a class is properly annotated as a CacheListener and returns the Listener annotation.protected static void
testListenerMethodValidity
(Method m, Class<?> allowedParameter, String annotationName) Tests that a method is a valid listener method, that is that it has a single argument that is assignable to allowedParameter.protected boolean
validateAndAddFilterListenerInvocations
(Object listener, AbstractListenerImpl<T, L>.AbstractInvocationBuilder builder, Set<Class<? extends Annotation>> filterAnnotations) protected boolean
validateAndAddListenerInvocations
(Object listener, AbstractListenerImpl<T, L>.AbstractInvocationBuilder builder) Loops through all valid methods on the object passed in, and caches the relevant methods asListenerInvocation
for invocation by reflection.
-
Field Details
-
asyncProcessor
-
listenersMap
-
-
Constructor Details
-
AbstractListenerImpl
public AbstractListenerImpl()
-
-
Method Details
-
stop
public void stop()Removes all listeners from the notifier -
resumeOnCPU
-
getLog
protected abstract org.infinispan.util.logging.Log getLog() -
getAllowedMethodAnnotations
protected abstract Map<Class<? extends Annotation>,Class<?>> getAllowedMethodAnnotations(Listener l) -
hasListener
-
hasListeners
public boolean hasListeners() -
getListenerCollectionForAnnotation
-
removeListenerAsync
-
composeStageIfNeeded
protected static AggregateCompletionStage<Void> composeStageIfNeeded(AggregateCompletionStage<Void> aggregateCompletionStage, CompletionStage<Void> stage) If the given stage is null or normally completed returns the provided aggregateCompletionStage as is. Otherwise the stage is used as a dependant for the provided aggregateCompletionStage if provided or a new one is created that depends upon the provided stage. The existing or new aggregateCompletionStage is then returned to the caller.- Parameters:
aggregateCompletionStage
- the existing composed stage or nullstage
- the stage to rely upon- Returns:
- null or a composed stage that relies upon the provided stage
-
removeListenerFromMaps
-
removeListenerInvocation
-
getListeners
-
validateAndAddListenerInvocations
protected boolean validateAndAddListenerInvocations(Object listener, AbstractListenerImpl<T, L>.AbstractInvocationBuilder builder) Loops through all valid methods on the object passed in, and caches the relevant methods asListenerInvocation
for invocation by reflection. The builder provided will be used to create the listener invocations. This method will set the target, subject sync, and methods as needed. If other values are needed to be set they should be invoked before passing to this method.- Parameters:
listener
- object to be considered as a listener.builder
- The builder to use to build the invocation- Returns:
true
if annotated listener methods were found orfalse
otherwise
-
validateAndAddFilterListenerInvocations
protected boolean validateAndAddFilterListenerInvocations(Object listener, AbstractListenerImpl<T, L>.AbstractInvocationBuilder builder, Set<Class<? extends Annotation>> filterAnnotations) -
canApply
public boolean canApply(Set<Class<? extends Annotation>> filterAnnotations, Class<? extends Annotation> annotationClass) -
findListenerCallbacks
-
testListenerClassValidity
Tests if a class is properly annotated as a CacheListener and returns the Listener annotation.- Parameters:
listenerClass
- class to inspect- Returns:
- the Listener annotation
-
testListenerMethodValidity
protected static void testListenerMethodValidity(Method m, Class<?> allowedParameter, String annotationName) Tests that a method is a valid listener method, that is that it has a single argument that is assignable to allowedParameter. The method must also return either void or a CompletionStage, meaning the method promises not block.- Parameters:
m
- method to testallowedParameter
- what parameter is allowed for the method argumentannotationName
- name of the annotation- Throws:
IncorrectListenerException
- if the listener is not a valid target
-
invokeListeners
-
handleException
-
suspendIfNeeded
protected abstract jakarta.transaction.Transaction suspendIfNeeded() -
resumeIfNeeded
protected abstract void resumeIfNeeded(jakarta.transaction.Transaction transaction)
-