Skip to content

Commit

Permalink
#155 RetryOnFailure.ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed May 9, 2015
1 parent 9e4da0e commit d8bf130
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/jcabi/aspects/RetryOnFailure.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
*/
Class<? extends Throwable>[] types() default { Throwable.class };

/**
* Exception types to ignore.
*/
Class<? extends Throwable>[] ignore() default { };

/**
* Shall it be fully verbose (show full exception trace) or just
* exception message?
Expand Down
22 changes: 13 additions & 9 deletions src/main/java/com/jcabi/aspects/aj/Repeater.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ public final class Repeater {
* @param point Joint point
* @return The result of call
* @throws Throwable If something goes wrong inside
* @checkstyle IllegalThrows (5 lines)
* @checkstyle IllegalThrows (6 lines)
* @checkstyle LineLength (4 lines)
* @checkstyle ExecutableStatementCountCheck (100 lines)
*/
@Around("execution(* * (..)) && @annotation(com.jcabi.aspects.RetryOnFailure)")
@SuppressWarnings("PMD.AvoidCatchingThrowable")
Expand All @@ -84,7 +85,10 @@ public Object wrap(final ProceedingJoinPoint point) throws Throwable {
throw ex;
// @checkstyle IllegalCatch (1 line)
} catch (final Throwable ex) {
if (!this.isExceptionToBeRetried(ex.getClass(), types)) {
if (Repeater.matches(ex.getClass(), rof.ignore())) {
throw ex;
}
if (!Repeater.matches(ex.getClass(), types)) {
throw ex;
}
++attempt;
Expand Down Expand Up @@ -150,23 +154,23 @@ private static String message(final Throwable exp) {
}

/**
* Checks if the exception thrown is specified to be retried.
* Checks if the exception thrown matches the list.
* @param thrown The thrown exception class
* @param types The exceptions specified to be retried
* @return True if the method call is to be retried
* @param types The exceptions to match
* @return TRUE if matches
*/
private boolean isExceptionToBeRetried(
private static boolean matches(
final Class<? extends Throwable> thrown,
final Class<? extends Throwable>[] types
) {
boolean result = false;
boolean matches = false;
for (final Class<? extends Throwable> type : types) {
if (type.isAssignableFrom(thrown)) {
result = true;
matches = true;
break;
}
}
return result;
return matches;
}

}

0 comments on commit d8bf130

Please sign in to comment.