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
public abstract class AbstractListenerImpl<T,L extends ListenerInvocation<T>> extends Object
Functionality common to bothCacheManagerNotifierImpl
andCacheNotifierImpl
- Author:
- Manik Surtani, William Burns
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AbstractListenerImpl.AbstractInvocationBuilder
protected class
AbstractListenerImpl.ListenerInvocationImpl<A>
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
Fields Modifier and Type Field Description protected ExecutorService
asyncProcessor
protected Map<Class<? extends Annotation>,List<L>>
listenersMap
protected ExecutorService
syncProcessor
-
Constructor Summary
Constructors Constructor Description AbstractListenerImpl()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
canApply(Set<Class<? extends Annotation>> filterAnnotations, Class<? extends Annotation> annotationClass)
protected Set<Class<? extends Annotation>>
findListenerCallbacks(Object listener)
protected abstract Map<Class<? extends Annotation>,Class<?>>
getAllowedMethodAnnotations(Listener l)
protected List<L>
getListenerCollectionForAnnotation(Class<? extends Annotation> annotation)
Set<Object>
getListeners()
protected abstract Log
getLog()
void
removeListener(Object listener)
protected Set<L>
removeListenerInvocation(Class<? extends Annotation> annotation, Object listener)
protected abstract void
resumeIfNeeded(Transaction transaction)
void
start()
void
stop()
Removes all listeners from the notifierprotected abstract Transaction
suspendIfNeeded()
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)
protected boolean
validateAndAddFilterListenerInvocations(Object listener, AbstractListenerImpl.AbstractInvocationBuilder builder, Set<Class<? extends Annotation>> filterAnnotations)
protected boolean
validateAndAddListenerInvocations(Object listener, AbstractListenerImpl.AbstractInvocationBuilder builder)
Loops through all valid methods on the object passed in, and caches the relevant methods asListenerInvocation
for invocation by reflection.
-
-
-
Field Detail
-
listenersMap
protected final Map<Class<? extends Annotation>,List<L extends ListenerInvocation<T>>> listenersMap
-
syncProcessor
protected ExecutorService syncProcessor
-
asyncProcessor
protected ExecutorService asyncProcessor
-
-
Method Detail
-
start
public void start()
-
stop
public void stop()
Removes all listeners from the notifier
-
getLog
protected abstract Log getLog()
-
getAllowedMethodAnnotations
protected abstract Map<Class<? extends Annotation>,Class<?>> getAllowedMethodAnnotations(Listener l)
-
getListenerCollectionForAnnotation
protected List<L> getListenerCollectionForAnnotation(Class<? extends Annotation> annotation)
-
removeListener
public void removeListener(Object listener)
-
removeListenerInvocation
protected Set<L> removeListenerInvocation(Class<? extends Annotation> annotation, Object listener)
-
validateAndAddListenerInvocations
protected boolean validateAndAddListenerInvocations(Object listener, AbstractListenerImpl.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.AbstractInvocationBuilder builder, Set<Class<? extends Annotation>> filterAnnotations)
-
canApply
public boolean canApply(Set<Class<? extends Annotation>> filterAnnotations, Class<? extends Annotation> annotationClass)
-
findListenerCallbacks
protected Set<Class<? extends Annotation>> findListenerCallbacks(Object listener)
-
testListenerClassValidity
protected static Listener testListenerClassValidity(Class<?> listenerClass)
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)
-
suspendIfNeeded
protected abstract Transaction suspendIfNeeded()
-
resumeIfNeeded
protected abstract void resumeIfNeeded(Transaction transaction)
-
-