Package org.jivesoftware.util.cache
Class ReverseLookupUpdatingCacheEntryListener<K,V>
java.lang.Object
org.jivesoftware.util.cache.ReverseLookupUpdatingCacheEntryListener<K,V>
- All Implemented Interfaces:
ClusteredCacheEntryListener<K,V>
public class ReverseLookupUpdatingCacheEntryListener<K,V>
extends Object
implements ClusteredCacheEntryListener<K,V>
Cache entry listener implementation that maintains a reverse lookup map for the cache that is being observed, which
is used to identify what cluster node is the logical owner of a particular cache entry. This information is typically
useful in scenarios where a cluster node drops out of the cluster requiring the remaining nodes to have to inform
their connected entities of what resources have become unavailable.
This implementation can be used in scenarios where exactly one cluster node 'owns' data (eg: client connection), as
well as in scenarios where more than one cluster node 'owns' data (eg: component sessions). Instances can be
configured to expect a unique owner (through a boolean argument in the constructor). When operating in that mode, an
entry addition or update will cause entries for other nodes to be removed. This can be particularly helpful when
events arrive 'out of order' (which could lead to data inconsistencies).
This implementation assumes that the cluster node on which the cache entry change originates is an owner of the
corresponding entry.
-
Constructor Summary
ConstructorsConstructorDescriptionReverseLookupUpdatingCacheEntryListener(ConcurrentMap<NodeID, Set<K>> reverseCacheRepresentation) ReverseLookupUpdatingCacheEntryListener(ConcurrentMap<NodeID, Set<K>> reverseCacheRepresentation, boolean uniqueOwnerExpected) -
Method Summary
Modifier and TypeMethodDescriptionvoidentryAdded(K key, V value, NodeID nodeID) An entry was added to the cache.voidentryEvicted(K key, V oldValue, NodeID nodeID) An entry was evicted from the cache.voidentryRemoved(K key, V oldValue, NodeID nodeID) An entry was removed from the cache.voidentryUpdated(K key, V oldValue, V newValue, NodeID nodeID) An entry was updated in the cache.voidmapCleared(NodeID nodeID) The cache was cleared.voidmapEvicted(NodeID nodeID) The cache was evicted.
-
Constructor Details
-
ReverseLookupUpdatingCacheEntryListener
public ReverseLookupUpdatingCacheEntryListener(@Nonnull ConcurrentMap<NodeID, Set<K>> reverseCacheRepresentation) -
ReverseLookupUpdatingCacheEntryListener
public ReverseLookupUpdatingCacheEntryListener(@Nonnull ConcurrentMap<NodeID, Set<K>> reverseCacheRepresentation, boolean uniqueOwnerExpected)
-
-
Method Details
-
entryAdded
Description copied from interface:ClusteredCacheEntryListenerAn entry was added to the cache.- Specified by:
entryAddedin interfaceClusteredCacheEntryListener<K,V> - Parameters:
key- The key of the entry that was added.value- The (optional) value of the entry that was added.nodeID- identifier of the node on which the cache modification occurred.
-
entryRemoved
Description copied from interface:ClusteredCacheEntryListenerAn entry was removed from the cache.- Specified by:
entryRemovedin interfaceClusteredCacheEntryListener<K,V> - Parameters:
key- The key of the entry that was removed.oldValue- The (optional) value of the entry that was removed.nodeID- identifier of the node on which the cache modification occurred.
-
entryUpdated
public void entryUpdated(@Nonnull K key, @Nullable V oldValue, @Nullable V newValue, @Nonnull NodeID nodeID) Description copied from interface:ClusteredCacheEntryListenerAn entry was updated in the cache.- Specified by:
entryUpdatedin interfaceClusteredCacheEntryListener<K,V> - Parameters:
key- The key of the entry that was changed.oldValue- The (optional) value of the entry prior to the update.newValue- The (optional) value of the entry after to the update.nodeID- identifier of the node on which the cache modification occurred.
-
entryEvicted
Description copied from interface:ClusteredCacheEntryListenerAn entry was evicted from the cache.- Specified by:
entryEvictedin interfaceClusteredCacheEntryListener<K,V> - Parameters:
key- The key of the entry that was evicted.oldValue- The (optional) value of the entry that was removed.nodeID- identifier of the node on which the cache modification occurred.
-
mapCleared
Description copied from interface:ClusteredCacheEntryListenerThe cache was cleared.- Specified by:
mapClearedin interfaceClusteredCacheEntryListener<K,V> - Parameters:
nodeID- identifier of the node on which the cache modification occurred.
-
mapEvicted
Description copied from interface:ClusteredCacheEntryListenerThe cache was evicted.- Specified by:
mapEvictedin interfaceClusteredCacheEntryListener<K,V> - Parameters:
nodeID- identifier of the node on which the cache modification occurred.
-