Class SerializingCache<K extends Serializable,V extends Serializable>
- java.lang.String
- org.xmpp.packet.JID
- Author:
- Guus der Kinderen, guus.der.kinderen@gmail.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jivesoftware.util.cache.Cache
Cache.CapacityUnit -
Field Summary
Fields inherited from interface org.jivesoftware.util.cache.Cache
secretKey, secretValue -
Method Summary
Modifier and TypeMethodDescriptionaddClusteredCacheEntryListener(ClusteredCacheEntryListener<K, V> listener, boolean includeValues, boolean includeEventsFromLocalNode) Registers a listener to receive entry events for this cache.voidclear()booleancontainsKey(Object key) booleancontainsValue(Object value) voidRemoves the registration of key and value class definitions.entrySet()IMPORTANT: Unlike the standardMap.entrySet()implementation, the set returned from this method cannot be modified.longReturns the number of cache hits.longReturns the number of cache misses.An optional, human-readable remark on the current size of the cache.Defines the unit used to calculate the capacity of the cache.Returns an existingLockon the specified key or creates a new one if none was found.longReturns the size of the cache.longReturns the maximum size of the cache.An optional, human-readable remark on the maximum cache capacity configuration.longReturns the maximum number of milliseconds that any object can live in cache.getName()Returns the name of the cache.booleanisEmpty()keySet()IMPORTANT: Unlike the standardMap.keySet()implementation, the set returned from this method cannot be modified.protected Stringmarshall(Serializable object, Class<?> typeClass) voidvoidregisterClasses(Class<K> keyClass, Class<V> valueClass) The cache will store (in serialized form) entries of which the keys are instances of the provided keyClass argument.voidremoveClusteredCacheEntryListener(String listenerId) Removes a previously registered event listener.voidsetMaxCacheSize(long maxSize) Sets the maximum size of the cache.voidsetMaxLifetime(long maxLifetime) Sets the maximum number of milliseconds that any object can live in cache.voidSets the name of the cacheintsize()protected Serializableunmarshall(String object, Class<?> typeClass) values()IMPORTANT: Unlike the standardMap.values()implementation, the collection returned from this method cannot be modified.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jivesoftware.util.cache.Cache
isKeySecret, isValueSecret, setSecretKey, setSecretValueMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Method Details
-
registerClasses
The cache will store (in serialized form) entries of which the keys are instances of the provided keyClass argument. The values are correspondingly instances of the provided valueClass argument. When this method is invoked more than once, the definitions provided by the last invocation will be used.- Parameters:
keyClass- The class of instances used as keys.valueClass- The class of instances used as values.- Throws:
IllegalArgumentException- when keyClass and/or valueClass cannot be used to serialize and deserialize instances.
-
deregisterClasses
public void deregisterClasses()Removes the registration of key and value class definitions. This is typically useful when the provided classes are provided by a plugin, and that plugin is being unloaded/replaced. When this method is not used, a reference to the classes from the original PluginClassLoader will be retained, which will cause ClassCastExceptions when interacting with the cache. An invocation of this method does not affect the data stored in the cache. After registering the class types again (using #registerClasses) that data can be stored in and retrieved from the cache again. -
marshall
-
unmarshall
-
getKeyClass
-
getValueClass
-
put
- Specified by:
putin interfaceMap<K extends Serializable,V extends Serializable>
-
get
- Specified by:
getin interfaceMap<K extends Serializable,V extends Serializable>
-
remove
- Specified by:
removein interfaceMap<K extends Serializable,V extends Serializable>
-
clear
public void clear()- Specified by:
clearin interfaceMap<K extends Serializable,V extends Serializable>
-
size
public int size()- Specified by:
sizein interfaceMap<K extends Serializable,V extends Serializable>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceMap<K extends Serializable,V extends Serializable>
-
values
Description copied from interface:CacheIMPORTANT: Unlike the standardMap.values()implementation, the collection returned from this method cannot be modified.- Specified by:
valuesin interfaceCache<K extends Serializable,V extends Serializable> - Specified by:
valuesin interfaceMap<K extends Serializable,V extends Serializable> - Returns:
- an unmodifiable collection view of the values contained in this map
-
containsKey
- Specified by:
containsKeyin interfaceMap<K extends Serializable,V extends Serializable>
-
putAll
- Specified by:
putAllin interfaceMap<K extends Serializable,V extends Serializable>
-
containsValue
- Specified by:
containsValuein interfaceMap<K extends Serializable,V extends Serializable>
-
entrySet
Description copied from interface:CacheIMPORTANT: Unlike the standardMap.entrySet()implementation, the set returned from this method cannot be modified.- Specified by:
entrySetin interfaceCache<K extends Serializable,V extends Serializable> - Specified by:
entrySetin interfaceMap<K extends Serializable,V extends Serializable> - Returns:
- an unmodifiable set view of the mappings contained in this map
-
keySet
Description copied from interface:CacheIMPORTANT: Unlike the standardMap.keySet()implementation, the set returned from this method cannot be modified.- Specified by:
keySetin interfaceCache<K extends Serializable,V extends Serializable> - Specified by:
keySetin interfaceMap<K extends Serializable,V extends Serializable> - Returns:
- an unmodifiable set view of the keys contained in this map
-
getLock
Description copied from interface:CacheReturns an existingLockon the specified key or creates a new one if none was found. This operation is thread safe. Successive calls with the same key may or may not return the sameLock. However, different threads asking for the same Lock at the same time will get the same Lock object.The supplied cache may or may not be used depending whether the server is running on cluster mode or not. When not running as part of a cluster then the lock will be unrelated to the cache and will only be visible in this JVM.
- Specified by:
getLockin interfaceCache<K extends Serializable,V extends Serializable> - Parameters:
key- the object that defines the visibility or scope of the lock.- Returns:
- an existing lock on the specified key or creates a new one if none was found.
-
getCapacityUnit
Description copied from interface:CacheDefines the unit used to calculate the capacity of the cache.When the unit is unknown, null is returned.
- Specified by:
getCapacityUnitin interfaceCache<K extends Serializable,V extends Serializable> - Returns:
- the unit to be used to calculate the capacity of this cache.
-
getName
Description copied from interface:CacheReturns the name of the cache.- Specified by:
getNamein interfaceCache<K extends Serializable,V extends Serializable> - Returns:
- the name of the cache.
-
setName
Description copied from interface:CacheSets the name of the cache- Specified by:
setNamein interfaceCache<K extends Serializable,V extends Serializable> - Parameters:
name- the name of the cache
-
getCacheHits
public long getCacheHits()Description copied from interface:CacheReturns the number of cache hits. A cache hit occurs every time the get method is called and the cache contains the requested object.Keeping track of cache hits and misses lets one measure how efficient the cache is; the higher the percentage of hits, the more efficient.
- Specified by:
getCacheHitsin interfaceCache<K extends Serializable,V extends Serializable> - Returns:
- the number of cache hits.
-
getCacheMisses
public long getCacheMisses()Description copied from interface:CacheReturns the number of cache misses. A cache miss occurs every time the get method is called and the cache does not contain the requested object.Keeping track of cache hits and misses lets one measure how efficient the cache is; the higher the percentage of hits, the more efficient.
- Specified by:
getCacheMissesin interfaceCache<K extends Serializable,V extends Serializable> - Returns:
- the number of cache hits.
-
getLongCacheSize
public long getLongCacheSize()Description copied from interface:CacheReturns the size of the cache.The value should be placed in context of the unit returned by
Cache.getCapacityUnit(). When, for example, the capacity unit for this cache isCache.CapacityUnit.BYTES, then a return value of 2048 should be interpreted as all entities of this cache having a combined size of 2024 bytes (or 2KB). When the capacity unit isCache.CapacityUnit.ENTITIESthen this cache currently contains 2048 elements.The returned value can be an approximation.
- Specified by:
getLongCacheSizein interfaceCache<K extends Serializable,V extends Serializable> - Returns:
- the size of the cache contents.
-
getCacheSizeRemark
Description copied from interface:CacheAn optional, human-readable remark on the current size of the cache.- Specified by:
getCacheSizeRemarkin interfaceCache<K extends Serializable,V extends Serializable> - Returns:
- an optional human-readable text
-
getMaxCacheSize
public long getMaxCacheSize()Description copied from interface:CacheReturns the maximum size of the cache.The value should be placed in context of the unit returned by
Cache.getCapacityUnit(). When, for example, the capacity unit for this cache isCache.CapacityUnit.BYTES, then a return value of 2048 should be interpreted as this cache having a capacity of 2048 bytes (or 2KB). When the capacity unit isCache.CapacityUnit.ENTITIESthen this cache can contain 2048 elements (irrespective of their byte size).If the cache grows larger than the maximum size, the least frequently used items will be removed.
If the maximum cache size is set to -1, there is no size limit.
- Specified by:
getMaxCacheSizein interfaceCache<K extends Serializable,V extends Serializable> - Returns:
- the maximum size of the cache.
-
setMaxCacheSize
public void setMaxCacheSize(long maxSize) Description copied from interface:CacheSets the maximum size of the cache.The value should be placed in context of the unit returned by
Cache.getCapacityUnit(). When, for example, the capacity unit for this cache isCache.CapacityUnit.BYTES, then a return value of 2048 should be interpreted as this cache having a capacity of 2048 bytes (or 2KB). When the capacity unit isCache.CapacityUnit.ENTITIESthen this cache can contain 2048 elements (irrespective of their byte size).If the cache grows larger than the maximum size, the least frequently used items will be removed. If the maximum cache size is set to -1, there is no size limit.
Note: If using the Hazelcast clustering plugin, this will only take effect if the cache is dynamically configured (not defined in the hazelcast-cache-config.xml file), and will not take effect until the next time the cache is created.
- Specified by:
setMaxCacheSizein interfaceCache<K extends Serializable,V extends Serializable> - Parameters:
maxSize- the maximum size of the cache.
-
getMaxCacheSizeRemark
Description copied from interface:CacheAn optional, human-readable remark on the maximum cache capacity configuration.- Specified by:
getMaxCacheSizeRemarkin interfaceCache<K extends Serializable,V extends Serializable> - Returns:
- an optional human-readable text
-
getMaxLifetime
public long getMaxLifetime()Description copied from interface:CacheReturns the maximum number of milliseconds that any object can live in cache. Once the specified number of milliseconds passes, the object will be automatically expired from cache. If the max lifetime is set to -1, then objects never expire.- Specified by:
getMaxLifetimein interfaceCache<K extends Serializable,V extends Serializable> - Returns:
- the maximum number of milliseconds before objects are expired.
-
setMaxLifetime
public void setMaxLifetime(long maxLifetime) Description copied from interface:CacheSets the maximum number of milliseconds that any object can live in cache. Once the specified number of milliseconds passes, the object will be automatically expired from cache. If the max lifetime is set to -1, then objects never expire.Note: If using the Hazelcast clustering plugin, this will only take effect if the cache is dynamically configured (not defined in the hazelcast-cache-config.xml file), and will not take effect until the next time the cache is created.
- Specified by:
setMaxLifetimein interfaceCache<K extends Serializable,V extends Serializable> - Parameters:
maxLifetime- the maximum number of milliseconds before objects are expired.
-
getDelegate
-
addClusteredCacheEntryListener
public String addClusteredCacheEntryListener(@Nonnull ClusteredCacheEntryListener<K, V> listener, boolean includeValues, boolean includeEventsFromLocalNode) Description copied from interface:CacheRegisters a listener to receive entry events for this cache. To optimize the amount of data that is being processed, this method allows the listener to be registered in a way that suppresses values from being sent to it. In that case, only keys will be included in the event listener invocation.- Specified by:
addClusteredCacheEntryListenerin interfaceCache<K extends Serializable,V extends Serializable> - Parameters:
listener- the listener to be registered.includeValues- defines if the listener should receive the values associated with the events.includeEventsFromLocalNode- defines if the listener should be invoked for events that originate on the local node.- Returns:
- a unique identifier for the listener which is used as a key to remove the listener
-
removeClusteredCacheEntryListener
Description copied from interface:CacheRemoves a previously registered event listener.- Specified by:
removeClusteredCacheEntryListenerin interfaceCache<K extends Serializable,V extends Serializable> - Parameters:
listenerId- the identifier of the listener to be removed.
-