private void processBatchedItems() throws ProcessingException { final int effectiveBatchSize = determineBatchSize(); List<E> batch = getItemsFromQueue(effectiveBatchSize); final int retryAttempts = config.getRetryAttempts(); int executionsLeft = retryAttempts + 1; while (executionsLeft-- > 0) { try { processor.process(batch); break; } catch (final RuntimeException e) { LOGGER.warn( "processBatchedItems caught error while processing batch of " + batch.size() + " error " + e); if (executionsLeft <= 0) { for (E item : batch) { try { processor.throwAway(item, e); } catch (final Throwable th) { LOGGER.warn( "processBatchedItems caught error while throwing away an item: " + item + " error " + th); } } } else { LOGGER.warn( getThreadName() + " : processBatchedItems() : exception during processing, retrying in " + retryAttempts + " milliseconds, " + executionsLeft + " retries left : " + e); try { Thread.sleep(config.getRetryAttemptDelay()); } catch (InterruptedException e1) { Thread.currentThread().interrupt(); throw e; } } } } removeFromQueue(effectiveBatchSize); }
private void processSingleItem() throws ProcessingException { // process the next item final E item = getItemsFromQueue(1).get(0); final int retryAttempts = config.getRetryAttempts(); int executionsLeft = retryAttempts + 1; while (executionsLeft-- > 0) { try { processor.process(item); break; } catch (final RuntimeException e) { if (executionsLeft <= 0) { try { processor.throwAway(item, e); } catch (final Throwable th) { LOGGER.warn( "processSingleItem caught error while throwing away an item: " + item + " " + th); } } else { LOGGER.warn( getThreadName() + " : processSingleItem() : exception during processing, retrying in " + retryAttempts + " milliseconds, " + executionsLeft + " retries left : " + e.getMessage()); try { Thread.sleep(config.getRetryAttemptDelay()); } catch (InterruptedException e1) { Thread.currentThread().interrupt(); throw e; } } } } removeFromQueue(1); }