ConcurrentCache can use to clean Cacheables asynchronously in a background instead of synchronously in the
user threads. It is normally used by the replacement algorithm in order to
make dirty Cacheables clean and evictable in the future. When the
background cleaner is asked to clean an item, it puts the item in a queue
and requests to be serviced by a DaemonService running in a
separate thread.
| Modifier and Type | Field and Description |
|---|---|
| private final ConcurrentCache | cacheManager
The cache manager owning this cleaner. |
| private final int | clientNumber
Subscription number for this |
| private final DaemonService | daemonService
The service thread which performs the clean operations. |
| private final ArrayBlockingQueue | queue
A queue of cache entries that need to be cleaned. |
| private final AtomicBoolean | scheduled
Flag which tells whether the cleaner has a still unprocessed job scheduled with the daemon service. |
| private volatile boolean | shrink
Flag which tells whether the cleaner should try to shrink the cache the next time it wakes up. |
| Access | Constructor and Description |
|---|---|
| pack-priv | BackgroundCleaner(ConcurrentCache
the cache manager that owns the cleaner cache, DaemonService the daemon service which perfoms the work daemon, int the maximum number of entries to keep in the queue
(must be greater than 0) queueSize)Create a background cleaner instance and subscribe it to a daemon service. |
| Modifier and Type | Method and Description |
|---|---|
| public int | Returns: status for the performed work (normallyServiceable.DONE)ignored context)Implements org. Clean the first entry in the queue. |
| private void | |
| pack-priv boolean | Returns: true if the entry has been scheduled for clean,
false if the background cleaner can't clean the entry (its
queue is full)the entry that needs to be cleaned entry)Try to schedule a clean operation in the background cleaner. |
| pack-priv void | |
| public boolean | Returns: trueImplements org. Indicate that we want to be serviced ASAP. |
| public boolean | Returns: falseImplements org. Indicate that we don't want the work to happen immediately in the user thread. |
| pack-priv void |
| cacheManager | back to summary |
|---|---|
| private final ConcurrentCache cacheManager The cache manager owning this cleaner. | |
| clientNumber | back to summary |
|---|---|
| private final int clientNumber Subscription number for this | |
| daemonService | back to summary |
|---|---|
| private final DaemonService daemonService The service thread which performs the clean operations. | |
| queue | back to summary |
|---|---|
| private final ArrayBlockingQueue<CacheEntry> queue A queue of cache entries that need to be cleaned. | |
| scheduled | back to summary |
|---|---|
| private final AtomicBoolean scheduled Flag which tells whether the cleaner has a still unprocessed job
scheduled with the daemon service. If this flag is | |
| shrink | back to summary |
|---|---|
| private volatile boolean shrink Flag which tells whether the cleaner should try to shrink the cache the next time it wakes up. | |
| BackgroundCleaner | back to summary |
|---|---|
| pack-priv BackgroundCleaner(ConcurrentCache cache, DaemonService daemon, int queueSize) Create a background cleaner instance and subscribe it to a daemon service.
| |
| performWork | back to summary |
|---|---|
| public int performWork(ContextManager context) throws StandardException Implements org. Clean the first entry in the queue. If there is more work, re-request service from the daemon service.
| |
| requestService | back to summary |
|---|---|
| private void requestService() Notify the daemon service that the cleaner needs to be serviced. | |
| scheduleClean | back to summary |
|---|---|
| pack-priv boolean scheduleClean(CacheEntry entry) Try to schedule a clean operation in the background cleaner.
| |
| scheduleShrink | back to summary |
|---|---|
| pack-priv void scheduleShrink() Request that the cleaner tries to shrink the cache the next time it wakes up. | |
| serviceASAP | back to summary |
|---|---|
| public boolean serviceASAP() Implements org. Indicate that we want to be serviced ASAP.
| |
| serviceImmediately | back to summary |
|---|---|
| public boolean serviceImmediately() Implements org. Indicate that we don't want the work to happen immediately in the user thread.
| |
| unsubscribe | back to summary |
|---|---|
| pack-priv void unsubscribe() Stop subscribing to the daemon service. | |