public final class BoundedLibraryObjectCache extends LibraryObjectCache
Cached LibraryObjects provide an addition feature in iFS: they represent the set of objects on which the session has implicit registration for iFS events. Because of this, the objects that are candidates for removal from the cache (due to not being recently used) must be "slowly" removed from the cache. This is accomplished by demoting a cache entry from being a "hard reference" to a "soft reference", and making use of the java.lang.ref.SoftReference class to determine when it is safe to completely remove the cache entry from the cache.
Note: this class requires JRE 1.2.2 or higher.
Modifier and Type | Field and Description |
---|---|
protected int |
m_AccessSequence
The access sequence.
|
protected int |
m_Capacity
Target max cache capacity; also used as initial Capacity
in HashMap constructor.
|
protected int |
m_DemoteCount
The number of cache entry demotions.
|
protected int |
m_EmergencyCapacityTrigger
capacity at which an "emergency" purge is performed.
|
protected boolean |
m_EmergencyPurgeRequested
Emergency cache purge requested.
|
protected int |
m_HardReferenceCount
The current hard-reference cache count.
|
protected int |
m_HitCount
The number of cache hits.
|
protected HashMap |
m_Items
The cache items.
|
protected int |
m_LockCount
The number of locked cache puts.
|
protected int |
m_MissCount
The number of cache misses.
|
protected int |
m_NormalCapacityTrigger
capacity at which a "normal" purge is posted.
|
protected boolean |
m_NormalPurgeRequested
Normal cache purge requested.
|
protected int |
m_PromoteCount
The number of cache entry promotions.
|
protected int |
m_PurgeCount
The number of cache removes.
|
protected int |
m_PurgeCycleCount
Total number of purge cycles performed
|
protected long |
m_PurgeCycleTime
Total elapsed time (in ms) of the purge cycles performed.
|
protected boolean |
m_PurgeInProgress
Cache purge in progress.
|
protected int |
m_PurgeTarget
Number of items desired in the cache after a purge operation.
|
protected int |
m_PutCount
The number of cache puts.
|
protected ReferenceQueue |
m_ReferenceQueue
The SoftReference queue
|
protected int |
m_RemoveCount
The number of cache removes.
|
protected int |
m_SequenceAtPreviousPurge
Cache purge in progress.
|
protected S_LibrarySession |
m_Session
The server-side session using this cache
|
protected int |
m_UrgentCapacityTrigger
capacity at which an "urgent" purge is posted.
|
protected boolean |
m_UrgentPurgeRequested
Urgent cache purge requested.
|
protected static int |
MAX_SEQUENCE
The maximum access sequence
|
protected static IfsLogger |
s_Logger
This logger instance specific to this class.
|
protected static int |
SEQUENCE_NORMALIZATION_FACTOR
The normalization factor to be used in case the access sequence
wraps past MAX_SEQUENCE.
|
m_Configuration
Constructor and Description |
---|
BoundedLibraryObjectCache(BoundedCacheConfiguration configuration,
S_LibrarySession session)
Construct a BoundedLibraryObjectCache
|
Modifier and Type | Method and Description |
---|---|
void |
dispose()
Disposes this cache.
|
protected void |
entryDemoted() |
protected void |
entryPromoted() |
Object |
find(Object id)
Gets an item from this cache.
|
LibraryObject |
findLibraryObject(Object itemKey,
LibrarySession session)
Gets an item from this cache.
|
S_LibraryObject |
findSLibraryObject(Object itemKey)
Gets an item from this cache.
|
CachePerformance |
getCachePerformance()
Gets the performance information for this cache.
|
Enumeration |
getElements()
Gets an Enumeration of the S_LibraryObjects in this cache.
|
protected HashMap |
getItemsHashMap()
Return cache item map, or null if it has been disposed
|
protected HashMap |
getItemsHashMap(boolean required)
Return cache item map, or throw if we are disposed
|
Enumeration |
getLibraryObjectEnumeration()
Gets an Enumeration of the LibraryObjects in this cache.
|
protected int |
getNextSequence()
Return next access sequence
|
Enumeration |
getSLibraryObjectEnumeration()
Gets an Enumeration of the S_LibraryObjects in this cache.
|
boolean |
isTraced(int channel,
int level)
Gets whether tracing is enabled for the specified channel and level.
|
void |
lock(Object itemKey,
Object value)
Locks an item in this cache.
|
void |
markEntriesAsUntrusted()
Mark all PO entries as untrusted.
|
void |
markEntryAsUntrusted(Object itemKey)
Mark an entry as untrusted.
|
void |
markFreeCancelled(Long id)
Respond to a rolledback FREE event.
|
void |
markFreeInitiated(Long id)
Removes an item from this cache, and mark it pending until the
current transaction is committed.
|
void |
performNormalPurgeIfNeeded()
Purge Cache if a request for "normal" purge is indicated
|
void |
performUrgentPurgeIfNeeded()
Purge Cache if a request for "urgent" purge is indicated
|
void |
purgeEntry(Long id)
Purges an item from this cache.
|
void |
put(Object itemKey,
Object value)
Puts an item in this cache.
|
void |
putLibraryObject(Object itemKey,
LibraryObject value)
Puts an item in this cache.
|
void |
remove(Object itemKey)
Removes an item from this cache, in reaction to a committed FREE
event, or a rolledbcak CREATE event.
|
void |
removeLibraryObject(Object itemKey)
Removes an item from this cache.
|
void |
reset()
Resets this cache.
|
void |
resetCachePerformance()
Resets the performance information for this cache.
|
void |
setCacheConfiguration(CacheConfiguration configuration)
Alters the configuration of this cache.
|
protected void |
setItemsHashMap(int size)
Initializes the cache item map,
|
void |
trace(int channel,
int level,
String payload)
Issues a trace request to the trace logger.
|
getCacheConfiguration
protected static int MAX_SEQUENCE
protected static int SEQUENCE_NORMALIZATION_FACTOR
protected S_LibrarySession m_Session
protected HashMap m_Items
protected ReferenceQueue m_ReferenceQueue
protected int m_Capacity
protected int m_NormalCapacityTrigger
protected int m_UrgentCapacityTrigger
protected int m_EmergencyCapacityTrigger
protected int m_PurgeTarget
protected int m_AccessSequence
protected int m_HardReferenceCount
protected int m_SequenceAtPreviousPurge
protected int m_PurgeCycleCount
protected long m_PurgeCycleTime
protected boolean m_PurgeInProgress
protected boolean m_NormalPurgeRequested
protected boolean m_UrgentPurgeRequested
protected boolean m_EmergencyPurgeRequested
protected int m_HitCount
protected int m_MissCount
protected int m_PutCount
protected int m_LockCount
protected int m_RemoveCount
protected int m_PurgeCount
protected int m_DemoteCount
protected int m_PromoteCount
protected static IfsLogger s_Logger
public BoundedLibraryObjectCache(BoundedCacheConfiguration configuration, S_LibrarySession session)
configuration
- the configuration paramaters for the new cachepublic void reset()
This causes the cache to be emptied and its performance information to be reset. This is invoked as part of construction, providing initialization.
public final void setCacheConfiguration(CacheConfiguration configuration) throws IfsException
The following cache configuration parameters can be changed using this method:
All other cache configuration parameters specified in the CacheConfiguration are ignored.
setCacheConfiguration
in class Cache
configuration
- the configuration parameters; must be a
BoundedCacheConfigurationIfsException
- (IFS-10810) if the operation failspublic final Object find(Object id) throws IfsException
find
in class Cache
id
- the item idIfsException
- if the operation failspublic final void remove(Object itemKey) throws IfsException
remove
in class Cache
itemKey
- the item idIfsException
- if the operation failspublic final void markFreeInitiated(Long id) throws IfsException
markFreeInitiated
in class LibraryObjectCache
id
- the item IDIfsException
- if the operation failspublic void markFreeCancelled(Long id) throws IfsException
markFreeCancelled
in class LibraryObjectCache
id
- the item IDIfsException
- if the operation failspublic final void put(Object itemKey, Object value) throws IfsException
put
in class Cache
itemKey
- the item idvalue
- the itemIfsException
- if the operation failspublic final void lock(Object itemKey, Object value) throws IfsException
lock
in class BoundedCache
itemKey
- the item idvalue
- the itemIfsException
- if the operation failspublic final S_LibraryObject findSLibraryObject(Object itemKey) throws IfsException
itemKey
- the item idIfsException
- if the operation failspublic final void purgeEntry(Long id)
id
- the item idpublic final LibraryObject findLibraryObject(Object itemKey, LibrarySession session) throws IfsException
itemKey
- the item idsession
- the bean-side sessionIfsException
- if the operation failspublic final void removeLibraryObject(Object itemKey) throws IfsException
itemKey
- the item idIfsException
- if the operation failspublic final void putLibraryObject(Object itemKey, LibraryObject value) throws IfsException
itemKey
- the item idvalue
- the itemIfsException
- if the operation failspublic void markEntriesAsUntrusted() throws IfsException
markEntriesAsUntrusted
in class LibraryObjectCache
IfsException
- if the operation failspublic void markEntryAsUntrusted(Object itemKey) throws IfsException
Called by S_LibrarySession when a special event is posted.
markEntryAsUntrusted
in class LibraryObjectCache
itemKey
- the ID of the entry to not be trustedIfsException
- if the operation failsprotected void entryPromoted()
protected void entryDemoted()
public final void performNormalPurgeIfNeeded()
performNormalPurgeIfNeeded
in class BoundedCache
public final void performUrgentPurgeIfNeeded()
performUrgentPurgeIfNeeded
in class BoundedCache
public Enumeration getElements() throws IfsException
getElements
in class Cache
IfsException
- if operation failspublic Enumeration getSLibraryObjectEnumeration() throws IfsException
IfsException
- if operation failspublic Enumeration getLibraryObjectEnumeration() throws IfsException
IfsException
- if operation failsprotected final int getNextSequence()
public final CachePerformance getCachePerformance()
getCachePerformance
in class Cache
public final void resetCachePerformance()
resetCachePerformance
in class Cache
public void dispose()
After the cache is disposed, it is invalid to use this cache.
public final boolean isTraced(int channel, int level)
channel
- the channel numberlevel
- the levelpublic final void trace(int channel, int level, String payload)
channel
- the channel numberlevel
- the levelpayload
- a string containing any additional information to
be placed in the trace logprotected HashMap getItemsHashMap()
protected HashMap getItemsHashMap(boolean required) throws IfsException
required
- whether the returned map must not be nullIfsException
- (IFS-21000) if required is true, and the map is nullprotected void setItemsHashMap(int size)
size
- the initial cache sizeCopyright © 2023. All rights reserved.