java.util.concurrent
package. It allows multiple threads to
access the cache concurrently without blocking each other, given that they
request different objects and the requested objects are present in the
cache.
All methods of this class should be thread safe. When exclusive access to an
entry is required, it is achieved by calling the lock()
method
on the CacheEntry
object. To ensure that the entry is always
unlocked, all calls to CacheEntry.lock()
should be followed by
a try
block with a finally
clause that unlocks the
entry.
Modifier and Type | Field and Description |
---|---|
private final ConcurrentHashMap | cache
Map with all the cached objects. |
private BackgroundCleaner | cleaner
Background cleaner which can be used to clean cached objects in a separate thread to avoid blocking the user threads. |
private volatile boolean | collectAccessCounts
Flag that tells if hit/miss/eviction counts should be collected. |
private final AtomicLong | evictions
The number of evictions from the cache. |
private final AtomicLong | hits
The number of cache hits. |
private final CacheableFactory | holderFactory
Factory which creates |
private final int | maxSize
The maximum size (number of elements) for this cache. |
private Object | mbean
The identifier of the MBean that allows monitoring of this instance. |
private final AtomicLong | misses
The number of cache misses. |
private final String | name
Name of this cache. |
private final ReplacementPolicy | replacementPolicy
Replacement policy to be used for this cache. |
private volatile boolean | stopped
Flag that indicates whether this cache instance has been shut down. |
Access | Constructor and Description |
---|---|
pack-priv | ConcurrentCache(CacheableFactory
factory which creates holderFactory, String Cacheable sthe name of the cache name, int the initial capacity of the cache initialSize, int maximum number of elements in the cache maxSize)Creates a new cache manager. |
Modifier and Type | Method and Description |
---|---|
public void | ageOut()
Implements org. |
public void | clean(Matchable
the partial (or exact) key to match partialKey)Implements org. |
public void | cleanAll()
Implements org. |
pack-priv void | cleanAndUnkeepEntry(CacheEntry
the entry to clean entry, Cacheable the cached object contained in the entry item)Clean an entry in the cache and decrement its keep count. |
private void | cleanCache(Matchable
the partial (or exact) key to match, or
partialKey)null to match all keysClean all dirty objects matching a partial key. |
pack-priv void | |
private void | |
private void | |
private void | |
public Cacheable | Returns: a reference to the cached object, ornull if the
object cannot be createdidentity of the object to create key, Object parameters passed to
createParameter)Cacheable.createIdentity() Implements org. |
public void | deregisterMBean()
Implements org. |
public boolean | Returns: true if all matching objects were removed,
false otherwisethe partial (or exact) key, or partialKey)null to
match all keysImplements org. |
pack-priv void | evictEntry(Object
identity of the entry to remove key)Evict an entry to make room for a new entry that is being inserted into the cache. |
public Cacheable | Returns: the cached object, ornull if it cannot be foundidentity of the object to find key)Implements org. |
public Cacheable | Returns: the cached object, ornull if it's not in the cacheidentity of the object to find key)Implements org. |
pack-priv long | |
pack-priv BackgroundCleaner | |
pack-priv boolean | |
private CacheEntry | |
pack-priv long | |
pack-priv long | |
pack-priv long | |
pack-priv long | |
pack-priv ReplacementPolicy | Returns: replacement policyReturn the |
private static Object | getSystemModule(final String factoryInterface)
Must be private so that user code can't call this entry point. |
pack-priv long | |
private Cacheable | Returns: aCacheable object that the caller can reusethe identity of the object being inserted key, CacheEntry the entry that is being inserted entry)Insert a |
public void | registerMBean(String
the unique name of the database to which the cache belongs dbName)Implements org. Register an MBean that allows user to monitor this cache instance. |
public void | release(Cacheable
a item)Cacheable valueImplements org. find() , findCached() or create() .
|
public void | remove(Cacheable
the object to remove from the cache item)Implements org. |
private void | |
pack-priv void | |
private void | settingIdentityComplete(Object
the identity of the object being inserted key, CacheEntry the entry which is going to hold the cached object entry, Cacheable a item)Cacheable object with the identity set (if
the identity was successfully set), or null if setting the
identity failedComplete the setting of the identity. |
public void | shutdown()
Implements org. |
public void | useDaemonService(DaemonService
the daemon service to use daemon)Implements org. |
public Collection | Returns: a collection view of the objects in the cacheImplements org. Cacheable s in the
cache.
|
cache | back to summary |
---|---|
private final ConcurrentHashMap<Object, CacheEntry> cache Map with all the cached objects. |
cleaner | back to summary |
---|---|
private BackgroundCleaner cleaner Background cleaner which can be used to clean cached objects in a separate thread to avoid blocking the user threads. |
collectAccessCounts | back to summary |
---|---|
private volatile boolean collectAccessCounts Flag that tells if hit/miss/eviction counts should be collected. |
evictions | back to summary |
---|---|
private final AtomicLong evictions The number of evictions from the cache. |
hits | back to summary |
---|---|
private final AtomicLong hits The number of cache hits. |
holderFactory | back to summary |
---|---|
private final CacheableFactory holderFactory Factory which creates |
maxSize | back to summary |
---|---|
private final int maxSize The maximum size (number of elements) for this cache. |
mbean | back to summary |
---|---|
private Object mbean The identifier of the MBean that allows monitoring of this instance. |
misses | back to summary |
---|---|
private final AtomicLong misses The number of cache misses. |
name | back to summary |
---|---|
private final String name Name of this cache. |
replacementPolicy | back to summary |
---|---|
private final ReplacementPolicy replacementPolicy Replacement policy to be used for this cache. |
stopped | back to summary |
---|---|
private volatile boolean stopped Flag that indicates whether this cache instance has been shut down. When
it has been stopped, |
ConcurrentCache | back to summary |
---|---|
pack-priv ConcurrentCache(CacheableFactory holderFactory, String name, int initialSize, int maxSize) Creates a new cache manager.
|
ageOut | back to summary |
---|---|
public void ageOut() Implements org. Remove all objects that are not kept and not dirty. |
clean | back to summary |
---|---|
public void clean(Matchable partialKey) throws StandardException Implements org. Clean all dirty objects matching a partial key.
|
cleanAll | back to summary |
---|---|
public void cleanAll() throws StandardException Implements org. Clean all dirty objects in the cache. All objects that existed in the cache at the time of the call will be cleaned. Objects added later may or may not be cleaned.
|
cleanAndUnkeepEntry | back to summary |
---|---|
pack-priv void cleanAndUnkeepEntry(CacheEntry entry, Cacheable item) throws StandardException Clean an entry in the cache and decrement its keep count. The entry must
be kept before this method is called, and it must contain the specified
|
cleanCache | back to summary |
---|---|
private void cleanCache(Matchable partialKey) throws StandardException Clean all dirty objects matching a partial key. If no key is specified, clean all dirty objects in the cache.
|
cleanEntry | back to summary |
---|---|
pack-priv void cleanEntry(CacheEntry entry) throws StandardException Clean an entry in the cache.
|
countEviction | back to summary |
---|---|
private void countEviction() Count an eviction from the cache. |
countHit | back to summary |
---|---|
private void countHit() Count a cache hit. |
countMiss | back to summary |
---|---|
private void countMiss() Count a cache miss. |
create | back to summary |
---|---|
public Cacheable create(Object key, Object createParameter) throws StandardException Implements org. Create an object in the cache. The object is kept until
|
deregisterMBean | back to summary |
---|---|
public void deregisterMBean() Implements org. Doc from org. Deregister the MBean that monitors this cache. If there is no MBean for this instance, this is a no-op.
|
discard | back to summary |
---|---|
public boolean discard(Matchable partialKey) Implements org. Discard all unused objects that match a partial key. Dirty objects will not be cleaned before their removal.
|
evictEntry | back to summary |
---|---|
pack-priv void evictEntry(Object key) Evict an entry to make room for a new entry that is being inserted into
the cache. Clear the identity of its The caller must have locked the entry that is about to be evicted.
|
find | back to summary |
---|---|
public Cacheable find(Object key) throws StandardException Implements org. Find an object in the cache. If it is not present, add it to the
cache. The returned object is kept until
|
findCached | back to summary |
---|---|
public Cacheable findCached(Object key) throws StandardException Implements org. Find an object in the cache. If it is not present, return
|
getAllocatedEntries | back to summary |
---|---|
pack-priv long getAllocatedEntries() Get the number of allocated entries in the cache. |
getBackgroundCleaner | back to summary |
---|---|
pack-priv BackgroundCleaner getBackgroundCleaner() |
getCollectAccessCounts | back to summary |
---|---|
pack-priv boolean getCollectAccessCounts() Check if collection of hit/miss/eviction counts is enabled. |
getEntry | back to summary |
---|---|
private CacheEntry getEntry(Object key) Get the entry associated with the specified key from the cache. If the entry does not exist, insert an empty one and return it. The returned entry is always locked for exclusive access by the current thread, but not kept. If another thread is currently setting the identity of this entry, this method will block until the identity has been set.
|
getEvictionCount | back to summary |
---|---|
pack-priv long getEvictionCount() Get the number of evictions from the cache. |
getHitCount | back to summary |
---|---|
pack-priv long getHitCount() Get the number of cache hits. |
getMaxEntries | back to summary |
---|---|
pack-priv long getMaxEntries() Get the maximum number of entries in the cache. |
getMissCount | back to summary |
---|---|
pack-priv long getMissCount() Get the number of cache misses. |
getReplacementPolicy | back to summary |
---|---|
pack-priv ReplacementPolicy getReplacementPolicy() Return the
|
getSystemModule | back to summary |
---|---|
private static Object getSystemModule(final String factoryInterface) Must be private so that user code can't call this entry point. |
getUsedEntries | back to summary |
---|---|
pack-priv long getUsedEntries() Get the number of cached objects. |
insertIntoFreeSlot | back to summary |
---|---|
private Cacheable insertIntoFreeSlot(Object key, CacheEntry entry) throws StandardException Insert a
|
registerMBean | back to summary |
---|---|
public void registerMBean(String dbName) throws StandardException Implements org. Doc from org. Register an MBean that allows user to monitor this cache instance. This is a no-op if the platform does not support Java Management Extensions (JMX).
The MBean will be automatically deregistered when
|
release | back to summary |
---|---|
public void release(Cacheable item) Implements org. Release an object that has been fetched from the cache with
|
remove | back to summary |
---|---|
public void remove(Cacheable item) throws StandardException Implements org. Remove an object from the cache. The object must previously have been
fetched from the cache with
|
removeEntry | back to summary |
---|---|
private void removeEntry(Object key) Remove an entry from the cache. Its
|
setCollectAccessCounts | back to summary |
---|---|
pack-priv void setCollectAccessCounts(boolean collect) Enable or disable collection of hit/miss/eviction counts. |
settingIdentityComplete | back to summary |
---|---|
private void settingIdentityComplete(Object key, CacheEntry entry, Cacheable item) Complete the setting of the identity. This includes notifying the threads that are waiting for the setting of the identity to complete, so that they can wake up and continue. If setting the identity failed, the entry will be removed from the cache.
|
shutdown | back to summary |
---|---|
public void shutdown() throws StandardException Implements org. Shut down the cache.
|
useDaemonService | back to summary |
---|---|
public void useDaemonService(DaemonService daemon) Implements org. Specify a daemon service that can be used to perform operations in the background. Callers must provide enough synchronization so that they have exclusive access to the cache when this method is called.
|
values | back to summary |
---|---|
public Collection Implements org. Return a collection view of all the
|