/** * {@inheritDoc} */ public void write(Element element) { queueWriteLock.lock(); try { waitForQueueSizeToDrop(); if (stopping || stopped) { throw new CacheException("The element '" + element + "' couldn't be added through the write-behind queue for cache '" + cacheName + "' since it's not started."); } addItem(new WriteOperation(element)); if (getQueueSize() + 1 < maxQueueSize) { queueIsFull.signal(); } queueIsEmpty.signal(); } finally { queueWriteLock.unlock(); } }
if (getQueueSize() > 0) { quarantined = quarantineItems(); } else { quarantined = null; LOGGER.finer(getThreadName() + " : processItems() : nothing to process"); filterQuarantined(quarantined); waitUntilEnoughWorkItemsAvailable(quarantined, workSize); return; final long secondsSinceLastWorkDone = (System.currentTimeMillis() - lastWorkDone.get()) / MS_IN_SEC; final long maxBatchSizeSinceLastWorkDone = rateLimitPerSecond * secondsSinceLastWorkDone; final int batchSize = determineBatchSize(quarantined); if (batchSize > maxBatchSizeSinceLastWorkDone) { waitUntilEnoughTimeHasPassed(quarantined, batchSize, secondsSinceLastWorkDone); return; LOGGER.finer(getThreadName() + " : processItems() : processing started"); processQuarantinedItems(quarantined); } catch (final RuntimeException e) { reassemble(quarantined); throw e; } catch (final Error e) { reassemble(quarantined); throw 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); } }
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(); } } } }
private void processBatchedOperations(List<SingleOperation> quarantined) { final int batchSize = determineBatchSize(quarantined); LOGGER.config(getThreadName() + " : processItems() : adding " + item + " to next batch"); reassemble(quarantined);
private void processBatchedOperations(List<SingleOperation> quarantined) { final int batchSize = determineBatchSize(quarantined); List<List<? extends SingleOperation>> batches = createMonomorphicBatches(quarantined.subList(0, batchSize)); reassemble(quarantined);
LOGGER.config(getThreadName() + " : processItems() : processing " + item);
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); }
while (!stopping && getQueueSize() == 0) { queueIsEmpty.await(); stop(); Thread.currentThread().interrupt(); if (stopping && getQueueSize() == 0) { stopTheQueueThread();
private void processBatchedOperations(List<SingleOperation> quarantined) { final int batchSize = determineBatchSize(quarantined); LOGGER.config(getThreadName() + " : processItems() : adding " + item + " to next batch"); reassemble(quarantined);
private void processBatchedOperations(List<SingleOperation> quarantined) { final int batchSize = determineBatchSize(quarantined); List<List<? extends SingleOperation>> batches = createMonomorphicBatches(quarantined.subList(0, batchSize)); reassemble(quarantined);
LOGGER.config(getThreadName() + " : processItems() : adding " + item + " to next batch");
if (getQueueSize() > 0) { quarantined = quarantineItems(); } else { quarantined = null; LOGGER.finer(getThreadName() + " : processItems() : nothing to process"); filterQuarantined(quarantined); waitUntilEnoughWorkItemsAvailable(quarantined, workSize); return; final long secondsSinceLastWorkDone = (System.currentTimeMillis() - lastWorkDone.get()) / MS_IN_SEC; final long maxBatchSizeSinceLastWorkDone = rateLimitPerSecond * secondsSinceLastWorkDone; final int batchSize = determineBatchSize(quarantined); if (batchSize > maxBatchSizeSinceLastWorkDone) { waitUntilEnoughTimeHasPassed(quarantined, batchSize, secondsSinceLastWorkDone); return; LOGGER.finer(getThreadName() + " : processItems() : processing started"); processQuarantinedItems(quarantined); } catch (final RuntimeException e) { reassemble(quarantined); throw e; } catch (final Error e) { reassemble(quarantined); throw e;
/** * {@inheritDoc} */ public void delete(CacheEntry entry) { queueWriteLock.lock(); try { waitForQueueSizeToDrop(); if (stopping || stopped) { throw new CacheException("The entry for key '" + entry.getKey() + "' couldn't be deleted through the write-behind " + "queue for cache '" + cacheName + "' since it's not started."); } addItem(new DeleteOperation(entry)); if (getQueueSize() + 1 < maxQueueSize) { queueIsFull.signal(); } queueIsEmpty.signal(); } finally { queueWriteLock.unlock(); } }
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); } }
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(); } } } }
LOGGER.config(getThreadName() + " : processItems() : processing " + item);
if (getQueueSize() > 0) { quarantined = quarantineItems(); } else { quarantined = null; LOGGER.finer(getThreadName() + " : processItems() : nothing to process"); filterQuarantined(quarantined); waitUntilEnoughWorkItemsAvailable(quarantined, workSize); return; final long secondsSinceLastWorkDone = (System.currentTimeMillis() - lastWorkDone.get()) / MS_IN_SEC; final long maxBatchSizeSinceLastWorkDone = rateLimitPerSecond * secondsSinceLastWorkDone; final int batchSize = determineBatchSize(quarantined); if (batchSize > maxBatchSizeSinceLastWorkDone) { waitUntilEnoughTimeHasPassed(quarantined, batchSize, secondsSinceLastWorkDone); return; LOGGER.finer(getThreadName() + " : processItems() : processing started"); processQuarantinedItems(quarantined); } catch (final RuntimeException e) { reassemble(quarantined); throw e; } catch (final Error e) { reassemble(quarantined); throw e;