|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.derby.impl.services.cache.BackgroundCleaner
final class BackgroundCleaner
A background cleaner that ConcurrentCache
can use to clean Cacheable
s asynchronously in a background instead of synchronously in the
user threads. It is normally used by the replacement algorithm in order to
make dirty Cacheable
s 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.
Field Summary | |
---|---|
private ConcurrentCache |
cacheManager
The cache manager owning this cleaner. |
private int |
clientNumber
Subscription number for this Serviceable . |
private DaemonService |
daemonService
The service thread which performs the clean operations. |
private java.util.concurrent.ArrayBlockingQueue<CacheEntry> |
queue
A queue of cache entries that need to be cleaned. |
private java.util.concurrent.atomic.AtomicBoolean |
scheduled
Flag which tells whether the cleaner has a still unprocessed job scheduled with the daemon service. |
private boolean |
shrink
Flag which tells whether the cleaner should try to shrink the cache the next time it wakes up. |
Fields inherited from interface org.apache.derby.iapi.services.daemon.Serviceable |
---|
DONE, REQUEUE |
Constructor Summary | |
---|---|
BackgroundCleaner(ConcurrentCache cache,
DaemonService daemon,
int queueSize)
Create a background cleaner instance and subscribe it to a daemon service. |
Method Summary | |
---|---|
int |
performWork(ContextManager context)
Clean the first entry in the queue. |
private void |
requestService()
Notify the daemon service that the cleaner needs to be serviced. |
(package private) boolean |
scheduleClean(CacheEntry entry)
Try to schedule a clean operation in the background cleaner. |
(package private) void |
scheduleShrink()
Request that the cleaner tries to shrink the cache the next time it wakes up. |
boolean |
serviceASAP()
Indicate that we want to be serviced ASAP. |
boolean |
serviceImmediately()
Indicate that we don't want the work to happen immediately in the user thread. |
(package private) void |
unsubscribe()
Stop subscribing to the daemon service. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final DaemonService daemonService
private final int clientNumber
Serviceable
.
private final java.util.concurrent.atomic.AtomicBoolean scheduled
true
,
calls to serviceNow()
won't result in the cleaner being
serviced.
private final java.util.concurrent.ArrayBlockingQueue<CacheEntry> queue
private volatile boolean shrink
private final ConcurrentCache cacheManager
Constructor Detail |
---|
BackgroundCleaner(ConcurrentCache cache, DaemonService daemon, int queueSize)
cache
- the cache manager that owns the cleanerdaemon
- the daemon service which perfoms the workqueueSize
- the maximum number of entries to keep in the queue
(must be greater than 0)Method Detail |
---|
boolean scheduleClean(CacheEntry entry)
entry
- the entry that needs to be cleaned
true
if the entry has been scheduled for clean,
false
if the background cleaner can't clean the entry (its
queue is full)void scheduleShrink()
private void requestService()
void unsubscribe()
public int performWork(ContextManager context) throws StandardException
performWork
in interface Serviceable
context
- ignored
Serviceable.DONE
)
StandardException
- if Cacheable.clean()
failspublic boolean serviceASAP()
serviceASAP
in interface Serviceable
true
public boolean serviceImmediately()
serviceImmediately
in interface Serviceable
false
|
Built on Thu 2012-03-29 21:53:33+0000, from revision ??? | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |