public RetryBaseInterceptor(Retry retry) { this(retry, createCondition(retry.condition())); }
protected void handleInvocation(IMethodInvocation invocation) throws Throwable { List<Throwable> throwables = new ArrayList<>(retry.count() + 1); for (int i = 0; i <= retry.count(); i++) { try { invocation.proceed(); return; } catch (Throwable e) { if (isExpected(invocation, e)) { throwables.add(e); if (retry.delay() > 0) { Thread.sleep(retry.delay()); } continue; } else { throw e; } } } throw new MultipleFailureException(throwables); } }
private boolean hasExpectedClass(Throwable failure) { for (Class<? extends Throwable> exception : retry.exceptions()) { if (exception.isInstance(failure)) { return true; } } return false; }
@Override public void visitFeatureAnnotation(Retry annotation, FeatureInfo feature) { if (feature.isParameterized() && (annotation.mode() == Retry.Mode.FEATURE)) { feature.addInterceptor(new RetryIterationInterceptor(annotation)); } else if (annotation.mode() == Retry.Mode.SETUP_FEATURE_CLEANUP) { feature.addIterationInterceptor(new RetryIterationInterceptor(annotation)); } else { feature.getFeatureMethod().addInterceptor(new RetryFeatureInterceptor(annotation)); } } }
@Override public void intercept(IMethodInvocation invocation) throws Throwable { List<Throwable> throwableList = new ArrayList<>(); for (int i = 0; i <= retry.count(); i++) { Queue<Throwable> throwables = new ConcurrentLinkedQueue<>(); invocation.getFeature().getFeatureMethod().addInterceptor(new InnerRetryInterceptor(retry, condition, throwables)); invocation.proceed(); if (throwables.isEmpty()) { throwableList.clear(); break; } else { throwableList.addAll(throwables); if (retry.delay() > 0) Thread.sleep(retry.delay()); } } if (!throwableList.isEmpty()) { throw new MultipleFailureException(throwableList); } }