/** * Re-throws the original throwable if it is an Exception, and wraps non-exceptions * into {@link RetryException}. */ private static <E extends Throwable> E wrapIfNecessary(Throwable throwable) throws RetryException { if (throwable instanceof Error) { throw (Error) throwable; } else if (throwable instanceof Exception) { @SuppressWarnings("unchecked") E rethrow = (E) throwable; return rethrow; } else { throw new RetryException("Exception in retry", throwable); } }
public Object evaluate(String expression, Map values) throws FirstException, RetryException { try{ // Some code that may throw FirstException int x = 10/0; }catch (ArithmeticException x){ // Handle divide by zero RetryException retry= new RetryException(); retry.setExpression(expression); retry.setPosition(position); retry.setOperator(tokens[position]); retry.setOperand(1); throw retry; } } }
private void checkSkipPolicy(Chunk<I>.ChunkIterator inputIterator, Chunk<O>.ChunkIterator outputIterator, Throwable e, StepContribution contribution, boolean recovery) throws Exception { logger.debug("Checking skip policy after failed write"); if (shouldSkip(itemWriteSkipPolicy, e, contribution.getStepSkipCount())) { contribution.incrementWriteSkipCount(); inputIterator.remove(); outputIterator.remove(e); logger.debug("Skipping after failed write", e); } else { if (recovery) { // Only if already recovering should we check skip policy throw new RetryException("Non-skippable exception in recoverer", e); } else { if (e instanceof Exception) { throw (Exception) e; } else if (e instanceof Error) { throw (Error) e; } else { throw new RetryException("Non-skippable throwable in recoverer", e); } } } }
@Override public O recover(RetryContext context) throws Exception { Throwable e = context.getLastThrowable(); if (shouldSkip(skipPolicy, e, contribution.getStepSkipCount())) { contribution.incrementWriteSkipCount(); logger.debug("Skipping after failed write", e); return null; } else { if (rollbackClassifier.classify(e)) { // Default is to rollback unless the classifier // allows us to continue throw new RetryException("Non-skippable exception in recoverer while write", e); } return null; } }
@Override public I recover(RetryContext context) throws Exception { Throwable e = context.getLastThrowable(); if (shouldSkip(skipPolicy, e, contribution.getStepSkipCount())) { contribution.incrementReadSkipCount(); logger.debug("Skipping after failed process", e); return null; } else { if (rollbackClassifier.classify(e)) { // Default is to rollback unless the classifier // allows us to continue throw new RetryException("Non-skippable exception in recoverer while reading", e); } throw new BatchRuntimeException(e); } }
@Override public O recover(RetryContext context) throws Exception { Throwable e = context.getLastThrowable(); if (shouldSkip(skipPolicy, e, contribution.getStepSkipCount())) { contribution.incrementProcessSkipCount(); logger.debug("Skipping after failed process", e); return null; } else { if (rollbackClassifier.classify(e)) { // Default is to rollback unless the classifier // allows us to continue throw new RetryException("Non-skippable exception in recoverer while processing", e); } throw new BatchRuntimeException(e); } } };
private void registerContext(RetryContext context, RetryState state) { if (state != null) { Object key = state.getKey(); if (key != null) { if (context.getRetryCount() > 1 && !this.retryContextCache.containsKey(key)) { throw new RetryException( "Inconsistent state for failed item key: cache key has changed. " + "Consider whether equals() or hashCode() for the key might be inconsistent, " + "or if you need to supply a better key"); } this.retryContextCache.put(key, context); } } }
@Override public O recover(RetryContext context) throws Exception { Throwable e = context.getLastThrowable(); if (shouldSkip(itemProcessSkipPolicy, e, contribution.getStepSkipCount())) { iterator.remove(e); contribution.incrementProcessSkipCount(); logger.debug("Skipping after failed process", e); return null; } else { if (rollbackClassifier.classify(e)) { // Default is to rollback unless the classifier // allows us to continue throw new RetryException("Non-skippable exception in recoverer while processing", e); } iterator.remove(e); return null; } }
@Override public Object recover(RetryContext context) throws Exception { Throwable e = context.getLastThrowable(); if (outputs.size() > 1 && !rollbackClassifier.classify(e)) { throw new RetryException("Invalid retry state during write caused by " + "exception that does not classify for rollback: ", e); } Chunk<I>.ChunkIterator inputIterator = inputs.iterator(); for (Chunk<O>.ChunkIterator outputIterator = outputs.iterator(); outputIterator.hasNext();) { inputIterator.next(); outputIterator.next(); checkSkipPolicy(inputIterator, outputIterator, e, contribution, true); if (!rollbackClassifier.classify(e)) { throw new RetryException( "Invalid retry state during recovery caused by exception that does not classify for rollback: ", e); } } return null; }
if (context == null) { if (this.retryContextCache.containsKey(key)) { throw new RetryException( "Inconsistent state for failed item: no history found. " + "Consider whether equals() or hashCode() for the item might be inconsistent, "
@Override public T recover(RetryContext context) throws Exception { Throwable lastThrowable = context.getLastThrowable(); if (lastThrowable != null) { if (lastThrowable instanceof RetryableStatusCodeException) { RetryableStatusCodeException ex = (RetryableStatusCodeException) lastThrowable; return createResponse((R) ex.getResponse(), ex.getUri()); } else if (lastThrowable instanceof Exception){ throw (Exception)lastThrowable; } } throw new RetryException("Could not recover", lastThrowable); } }
/** * Re-throws the original throwable if it is an Exception, and wraps non-exceptions * into {@link RetryException}. */ private static <E extends Throwable> E wrapIfNecessary(Throwable throwable) throws RetryException { if (throwable instanceof Error) { throw (Error) throwable; } else if (throwable instanceof Exception) { @SuppressWarnings("unchecked") E rethrow = (E) throwable; return rethrow; } else { throw new RetryException("Exception in retry", throwable); } }
private void checkSkipPolicy(Chunk<I>.ChunkIterator inputIterator, Chunk<O>.ChunkIterator outputIterator, Throwable e, StepContribution contribution, boolean recovery) throws Exception { logger.debug("Checking skip policy after failed write"); if (shouldSkip(itemWriteSkipPolicy, e, contribution.getStepSkipCount())) { contribution.incrementWriteSkipCount(); inputIterator.remove(); outputIterator.remove(e); logger.debug("Skipping after failed write", e); } else { if (recovery) { // Only if already recovering should we check skip policy throw new RetryException("Non-skippable exception in recoverer", e); } else { if (e instanceof Exception) { throw (Exception) e; } else if (e instanceof Error) { throw (Error) e; } else { throw new RetryException("Non-skippable throwable in recoverer", e); } } } }
private void checkSkipPolicy(Chunk<I>.ChunkIterator inputIterator, Chunk<O>.ChunkIterator outputIterator, Throwable e, StepContribution contribution, boolean recovery) throws Exception { logger.debug("Checking skip policy after failed write"); if (shouldSkip(itemWriteSkipPolicy, e, contribution.getStepSkipCount())) { contribution.incrementWriteSkipCount(); inputIterator.remove(); outputIterator.remove(e); logger.debug("Skipping after failed write", e); } else { if (recovery) { // Only if already recovering should we check skip policy throw new RetryException("Non-skippable exception in recoverer", e); } else { if (e instanceof Exception) { throw (Exception) e; } else if (e instanceof Error) { throw (Error) e; } else { throw new RetryException("Non-skippable throwable in recoverer", e); } } } }
private void checkSkipPolicy(Chunk<I>.ChunkIterator inputIterator, Chunk<O>.ChunkIterator outputIterator, Throwable e, StepContribution contribution, boolean recovery) throws Exception { logger.debug("Checking skip policy after failed write"); if (shouldSkip(itemWriteSkipPolicy, e, contribution.getStepSkipCount())) { contribution.incrementWriteSkipCount(); inputIterator.remove(); outputIterator.remove(e); logger.debug("Skipping after failed write", e); } else { if (recovery) { // Only if already recovering should we check skip policy throw new RetryException("Non-skippable exception in recoverer", e); } else { if (e instanceof Exception) { throw (Exception) e; } else if (e instanceof Error) { throw (Error) e; } else { throw new RetryException("Non-skippable throwable in recoverer", e); } } } }
@Override public O recover(RetryContext context) throws Exception { Throwable e = context.getLastThrowable(); if (shouldSkip(skipPolicy, e, contribution.getStepSkipCount())) { contribution.incrementWriteSkipCount(); logger.debug("Skipping after failed write", e); return null; } else { if (rollbackClassifier.classify(e)) { // Default is to rollback unless the classifier // allows us to continue throw new RetryException("Non-skippable exception in recoverer while write", e); } return null; } }
@Override public O recover(RetryContext context) throws Exception { Throwable e = context.getLastThrowable(); if (shouldSkip(skipPolicy, e, contribution.getStepSkipCount())) { contribution.incrementWriteSkipCount(); logger.debug("Skipping after failed write", e); return null; } else { if (rollbackClassifier.classify(e)) { // Default is to rollback unless the classifier // allows us to continue throw new RetryException("Non-skippable exception in recoverer while write", e); } return null; } }
@Override public O recover(RetryContext context) throws Exception { Throwable e = context.getLastThrowable(); if (shouldSkip(skipPolicy, e, contribution.getStepSkipCount())) { contribution.incrementWriteSkipCount(); logger.debug("Skipping after failed write", e); return null; } else { if (rollbackClassifier.classify(e)) { // Default is to rollback unless the classifier // allows us to continue throw new RetryException("Non-skippable exception in recoverer while write", e); } return null; } }
tries++; if( MAX_RETRIES == tries ) { throw new RetryException("Maximum retries exceeded", ex ); } else { return run();
@Override public T recover(RetryContext context) throws Exception { Throwable lastThrowable = context.getLastThrowable(); if (lastThrowable != null) { if (lastThrowable instanceof RetryableStatusCodeException) { RetryableStatusCodeException ex = (RetryableStatusCodeException) lastThrowable; return createResponse((R) ex.getResponse(), ex.getUri()); } else if (lastThrowable instanceof Exception){ throw (Exception)lastThrowable; } } throw new RetryException("Could not recover", lastThrowable); } }