Top Description Inners Fields Constructors Methods
net.sf.ehcache.writer.writebehind

public abstract Class AbstractWriteBehindQueue

extends Object
implements WriteBehind
Class Inheritance
All Implemented Interfaces
net.sf.ehcache.writer.writebehind.WriteBehind
Known Direct Subclasses
net.sf.ehcache.writer.writebehind.WriteBehindQueue
Imports
java.util.ArrayList, .HashSet, .List, .Set, java.util.concurrent.TimeUnit, java.util.concurrent.atomic.AtomicBoolean, .AtomicLong, java.util.concurrent.locks.Condition, .ReentrantReadWriteLock, java.util.logging.Level, .Logger, net.sf.ehcache.CacheEntry, .CacheException, .Element, net.sf.ehcache.config.CacheConfiguration, .CacheWriterConfiguration, net.sf.ehcache.writer.CacheWriter, net.sf.ehcache.writer.writebehind.operations.DeleteOperation, .SingleOperation, .WriteOperation

Abstract implementation of a WriteBehindQueue.
Author
tim

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
AbstractWriteBehindQueue.ProcessingThread

Thread this will continuously process the items in the queue.

Field Summary

Modifier and TypeField and Description
private final AtomicBoolean
private final String
private CacheWriter
private volatile OperationsFilter<T>
private final AtomicLong
private final AtomicLong
private static final Logger
private final int
private final long
private final long
private static final int
private final Thread
private final Condition
private final Condition
private final Condition
private final ReentrantReadWriteLock
private final ReentrantReadWriteLock.ReadLock
private final ReentrantReadWriteLock.WriteLock
private final int
private final int
private final int
private boolean
private boolean
private final boolean
private final int

Constructor Summary

AccessConstructor and Description
public
AbstractWriteBehindQueue(CacheConfiguration
the configuration for the queue
config
)

Create a new write behind queue.

Method Summary

Modifier and TypeMethod and Description
protected abstract void
addItem(SingleOperation
operation to be done
operation
)

Add an item to the write behind queue

private List<List<? extends SingleOperation>>
public void
delete(CacheEntry
the cache entry for which a delete operation will be added to the write behind queue
entry
)

Implements net.sf.ehcache.writer.writebehind.WriteBehind.delete.

Add a delete operation for the given cache entry
private int
private void
private long
protected Thread
getProcessingThread()

Backdoor to allow killing the processing thread for testing purposes.

public abstract long

Returns:

the amount of elements still awaiting processing.
getQueueSize
()

Redeclares net.sf.ehcache.writer.writebehind.WriteBehind.getQueueSize.

Gets the best estimate for items in the queue still awaiting processing.
private String
private boolean
private void
private void
private void
private void
protected abstract List<SingleOperation>

Returns:

list of operations
quarantineItems
()

Quarantine items to be processed.

private void
protected abstract void
reinsertUnprocessedItems(List<SingleOperation>
list of unfinished operations
operations
)

Reinsert any unfinished operations into the queue.

public void
setOperationsFilter(OperationsFilter<T>
the filter that will be used as of now
filter
)

Implements net.sf.ehcache.writer.writebehind.WriteBehind.setOperationsFilter.

Set the operations filter that should be used.
public void
start(CacheWriter
the cache writer that should be used to process the operations
writer
)

Implements net.sf.ehcache.writer.writebehind.WriteBehind.start.

Start the write behind queue with a cache writer
public void
stop()

Implements net.sf.ehcache.writer.writebehind.WriteBehind.stop.

Stop the coordinator and all the internal data structures.
private void
private void
waitUntilEnoughTimeHasPassed(List<SingleOperation> quarantined, int batchSize, long secondsSinceLastWorkDone)

private void
public void
write(Element
the element for which a write operation will be added to the write behind queue
element
)

Implements net.sf.ehcache.writer.writebehind.WriteBehind.write.

Add a write operation for a given element.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

busyProcessingback to summary
private final AtomicBoolean busyProcessing
cacheNameback to summary
private final String cacheName
cacheWriterback to summary
private CacheWriter cacheWriter
filterback to summary
private volatile OperationsFilter<T> filter
lastProcessingback to summary
private final AtomicLong lastProcessing
lastWorkDoneback to summary
private final AtomicLong lastWorkDone
LOGGERback to summary
private static final Logger LOGGER
maxQueueSizeback to summary
private final int maxQueueSize
maxWriteDelayMsback to summary
private final long maxWriteDelayMs
minWriteDelayMsback to summary
private final long minWriteDelayMs
MS_IN_SECback to summary
private static final int MS_IN_SEC
processingThreadback to summary
private final Thread processingThread
queueIsEmptyback to summary
private final Condition queueIsEmpty
queueIsFullback to summary
private final Condition queueIsFull
queueIsStoppedback to summary
private final Condition queueIsStopped
queueLockback to summary
private final ReentrantReadWriteLock queueLock
queueReadLockback to summary
private final ReentrantReadWriteLock.ReadLock queueReadLock
queueWriteLockback to summary
private final ReentrantReadWriteLock.WriteLock queueWriteLock
rateLimitPerSecondback to summary
private final int rateLimitPerSecond
retryAttemptDelaySecondsback to summary
private final int retryAttemptDelaySeconds
retryAttemptsback to summary
private final int retryAttempts
stoppedback to summary
private boolean stopped
stoppingback to summary
private boolean stopping
writeBatchingback to summary
private final boolean writeBatching
writeBatchSizeback to summary
private final int writeBatchSize

Constructor Detail

AbstractWriteBehindQueueback to summary
public AbstractWriteBehindQueue(CacheConfiguration config)

Create a new write behind queue.

Parameters
config:CacheConfiguration

the configuration for the queue

Method Detail

addItemback to summary
protected abstract void addItem(SingleOperation operation)

Add an item to the write behind queue

Parameters
operation:SingleOperation

operation to be done

createMonomorphicBatchesback to summary
private List<List<? extends SingleOperation>> createMonomorphicBatches(List<SingleOperation> batch)
deleteback to summary
public void delete(CacheEntry entry)

Implements net.sf.ehcache.writer.writebehind.WriteBehind.delete.

Doc from net.sf.ehcache.writer.writebehind.WriteBehind.delete.

Add a delete operation for the given cache entry

Parameters
entry:CacheEntry

the cache entry for which a delete operation will be added to the write behind queue

determineBatchSizeback to summary
private int determineBatchSize(List<SingleOperation> quarantined)
filterQuarantinedback to summary
private void filterQuarantined(List<SingleOperation> quarantined)
getLastProcessingback to summary
private long getLastProcessing()
getProcessingThreadback to summary
protected Thread getProcessingThread()

Backdoor to allow killing the processing thread for testing purposes.

getQueueSizeback to summary
public abstract long getQueueSize()

Redeclares net.sf.ehcache.writer.writebehind.WriteBehind.getQueueSize.

Gets the best estimate for items in the queue still awaiting processing. Not including elements currently processed

Returns:long

the amount of elements still awaiting processing.

getThreadNameback to summary
private String getThreadName()
isStoppedback to summary
private boolean isStopped()
processBatchedOperationsback to summary
private void processBatchedOperations(List<SingleOperation> quarantined)
processItemsback to summary
private void processItems() throws CacheException
processQuarantinedItemsback to summary
private void processQuarantinedItems(List<SingleOperation> quarantined)
processSingleOperationback to summary
private void processSingleOperation(List<SingleOperation> quarantined)
quarantineItemsback to summary
protected abstract List<SingleOperation> quarantineItems()

Quarantine items to be processed.

Returns:List<SingleOperation>

list of operations

reassembleback to summary
private void reassemble(List<SingleOperation> quarantined)
reinsertUnprocessedItemsback to summary
protected abstract void reinsertUnprocessedItems(List<SingleOperation> operations)

Reinsert any unfinished operations into the queue.

Parameters
operations:List<SingleOperation>

list of unfinished operations

setOperationsFilterback to summary
public void setOperationsFilter(OperationsFilter<T> filter)

Implements net.sf.ehcache.writer.writebehind.WriteBehind.setOperationsFilter.

Doc from net.sf.ehcache.writer.writebehind.WriteBehind.setOperationsFilter.

Set the operations filter that should be used.

Parameters
filter:OperationsFilter<T>

the filter that will be used as of now

startback to summary
public void start(CacheWriter writer)

Implements net.sf.ehcache.writer.writebehind.WriteBehind.start.

Doc from net.sf.ehcache.writer.writebehind.WriteBehind.start.

Start the write behind queue with a cache writer

Parameters
writer:CacheWriter

the cache writer that should be used to process the operations

stopback to summary
public void stop() throws CacheException

Implements net.sf.ehcache.writer.writebehind.WriteBehind.stop.

Doc from net.sf.ehcache.writer.writebehind.WriteBehind.stop.

Stop the coordinator and all the internal data structures.

This stops as quickly as possible without losing any previously added items. However, no guarantees are made towards the processing of these items. It's highly likely that items are still inside the internal data structures and not processed.

waitForQueueSizeToDropback to summary
private void waitForQueueSizeToDrop()
waitUntilEnoughTimeHasPassedback to summary
private void waitUntilEnoughTimeHasPassed(List<SingleOperation> quarantined, int batchSize, long secondsSinceLastWorkDone)
waitUntilEnoughWorkItemsAvailableback to summary
private void waitUntilEnoughWorkItemsAvailable(List<SingleOperation> quarantined, int workSize)
writeback to summary
public void write(Element element)

Implements net.sf.ehcache.writer.writebehind.WriteBehind.write.

Doc from net.sf.ehcache.writer.writebehind.WriteBehind.write.

Add a write operation for a given element.

Parameters
element:Element

the element for which a write operation will be added to the write behind queue

net.sf.ehcache.writer.writebehind back to summary

private final Class AbstractWriteBehindQueue.ProcessingThread

extends Object
implements Runnable
Class Inheritance
  • java.lang.Object
  • net.sf.ehcache.writer.writebehind.AbstractWriteBehindQueue.ProcessingThread
All Implemented Interfaces
java.lang.Runnable

Thread this will continuously process the items in the queue.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ProcessingThreadback to summary
private ProcessingThread()

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

stopTheQueueThreadback to summary
private void stopTheQueueThread()