Class CacheNotifierImpl<K,V>
- java.lang.Object
-
- org.infinispan.notifications.impl.AbstractListenerImpl<Event<K,V>,CacheEntryListenerInvocation<K,V>>
-
- org.infinispan.notifications.cachelistener.CacheNotifierImpl<K,V>
-
- All Implemented Interfaces:
CacheNotifier<K,V>
,ClusterCacheNotifier<K,V>
,ClassLoaderAwareFilteringListenable<K,V>
,ClassLoaderAwareListenable
,DataConversionAwareListenable<K,V>
,FilteringListenable<K,V>
,Listenable
public final class CacheNotifierImpl<K,V> extends AbstractListenerImpl<Event<K,V>,CacheEntryListenerInvocation<K,V>> implements ClusterCacheNotifier<K,V>
Helper class that handles all notifications to registered listeners.- Since:
- 4.0
- Author:
- Manik Surtani (manik AT infinispan DOT org), Mircea.Markus@jboss.com, William Burns, anistor@redhat.com
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
CacheNotifierImpl.BaseCacheEntryListenerInvocation<K,V>
protected class
CacheNotifierImpl.CacheInvocationBuilder
protected static class
CacheNotifierImpl.ClusteredListenerInvocation<K,V>
This class is to be used with cluster listener invocations only when they have included current state.protected class
CacheNotifierImpl.DelegatingCacheInvocationBuilder
-
Nested classes/interfaces inherited from class org.infinispan.notifications.impl.AbstractListenerImpl
AbstractListenerImpl.AbstractInvocationBuilder, AbstractListenerImpl.ListenerInvocationImpl<A>
-
-
Field Summary
-
Fields inherited from class org.infinispan.notifications.impl.AbstractListenerImpl
asyncProcessor, listenersMap, syncProcessor
-
-
Constructor Summary
Constructors Constructor Description CacheNotifierImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <C> void
addFilteredListener(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, Set<Class<? extends Annotation>> filterAnnotations)
Registers a listener limiting the cache-entry specific events only to annotations that are passed in as parameter.<C> void
addFilteredListener(ListenerHolder listenerHolder, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, Set<Class<? extends Annotation>> filterAnnotations)
void
addListener(Object listener)
Adds a listener to the component.void
addListener(Object listener, ClassLoader classLoader)
Adds a listener along with a class loader to use for the invocationvoid
addListener(Object listener, KeyFilter<? super K> filter)
Adds a listener to the component.void
addListener(Object listener, KeyFilter<? super K> filter, ClassLoader classLoader)
Adds a listener to the component.<C> void
addListener(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter)
Registers a listener that will be notified on events that pass the filter condition.<C> void
addListener(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, ClassLoader classLoader)
Adds the listener using the provided filter converter and class loader.<C> void
addListener(ListenerHolder listenerHolder, KeyFilter<? super K> filter)
<C> void
addListener(ListenerHolder listenerHolder, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, ClassLoader classLoader)
<C> void
addStorageFormatFilteredListener(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, Set<Class<? extends Annotation>> filterAnnotations)
Same asFilteringListenable.addFilteredListener(Object, CacheEventFilter, CacheEventConverter, Set)
, but assumes the filter and/or the converter will be done in the same data format as it's stored in the cache.protected Map<Class<? extends Annotation>,Class<?>>
getAllowedMethodAnnotations(Listener l)
List<CacheEntryListenerInvocation<K,V>>
getListenerCollectionForAnnotation(Class<? extends Annotation> annotation)
protected Log
getLog()
boolean
isNotificationAllowed(FlagAffectedCommand cmd, List<CacheEntryListenerInvocation<K,V>> listeners)
void
notifyCacheEntriesEvicted(Collection<InternalCacheEntry<? extends K,? extends V>> entries, InvocationContext ctx, FlagAffectedCommand command)
Notifies all registered listeners of aCacheEntriesEvictedEvent
event.void
notifyCacheEntryActivated(K key, V value, boolean pre, InvocationContext ctx, FlagAffectedCommand command)
Notifies all registered listeners of aCacheEntryActivatedEvent
event.void
notifyCacheEntryCreated(K key, V value, Metadata metadata, boolean pre, InvocationContext ctx, FlagAffectedCommand command)
Notifies all registered listeners of aCacheEntryCreatedEvent
event.void
notifyCacheEntryExpired(K key, V value, Metadata metadata, InvocationContext ctx)
Notifies all registered listeners of a CacheEntryExpired event.void
notifyCacheEntryInvalidated(K key, V value, Metadata metadata, boolean pre, InvocationContext ctx, FlagAffectedCommand command)
Notifies all registered listeners of aCacheEntryInvalidatedEvent
event.void
notifyCacheEntryLoaded(K key, V value, boolean pre, InvocationContext ctx, FlagAffectedCommand command)
Notifies all registered listeners of aCacheEntryLoadedEvent
event.void
notifyCacheEntryModified(K key, V value, Metadata metadata, V previousValue, Metadata previousMetadata, boolean pre, InvocationContext ctx, FlagAffectedCommand command)
Notifies all registered listeners of aCacheEntryModifiedEvent
event.void
notifyCacheEntryPassivated(K key, V value, boolean pre, InvocationContext ctx, FlagAffectedCommand command)
Notifies all registered listeners of aCacheEntryPassivatedEvent
event.void
notifyCacheEntryRemoved(K key, V previousValue, Metadata previousMetadata, boolean pre, InvocationContext ctx, FlagAffectedCommand command)
Notifies all registered listeners of aCacheEntryRemovedEvent
event.void
notifyCacheEntryVisited(K key, V value, boolean pre, InvocationContext ctx, FlagAffectedCommand command)
Notifies all registered listeners of aCacheEntryVisitedEvent
event.void
notifyClusterListeners(Collection<? extends CacheEntryEvent<K,V>> events, UUID uuid)
Method that is invoked on the node that has the given cluster listener that when registered generated the given listenerId.void
notifyDataRehashed(ConsistentHash oldCH, ConsistentHash newCH, ConsistentHash unionCH, int newTopologyId, boolean pre)
void
notifyPartitionStatusChanged(AvailabilityMode mode, boolean pre)
void
notifyPersistenceAvailabilityChanged(boolean available)
void
notifyTopologyChanged(CacheTopology oldTopology, CacheTopology newTopology, int newTopologyId, boolean pre)
void
notifyTransactionCompleted(GlobalTransaction transaction, boolean successful, InvocationContext ctx)
Notifies all registered listeners of a transaction completion event.void
notifyTransactionRegistered(GlobalTransaction globalTransaction, boolean isOriginLocal)
Notifies all registered listeners of a transaction registration event.void
removeListener(Object listener)
Removes a listener from the component.protected Set<CacheEntryListenerInvocation<K,V>>
removeListenerInvocation(Class<? extends Annotation> annotation, Object listener)
protected void
resumeIfNeeded(Transaction transaction)
Collection<DistributedCallable>
retrieveClusterListenerCallablesToInstall()
This method is invoked so that this node can send the details required for a new node to be bootstrapped with the existing cluster listeners that are already installed.void
start()
void
stop()
Removes all listeners from the notifierprotected Transaction
suspendIfNeeded()
-
Methods inherited from class org.infinispan.notifications.impl.AbstractListenerImpl
canApply, findListenerCallbacks, getListeners, testListenerClassValidity, testListenerMethodValidity, validateAndAddFilterListenerInvocations, validateAndAddListenerInvocations
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.infinispan.notifications.Listenable
getListeners
-
-
-
-
Method Detail
-
start
public void start()
- Overrides:
start
in classAbstractListenerImpl<Event<K,V>,CacheEntryListenerInvocation<K,V>>
-
stop
public void stop()
Description copied from class:AbstractListenerImpl
Removes all listeners from the notifier- Overrides:
stop
in classAbstractListenerImpl<Event<K,V>,CacheEntryListenerInvocation<K,V>>
-
getLog
protected Log getLog()
- Specified by:
getLog
in classAbstractListenerImpl<Event<K,V>,CacheEntryListenerInvocation<K,V>>
-
getAllowedMethodAnnotations
protected Map<Class<? extends Annotation>,Class<?>> getAllowedMethodAnnotations(Listener l)
- Specified by:
getAllowedMethodAnnotations
in classAbstractListenerImpl<Event<K,V>,CacheEntryListenerInvocation<K,V>>
-
suspendIfNeeded
protected final Transaction suspendIfNeeded()
- Specified by:
suspendIfNeeded
in classAbstractListenerImpl<Event<K,V>,CacheEntryListenerInvocation<K,V>>
-
resumeIfNeeded
protected final void resumeIfNeeded(Transaction transaction)
- Specified by:
resumeIfNeeded
in classAbstractListenerImpl<Event<K,V>,CacheEntryListenerInvocation<K,V>>
-
notifyCacheEntryCreated
public void notifyCacheEntryCreated(K key, V value, Metadata metadata, boolean pre, InvocationContext ctx, FlagAffectedCommand command)
Description copied from interface:CacheNotifier
Notifies all registered listeners of aCacheEntryCreatedEvent
event.- Specified by:
notifyCacheEntryCreated
in interfaceCacheNotifier<K,V>
-
notifyCacheEntryModified
public void notifyCacheEntryModified(K key, V value, Metadata metadata, V previousValue, Metadata previousMetadata, boolean pre, InvocationContext ctx, FlagAffectedCommand command)
Description copied from interface:CacheNotifier
Notifies all registered listeners of aCacheEntryModifiedEvent
event.- Specified by:
notifyCacheEntryModified
in interfaceCacheNotifier<K,V>
-
notifyCacheEntryRemoved
public void notifyCacheEntryRemoved(K key, V previousValue, Metadata previousMetadata, boolean pre, InvocationContext ctx, FlagAffectedCommand command)
Description copied from interface:CacheNotifier
Notifies all registered listeners of aCacheEntryRemovedEvent
event.- Specified by:
notifyCacheEntryRemoved
in interfaceCacheNotifier<K,V>
-
notifyCacheEntryVisited
public void notifyCacheEntryVisited(K key, V value, boolean pre, InvocationContext ctx, FlagAffectedCommand command)
Description copied from interface:CacheNotifier
Notifies all registered listeners of aCacheEntryVisitedEvent
event.- Specified by:
notifyCacheEntryVisited
in interfaceCacheNotifier<K,V>
-
notifyCacheEntriesEvicted
public void notifyCacheEntriesEvicted(Collection<InternalCacheEntry<? extends K,? extends V>> entries, InvocationContext ctx, FlagAffectedCommand command)
Description copied from interface:CacheNotifier
Notifies all registered listeners of aCacheEntriesEvictedEvent
event.- Specified by:
notifyCacheEntriesEvicted
in interfaceCacheNotifier<K,V>
-
notifyCacheEntryExpired
public void notifyCacheEntryExpired(K key, V value, Metadata metadata, InvocationContext ctx)
Description copied from interface:CacheNotifier
Notifies all registered listeners of a CacheEntryExpired event.- Specified by:
notifyCacheEntryExpired
in interfaceCacheNotifier<K,V>
-
notifyCacheEntryInvalidated
public void notifyCacheEntryInvalidated(K key, V value, Metadata metadata, boolean pre, InvocationContext ctx, FlagAffectedCommand command)
Description copied from interface:CacheNotifier
Notifies all registered listeners of aCacheEntryInvalidatedEvent
event.- Specified by:
notifyCacheEntryInvalidated
in interfaceCacheNotifier<K,V>
-
notifyCacheEntryLoaded
public void notifyCacheEntryLoaded(K key, V value, boolean pre, InvocationContext ctx, FlagAffectedCommand command)
Description copied from interface:CacheNotifier
Notifies all registered listeners of aCacheEntryLoadedEvent
event.- Specified by:
notifyCacheEntryLoaded
in interfaceCacheNotifier<K,V>
-
notifyCacheEntryActivated
public void notifyCacheEntryActivated(K key, V value, boolean pre, InvocationContext ctx, FlagAffectedCommand command)
Description copied from interface:CacheNotifier
Notifies all registered listeners of aCacheEntryActivatedEvent
event.- Specified by:
notifyCacheEntryActivated
in interfaceCacheNotifier<K,V>
-
notifyCacheEntryPassivated
public void notifyCacheEntryPassivated(K key, V value, boolean pre, InvocationContext ctx, FlagAffectedCommand command)
Description copied from interface:CacheNotifier
Notifies all registered listeners of aCacheEntryPassivatedEvent
event.- Specified by:
notifyCacheEntryPassivated
in interfaceCacheNotifier<K,V>
-
notifyTransactionCompleted
public void notifyTransactionCompleted(GlobalTransaction transaction, boolean successful, InvocationContext ctx)
Description copied from interface:CacheNotifier
Notifies all registered listeners of a transaction completion event.- Specified by:
notifyTransactionCompleted
in interfaceCacheNotifier<K,V>
- Parameters:
transaction
- the transaction that has just completedsuccessful
- if true, the transaction committed. If false, this is a rollback event
-
notifyTransactionRegistered
public void notifyTransactionRegistered(GlobalTransaction globalTransaction, boolean isOriginLocal)
Description copied from interface:CacheNotifier
Notifies all registered listeners of a transaction registration event.- Specified by:
notifyTransactionRegistered
in interfaceCacheNotifier<K,V>
-
notifyDataRehashed
public void notifyDataRehashed(ConsistentHash oldCH, ConsistentHash newCH, ConsistentHash unionCH, int newTopologyId, boolean pre)
- Specified by:
notifyDataRehashed
in interfaceCacheNotifier<K,V>
-
notifyTopologyChanged
public void notifyTopologyChanged(CacheTopology oldTopology, CacheTopology newTopology, int newTopologyId, boolean pre)
- Specified by:
notifyTopologyChanged
in interfaceCacheNotifier<K,V>
-
notifyPartitionStatusChanged
public void notifyPartitionStatusChanged(AvailabilityMode mode, boolean pre)
- Specified by:
notifyPartitionStatusChanged
in interfaceCacheNotifier<K,V>
-
notifyPersistenceAvailabilityChanged
public void notifyPersistenceAvailabilityChanged(boolean available)
- Specified by:
notifyPersistenceAvailabilityChanged
in interfaceCacheNotifier<K,V>
-
notifyClusterListeners
public void notifyClusterListeners(Collection<? extends CacheEntryEvent<K,V>> events, UUID uuid)
Description copied from interface:ClusterCacheNotifier
Method that is invoked on the node that has the given cluster listener that when registered generated the given listenerId. Note this will notify only cluster listeners and regular listeners are not notified of the events. Will fire the events in the order of the iteration of the collection.- Specified by:
notifyClusterListeners
in interfaceClusterCacheNotifier<K,V>
-
retrieveClusterListenerCallablesToInstall
public Collection<DistributedCallable> retrieveClusterListenerCallablesToInstall()
Description copied from interface:ClusterCacheNotifier
This method is invoked so that this node can send the details required for a new node to be bootstrapped with the existing cluster listeners that are already installed.- Specified by:
retrieveClusterListenerCallablesToInstall
in interfaceClusterCacheNotifier<K,V>
- Returns:
- A collection of callables that should be invoked on the new node to properly install cluster listener information
-
isNotificationAllowed
public boolean isNotificationAllowed(FlagAffectedCommand cmd, List<CacheEntryListenerInvocation<K,V>> listeners)
-
addListener
public void addListener(Object listener)
Description copied from interface:Listenable
Adds a listener to the component. Typically, listeners would need to be annotated withListener
and further to that, contain methods annotated appropriately, otherwise the listener will not be registered. See theListener
annotation for more information.- Specified by:
addListener
in interfaceListenable
- Parameters:
listener
- must not be null.
-
addListener
public void addListener(Object listener, ClassLoader classLoader)
Description copied from interface:ClassLoaderAwareListenable
Adds a listener along with a class loader to use for the invocation- Specified by:
addListener
in interfaceClassLoaderAwareListenable
-
addListener
public void addListener(Object listener, KeyFilter<? super K> filter, ClassLoader classLoader)
Description copied from interface:ClassLoaderAwareFilteringListenable
Adds a listener to the component. Typically, listeners would need to be annotated withListener
and further to that, contain methods annotated appropriately, otherwise the listener will not be registered. See theListener
annotation for more information.- Specified by:
addListener
in interfaceClassLoaderAwareFilteringListenable<K,V>
- Parameters:
listener
- must not be null.classLoader
- class loader
-
addListener
public <C> void addListener(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, ClassLoader classLoader)
Adds the listener using the provided filter converter and class loader. The provided builder is used to add additional configuration including (clustered, onlyPrimary & identifier) which can be used after this method is completed to see what values were used in the addition of this listener- Specified by:
addListener
in interfaceClassLoaderAwareFilteringListenable<K,V>
- Type Parameters:
C
-- Parameters:
listener
-filter
-converter
-classLoader
-
-
getListenerCollectionForAnnotation
public List<CacheEntryListenerInvocation<K,V>> getListenerCollectionForAnnotation(Class<? extends Annotation> annotation)
- Overrides:
getListenerCollectionForAnnotation
in classAbstractListenerImpl<Event<K,V>,CacheEntryListenerInvocation<K,V>>
-
addListener
public void addListener(Object listener, KeyFilter<? super K> filter)
Description copied from interface:FilteringListenable
Adds a listener to the component. Typically, listeners would need to be annotated withListener
and further to that, contain methods annotated appropriately, otherwise the listener will not be registered. See theListener
annotation for more information.- Specified by:
addListener
in interfaceFilteringListenable<K,V>
- Parameters:
listener
- must not be null.
-
addListener
public <C> void addListener(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter)
Description copied from interface:FilteringListenable
Registers a listener that will be notified on events that pass the filter condition. The value presented in the notifications will be first converted using the provided converter if there is one.Some implementations may provide optimizations when a
CacheEventFilterConverter
is provided as both arguments to the filter and converter arguments. Note the provided object must have reference equality ie. (==) to be recognized. This allows for the filter and conversion step to take place in the same method call reducing possible overhead.- Specified by:
addListener
in interfaceFilteringListenable<K,V>
- Type Parameters:
C
- The type of the resultant value after being converted- Parameters:
listener
- The listener to callback upon event notifications. Must not be null.filter
- The filter to see if the notification should be sent to the listener. Can be null.converter
- The converter to apply to the entry before being sent to the listener. Can be null.
-
addFilteredListener
public <C> void addFilteredListener(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, Set<Class<? extends Annotation>> filterAnnotations)
Description copied from interface:FilteringListenable
Registers a listener limiting the cache-entry specific events only to annotations that are passed in as parameter. For example, if the listener passed in contains callbacks forCacheEntryCreated
andCacheEntryModified
, and filtered annotations contains onlyCacheEntryCreated
, then the listener will be registered only forCacheEntryCreated
callbacks. Callback filtering only applies toCacheEntryCreated
,CacheEntryModified
,CacheEntryRemoved
andCacheEntryExpired
annotations. If the listener contains other annotations, these are preserved. This methods enables dynamic registration of listener interests at runtime without the need to create several different listener classes.- Specified by:
addFilteredListener
in interfaceFilteringListenable<K,V>
- Type Parameters:
C
- The type of the resultant value after being converted- Parameters:
listener
- The listener to callback upon event notifications. Must not be null.filter
- The filter to see if the notification should be sent to the listener. Can be null.converter
- The converter to apply to the entry before being sent to the listener. Can be null.filterAnnotations
- cache-entry annotations to allow listener to be registered on. Must not be null.
-
addStorageFormatFilteredListener
public <C> void addStorageFormatFilteredListener(Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, Set<Class<? extends Annotation>> filterAnnotations)
Description copied from interface:FilteringListenable
Same asFilteringListenable.addFilteredListener(Object, CacheEventFilter, CacheEventConverter, Set)
, but assumes the filter and/or the converter will be done in the same data format as it's stored in the cache.- Specified by:
addStorageFormatFilteredListener
in interfaceFilteringListenable<K,V>
-
addListener
public <C> void addListener(ListenerHolder listenerHolder, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, ClassLoader classLoader)
- Specified by:
addListener
in interfaceDataConversionAwareListenable<K,V>
-
addListener
public <C> void addListener(ListenerHolder listenerHolder, KeyFilter<? super K> filter)
- Specified by:
addListener
in interfaceDataConversionAwareListenable<K,V>
-
addFilteredListener
public <C> void addFilteredListener(ListenerHolder listenerHolder, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, Set<Class<? extends Annotation>> filterAnnotations)
- Specified by:
addFilteredListener
in interfaceDataConversionAwareListenable<K,V>
-
removeListener
public void removeListener(Object listener)
Description copied from interface:Listenable
Removes a listener from the component.- Specified by:
removeListener
in interfaceListenable
- Overrides:
removeListener
in classAbstractListenerImpl<Event<K,V>,CacheEntryListenerInvocation<K,V>>
- Parameters:
listener
- listener to remove. Must not be null.
-
removeListenerInvocation
protected Set<CacheEntryListenerInvocation<K,V>> removeListenerInvocation(Class<? extends Annotation> annotation, Object listener)
- Overrides:
removeListenerInvocation
in classAbstractListenerImpl<Event<K,V>,CacheEntryListenerInvocation<K,V>>
-
-