Top Description Fields Constructors Methods
org.apache.derby.impl.services.cache

pack-priv final Class BackgroundCleaner

extends Object
implements Serviceable
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.services.daemon.Serviceable
Imports
java.util.concurrent.ArrayBlockingQueue, java.util.concurrent.atomic.AtomicBoolean, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.iapi.services.daemon.DaemonService, .Serviceable

A background cleaner that 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.

Field Summary

Modifier and TypeField and Description
private final ConcurrentCache
cacheManager

The cache manager owning this cleaner.

private final int
clientNumber

Subscription number for this Serviceable.

private final DaemonService
daemonService

The service thread which performs the clean operations.

private final ArrayBlockingQueue<CacheEntry>
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.

Constructor Summary

AccessConstructor 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.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

status for the performed work (normally Serviceable.DONE)
performWork
(ContextManager
ignored
context
)

Implements org.apache.derby.iapi.services.daemon.Serviceable.performWork.

Clean the first entry in the queue.

private void
requestService()

Notify the daemon service that the cleaner needs to be serviced.

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)
scheduleClean
(CacheEntry
the entry that needs to be cleaned
entry
)

Try to schedule a clean operation in the background cleaner.

pack-priv void
scheduleShrink()

Request that the cleaner tries to shrink the cache the next time it wakes up.

public boolean

Returns:

true
serviceASAP
()

Implements org.apache.derby.iapi.services.daemon.Serviceable.serviceASAP.

Indicate that we want to be serviced ASAP.

public boolean

Returns:

false
serviceImmediately
()

Implements org.apache.derby.iapi.services.daemon.Serviceable.serviceImmediately.

Indicate that we don't want the work to happen immediately in the user thread.

pack-priv void
unsubscribe()

Stop subscribing to the daemon service.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheManagerback to summary
private final ConcurrentCache cacheManager

The cache manager owning this cleaner.

clientNumberback to summary
private final int clientNumber

Subscription number for this Serviceable.

daemonServiceback to summary
private final DaemonService daemonService

The service thread which performs the clean operations.

queueback to summary
private final ArrayBlockingQueue<CacheEntry> queue

A queue of cache entries that need to be cleaned.

scheduledback 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 true, calls to serviceNow() won't result in the cleaner being serviced.

shrinkback to summary
private volatile boolean shrink

Flag which tells whether the cleaner should try to shrink the cache the next time it wakes up.

Constructor Detail

BackgroundCleanerback to summary
pack-priv BackgroundCleaner(ConcurrentCache cache, DaemonService daemon, int queueSize)

Create a background cleaner instance and subscribe it to a daemon service.

Parameters
cache:ConcurrentCache

the cache manager that owns the cleaner

daemon:DaemonService

the daemon service which perfoms the work

queueSize:int

the maximum number of entries to keep in the queue (must be greater than 0)

Method Detail

performWorkback to summary
public int performWork(ContextManager context) throws StandardException

Implements org.apache.derby.iapi.services.daemon.Serviceable.performWork.

Clean the first entry in the queue. If there is more work, re-request service from the daemon service.

Parameters
context:ContextManager

ignored

Returns:int

status for the performed work (normally Serviceable.DONE)

Exceptions
StandardException:
if Cacheable.clean() fails
requestServiceback to summary
private void requestService()

Notify the daemon service that the cleaner needs to be serviced.

scheduleCleanback to summary
pack-priv boolean scheduleClean(CacheEntry entry)

Try to schedule a clean operation in the background cleaner.

Parameters
entry:CacheEntry

the entry that needs to be cleaned

Returns:boolean

true if the entry has been scheduled for clean, false if the background cleaner can't clean the entry (its queue is full)

scheduleShrinkback to summary
pack-priv void scheduleShrink()

Request that the cleaner tries to shrink the cache the next time it wakes up.

serviceASAPback to summary
public boolean serviceASAP()

Implements org.apache.derby.iapi.services.daemon.Serviceable.serviceASAP.

Indicate that we want to be serviced ASAP.

Returns:boolean

true

serviceImmediatelyback to summary
public boolean serviceImmediately()

Implements org.apache.derby.iapi.services.daemon.Serviceable.serviceImmediately.

Indicate that we don't want the work to happen immediately in the user thread.

Returns:boolean

false

unsubscribeback to summary
pack-priv void unsubscribe()

Stop subscribing to the daemon service.