private void filterQuarantined(List<SingleOperation> quarantined) { OperationsFilter operationsFilter = this.filter; if (operationsFilter != null) { operationsFilter.filter(quarantined, CastingOperationConverter.getInstance()); } }
/** * {@inheritDoc} */ public void dispose() { /* If WriteBehind is configured but no writer is registered, writeBehind will be null */ if (writeBehind != null) { writeBehind.stop(); } }
@Override public void filter(final List<SingleAsyncOperation> items) { delegate.filter(items, new OperationConverter<KeyBasedOperation>() { public KeyBasedOperation convert(Object source) { SingleAsyncOperation operation = (SingleAsyncOperation) source; try { return new KeyBasedOperationWrapper(operation.getKey(), operation.getCreationTime()); } catch (Exception e) { throw new CacheException(e); } } }); }
private void processQuarantinedItems(List<SingleOperation> quarantined) { if (LOGGER.isLoggable(Level.CONFIG)) { LOGGER.config(getThreadName() + " : processItems() : processing " + quarantined.size() + " quarantined items"); } if (writeBatching && writeBatchSize > 0) { processBatchedOperations(quarantined); } else { processSingleOperation(quarantined); } }
/** * {@inheritDoc} */ public void init(Cache cache) throws CacheException { CacheWriter cacheWriter = cache.getRegisteredCacheWriter(); if (null == cacheWriter) { throw new CacheException("No cache writer was registered for cache " + cache.getName()); } if (cache.getCacheConfiguration().getCacheWriterConfiguration().getWriteCoalescing()) { writeBehind.setOperationsFilter(new CoalesceKeysFilter()); } writeBehind.start(cacheWriter); }
private void waitUntilEnoughTimeHasPassed(List<SingleOperation> quarantined, int batchSize, long secondsSinceLastWorkDone) { if (LOGGER.isLoggable(Level.FINER)) { LOGGER.finer(getThreadName() + " : processItems() : last work was done " + secondsSinceLastWorkDone + " seconds ago, processing " + batchSize + " batch items would exceed the rate limit of " + rateLimitPerSecond + ", waiting for a while."); } reassemble(quarantined); }
private void waitForQueueSizeToDrop() { if (maxQueueSize > 0) { while (getQueueSize() >= maxQueueSize) { try { queueIsFull.await(); } catch (InterruptedException e) { stop(); Thread.currentThread().interrupt(); } } } }
/** * {@inheritDoc} */ public long getQueueSize() { int size = 0; readLock.lock(); try { for (WriteBehind queue : queues) { size += queue.getQueueSize(); } } finally { readLock.unlock(); } return size; }
/** * Create a new write behind queue manager. Which in turn will create as many queues as * required by the {@link net.sf.ehcache.config.CacheWriterConfiguration#getWriteBehindConcurrency} * * @param config the configuration for the queue */ public WriteBehindQueueManager(CacheConfiguration config) { this(config, new WriteBehindQueueFactory()); }
/** * {@inheritDoc} */ @Override public CacheWriterManager createWriterManager(Cache cache, Store store) { return new WriteBehindManager(cache, store); } };
/** * Create a write behind queue stripe. * * @param index index of the stripe * @param config cache configuration for the cache this queue will be associated with. * @return a write behind queue */ protected WriteBehind createQueue(int index, CacheConfiguration config) { return new WriteBehindQueue(config); } }
/** * {@inheritDoc} */ public void put(Element element) throws CacheException { writeBehind.write(element); }
/** * {@inheritDoc} */ public void remove(CacheEntry entry) throws CacheException { writeBehind.delete(entry); }
/** * {@inheritDoc} */ public void start(final CacheWriter writer) throws CacheException { writeLock.lock(); try { for (WriteBehind queue : queues) { queue.start(writer); } } finally { writeLock.unlock(); } }
/** * {@inheritDoc} */ public void setOperationsFilter(final OperationsFilter filter) { readLock.lock(); try { for (WriteBehind queue : queues) { queue.setOperationsFilter(filter); } } finally { readLock.unlock(); } }
private void waitUntilEnoughWorkItemsAvailable(List<SingleOperation> quarantined, int workSize) { if (LOGGER.isLoggable(Level.FINER)) { LOGGER.finer(getThreadName() + " : processItems() : only " + workSize + " work items available, waiting for " + writeBatchSize + " items to fill up a batch"); } reassemble(quarantined); }
/** * {@inheritDoc} */ public void stop() throws CacheException { writeLock.lock(); try { for (WriteBehind queue : queues) { queue.stop(); } } finally { writeLock.unlock(); } }
/** * Gets the best estimate for items in the queue still awaiting processing. * Not including elements currently processed * * @return the amount of elements still awaiting processing. */ @Statistic(name = "queue-length", tags = "write-behind") public long getQueueSize() { return writeBehind.getQueueSize(); } }