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 org.infinispan.notifications.impl.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 classCacheNotifierImpl.BaseCacheEntryListenerInvocation<K,V>protected classCacheNotifierImpl.CacheInvocationBuilderprotected static classCacheNotifierImpl.ClusteredListenerInvocation<K,V>This class is to be used with cluster listener invocations only when they have included current state.protected classCacheNotifierImpl.DelegatingCacheInvocationBuilder
-
Constructor Summary
Constructors Constructor Description CacheNotifierImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <C> voidaddFilteredListener(java.lang.Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> filterAnnotations)Registers a listener limiting the cache-entry specific events only to annotations that are passed in as parameter.<C> voidaddFilteredListener(ListenerHolder listenerHolder, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> filterAnnotations)voidaddListener(java.lang.Object listener)Adds a listener to the component.voidaddListener(java.lang.Object listener, java.lang.ClassLoader classLoader)Adds a listener along with a class loader to use for the invocationvoidaddListener(java.lang.Object listener, KeyFilter<? super K> filter)Adds a listener to the component.voidaddListener(java.lang.Object listener, KeyFilter<? super K> filter, java.lang.ClassLoader classLoader)Adds a listener to the component.<C> voidaddListener(java.lang.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> voidaddListener(java.lang.Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, java.lang.ClassLoader classLoader)Adds the listener using the provided filter converter and class loader.<C> voidaddListener(ListenerHolder listenerHolder, KeyFilter<? super K> filter)<C> voidaddListener(ListenerHolder listenerHolder, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, java.lang.ClassLoader classLoader)<C> voidaddStorageFormatFilteredListener(java.lang.Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, java.util.Set<java.lang.Class<? extends java.lang.annotation.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 java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.lang.Class<?>>getAllowedMethodAnnotations(Listener l)java.util.List<CacheEntryListenerInvocation<K,V>>getListenerCollectionForAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)protected org.infinispan.util.logging.LoggetLog()booleanisNotificationAllowed(org.infinispan.commands.FlagAffectedCommand cmd, java.util.List<CacheEntryListenerInvocation<K,V>> listeners)voidnotifyCacheEntriesEvicted(java.util.Collection<java.util.Map.Entry<K,V>> entries, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)Notifies all registered listeners of aCacheEntriesEvictedEventevent.voidnotifyCacheEntryActivated(K key, V value, boolean pre, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)Notifies all registered listeners of aCacheEntryActivatedEventevent.voidnotifyCacheEntryCreated(K key, V value, Metadata metadata, boolean pre, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)Notifies all registered listeners of aCacheEntryCreatedEventevent.voidnotifyCacheEntryExpired(K key, V value, Metadata metadata, InvocationContext ctx)Notifies all registered listeners of a CacheEntryExpired event.voidnotifyCacheEntryInvalidated(K key, V value, Metadata metadata, boolean pre, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)Notifies all registered listeners of aCacheEntryInvalidatedEventevent.voidnotifyCacheEntryLoaded(K key, V value, boolean pre, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)Notifies all registered listeners of aCacheEntryLoadedEventevent.voidnotifyCacheEntryModified(K key, V value, Metadata metadata, V previousValue, Metadata previousMetadata, boolean pre, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)Notifies all registered listeners of aCacheEntryModifiedEventevent.voidnotifyCacheEntryPassivated(K key, V value, boolean pre, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)Notifies all registered listeners of aCacheEntryPassivatedEventevent.voidnotifyCacheEntryRemoved(K key, V previousValue, Metadata previousMetadata, boolean pre, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)Notifies all registered listeners of aCacheEntryRemovedEventevent.voidnotifyCacheEntryVisited(K key, V value, boolean pre, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)Notifies all registered listeners of aCacheEntryVisitedEventevent.voidnotifyClusterListeners(java.util.Collection<? extends CacheEntryEvent<K,V>> events, java.util.UUID uuid)Method that is invoked on the node that has the given cluster listener that when registered generated the given listenerId.voidnotifyDataRehashed(ConsistentHash oldCH, ConsistentHash newCH, ConsistentHash unionCH, int newTopologyId, boolean pre)voidnotifyPartitionStatusChanged(AvailabilityMode mode, boolean pre)voidnotifyPersistenceAvailabilityChanged(boolean available)voidnotifyTopologyChanged(CacheTopology oldTopology, CacheTopology newTopology, int newTopologyId, boolean pre)voidnotifyTransactionCompleted(GlobalTransaction transaction, boolean successful, InvocationContext ctx)Notifies all registered listeners of a transaction completion event.voidnotifyTransactionRegistered(GlobalTransaction globalTransaction, boolean isOriginLocal)Notifies all registered listeners of a transaction registration event.voidremoveListener(java.lang.Object listener)Removes a listener from the component.protected java.util.Set<CacheEntryListenerInvocation<K,V>>removeListenerInvocation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.Object listener)protected voidresumeIfNeeded(javax.transaction.Transaction transaction)java.util.Collection<ClusterListenerReplicateCallable<K,V>>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.voidstart()voidstop()Removes all listeners from the notifierprotected javax.transaction.TransactionsuspendIfNeeded()-
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()
-
stop
public void stop()
Description copied from class:org.infinispan.notifications.impl.AbstractListenerImplRemoves all listeners from the notifier
-
getLog
protected org.infinispan.util.logging.Log getLog()
-
getAllowedMethodAnnotations
protected java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.lang.Class<?>> getAllowedMethodAnnotations(Listener l)
-
suspendIfNeeded
protected final javax.transaction.Transaction suspendIfNeeded()
-
resumeIfNeeded
protected final void resumeIfNeeded(javax.transaction.Transaction transaction)
-
notifyCacheEntryCreated
public void notifyCacheEntryCreated(K key, V value, Metadata metadata, boolean pre, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)
Description copied from interface:CacheNotifierNotifies all registered listeners of aCacheEntryCreatedEventevent.- Specified by:
notifyCacheEntryCreatedin interfaceCacheNotifier<K,V>
-
notifyCacheEntryModified
public void notifyCacheEntryModified(K key, V value, Metadata metadata, V previousValue, Metadata previousMetadata, boolean pre, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)
Description copied from interface:CacheNotifierNotifies all registered listeners of aCacheEntryModifiedEventevent.- Specified by:
notifyCacheEntryModifiedin interfaceCacheNotifier<K,V>
-
notifyCacheEntryRemoved
public void notifyCacheEntryRemoved(K key, V previousValue, Metadata previousMetadata, boolean pre, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)
Description copied from interface:CacheNotifierNotifies all registered listeners of aCacheEntryRemovedEventevent.- Specified by:
notifyCacheEntryRemovedin interfaceCacheNotifier<K,V>
-
notifyCacheEntryVisited
public void notifyCacheEntryVisited(K key, V value, boolean pre, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)
Description copied from interface:CacheNotifierNotifies all registered listeners of aCacheEntryVisitedEventevent.- Specified by:
notifyCacheEntryVisitedin interfaceCacheNotifier<K,V>
-
notifyCacheEntriesEvicted
public void notifyCacheEntriesEvicted(java.util.Collection<java.util.Map.Entry<K,V>> entries, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)
Description copied from interface:CacheNotifierNotifies all registered listeners of aCacheEntriesEvictedEventevent.- Specified by:
notifyCacheEntriesEvictedin interfaceCacheNotifier<K,V>
-
notifyCacheEntryExpired
public void notifyCacheEntryExpired(K key, V value, Metadata metadata, InvocationContext ctx)
Description copied from interface:CacheNotifierNotifies all registered listeners of a CacheEntryExpired event.- Specified by:
notifyCacheEntryExpiredin interfaceCacheNotifier<K,V>
-
notifyCacheEntryInvalidated
public void notifyCacheEntryInvalidated(K key, V value, Metadata metadata, boolean pre, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)
Description copied from interface:CacheNotifierNotifies all registered listeners of aCacheEntryInvalidatedEventevent.- Specified by:
notifyCacheEntryInvalidatedin interfaceCacheNotifier<K,V>
-
notifyCacheEntryLoaded
public void notifyCacheEntryLoaded(K key, V value, boolean pre, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)
Description copied from interface:CacheNotifierNotifies all registered listeners of aCacheEntryLoadedEventevent.- Specified by:
notifyCacheEntryLoadedin interfaceCacheNotifier<K,V>
-
notifyCacheEntryActivated
public void notifyCacheEntryActivated(K key, V value, boolean pre, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)
Description copied from interface:CacheNotifierNotifies all registered listeners of aCacheEntryActivatedEventevent.- Specified by:
notifyCacheEntryActivatedin interfaceCacheNotifier<K,V>
-
notifyCacheEntryPassivated
public void notifyCacheEntryPassivated(K key, V value, boolean pre, InvocationContext ctx, org.infinispan.commands.FlagAffectedCommand command)
Description copied from interface:CacheNotifierNotifies all registered listeners of aCacheEntryPassivatedEventevent.- Specified by:
notifyCacheEntryPassivatedin interfaceCacheNotifier<K,V>
-
notifyTransactionCompleted
public void notifyTransactionCompleted(GlobalTransaction transaction, boolean successful, InvocationContext ctx)
Description copied from interface:CacheNotifierNotifies all registered listeners of a transaction completion event.- Specified by:
notifyTransactionCompletedin 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:CacheNotifierNotifies all registered listeners of a transaction registration event.- Specified by:
notifyTransactionRegisteredin interfaceCacheNotifier<K,V>
-
notifyDataRehashed
public void notifyDataRehashed(ConsistentHash oldCH, ConsistentHash newCH, ConsistentHash unionCH, int newTopologyId, boolean pre)
- Specified by:
notifyDataRehashedin interfaceCacheNotifier<K,V>
-
notifyTopologyChanged
public void notifyTopologyChanged(CacheTopology oldTopology, CacheTopology newTopology, int newTopologyId, boolean pre)
- Specified by:
notifyTopologyChangedin interfaceCacheNotifier<K,V>
-
notifyPartitionStatusChanged
public void notifyPartitionStatusChanged(AvailabilityMode mode, boolean pre)
- Specified by:
notifyPartitionStatusChangedin interfaceCacheNotifier<K,V>
-
notifyPersistenceAvailabilityChanged
public void notifyPersistenceAvailabilityChanged(boolean available)
- Specified by:
notifyPersistenceAvailabilityChangedin interfaceCacheNotifier<K,V>
-
notifyClusterListeners
public void notifyClusterListeners(java.util.Collection<? extends CacheEntryEvent<K,V>> events, java.util.UUID uuid)
Description copied from interface:ClusterCacheNotifierMethod 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:
notifyClusterListenersin interfaceClusterCacheNotifier<K,V>
-
retrieveClusterListenerCallablesToInstall
public java.util.Collection<ClusterListenerReplicateCallable<K,V>> retrieveClusterListenerCallablesToInstall()
Description copied from interface:ClusterCacheNotifierThis 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:
retrieveClusterListenerCallablesToInstallin 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(org.infinispan.commands.FlagAffectedCommand cmd, java.util.List<CacheEntryListenerInvocation<K,V>> listeners)
-
addListener
public void addListener(java.lang.Object listener)
Description copied from interface:ListenableAdds a listener to the component. Typically, listeners would need to be annotated withListenerand further to that, contain methods annotated appropriately, otherwise the listener will not be registered. See theListenerannotation for more information.- Specified by:
addListenerin interfaceListenable- Parameters:
listener- must not be null.
-
addListener
public void addListener(java.lang.Object listener, java.lang.ClassLoader classLoader)Description copied from interface:ClassLoaderAwareListenableAdds a listener along with a class loader to use for the invocation- Specified by:
addListenerin interfaceClassLoaderAwareListenable
-
addListener
public void addListener(java.lang.Object listener, KeyFilter<? super K> filter, java.lang.ClassLoader classLoader)Description copied from interface:ClassLoaderAwareFilteringListenableAdds a listener to the component. Typically, listeners would need to be annotated withListenerand further to that, contain methods annotated appropriately, otherwise the listener will not be registered. See theListenerannotation for more information.- Specified by:
addListenerin interfaceClassLoaderAwareFilteringListenable<K,V>- Parameters:
listener- must not be null.classLoader- class loader
-
addListener
public <C> void addListener(java.lang.Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, java.lang.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:
addListenerin interfaceClassLoaderAwareFilteringListenable<K,V>- Type Parameters:
C-- Parameters:
listener-filter-converter-classLoader-
-
getListenerCollectionForAnnotation
public java.util.List<CacheEntryListenerInvocation<K,V>> getListenerCollectionForAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
-
addListener
public void addListener(java.lang.Object listener, KeyFilter<? super K> filter)Description copied from interface:FilteringListenableAdds a listener to the component. Typically, listeners would need to be annotated withListenerand further to that, contain methods annotated appropriately, otherwise the listener will not be registered. See theListenerannotation for more information.- Specified by:
addListenerin interfaceFilteringListenable<K,V>- Parameters:
listener- must not be null.
-
addListener
public <C> void addListener(java.lang.Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter)Description copied from interface:FilteringListenableRegisters 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
CacheEventFilterConverteris 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:
addListenerin 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(java.lang.Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> filterAnnotations)Description copied from interface:FilteringListenableRegisters 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 forCacheEntryCreatedandCacheEntryModified, and filtered annotations contains onlyCacheEntryCreated, then the listener will be registered only forCacheEntryCreatedcallbacks. Callback filtering only applies toCacheEntryCreated,CacheEntryModified,CacheEntryRemovedandCacheEntryExpiredannotations. 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:
addFilteredListenerin 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(java.lang.Object listener, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> filterAnnotations)Description copied from interface:FilteringListenableSame 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:
addStorageFormatFilteredListenerin interfaceFilteringListenable<K,V>
-
addListener
public <C> void addListener(ListenerHolder listenerHolder, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, java.lang.ClassLoader classLoader)
- Specified by:
addListenerin interfaceDataConversionAwareListenable<K,V>
-
addListener
public <C> void addListener(ListenerHolder listenerHolder, KeyFilter<? super K> filter)
- Specified by:
addListenerin interfaceDataConversionAwareListenable<K,V>
-
addFilteredListener
public <C> void addFilteredListener(ListenerHolder listenerHolder, CacheEventFilter<? super K,? super V> filter, CacheEventConverter<? super K,? super V,C> converter, java.util.Set<java.lang.Class<? extends java.lang.annotation.Annotation>> filterAnnotations)
- Specified by:
addFilteredListenerin interfaceDataConversionAwareListenable<K,V>
-
removeListener
public void removeListener(java.lang.Object listener)
Description copied from interface:ListenableRemoves a listener from the component.- Specified by:
removeListenerin interfaceListenable- Overrides:
removeListenerin classorg.infinispan.notifications.impl.AbstractListenerImpl<Event<K,V>,CacheEntryListenerInvocation<K,V>>- Parameters:
listener- listener to remove. Must not be null.
-
removeListenerInvocation
protected java.util.Set<CacheEntryListenerInvocation<K,V>> removeListenerInvocation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation, java.lang.Object listener)
-
-