@@ -27,7 +27,7 @@ public final class ExceptionHandler implements Serializable {
2727 private final ImmutableList <Interceptor > interceptors ;
2828 private final ImmutableSet <Class <? extends Exception >> retriableExceptions ;
2929 private final ImmutableSet <Class <? extends Exception >> nonRetriableExceptions ;
30- private final Set <RetryInfo > retryInfos = Sets .newHashSet ();
30+ private final Set <RetryInfo > retryInfo = Sets .newHashSet ();
3131
3232 public interface Interceptor extends Serializable {
3333
@@ -38,7 +38,7 @@ enum RetryResult {
3838
3939 private final boolean booleanValue ;
4040
41- private RetryResult (boolean booleanValue ) {
41+ RetryResult (boolean booleanValue ) {
4242 this .booleanValue = booleanValue ;
4343 }
4444
@@ -55,7 +55,7 @@ boolean booleanValue() {
5555 * ({@link RetryResult#RETRY}), propagated ({@link RetryResult#ABORT}),
5656 * or evaluation should proceed ({@code null}).
5757 */
58- RetryResult shouldRetry (Exception exception );
58+ RetryResult beforeEval (Exception exception );
5959
6060 /**
6161 * This method is called after the evaluation and could alter its result.
@@ -66,7 +66,7 @@ boolean booleanValue() {
6666 * ({@link RetryResult#RETRY}), propagated ({@link RetryResult#ABORT}),
6767 * or evaluation should proceed ({@code null}).
6868 */
69- RetryResult shouldRetry (Exception exception , RetryResult retryResult );
69+ RetryResult afterEval (Exception exception , RetryResult retryResult );
7070 }
7171
7272 /**
@@ -173,31 +173,30 @@ private ExceptionHandler(Builder builder) {
173173 Sets .intersection (retriableExceptions , nonRetriableExceptions ).isEmpty (),
174174 "Same exception was found in both retriable and non-retriable sets" );
175175 for (Class <? extends Exception > exception : retriableExceptions ) {
176- addToRetryInfos ( retryInfos , new RetryInfo (exception , Interceptor .RetryResult .RETRY ));
176+ addRetryInfo ( new RetryInfo (exception , Interceptor .RetryResult .RETRY ), retryInfo );
177177 }
178178 for (Class <? extends Exception > exception : nonRetriableExceptions ) {
179- addToRetryInfos ( retryInfos , new RetryInfo (exception , Interceptor .RetryResult .ABORT ));
179+ addRetryInfo ( new RetryInfo (exception , Interceptor .RetryResult .ABORT ), retryInfo );
180180 }
181181 }
182182
183- private static void addToRetryInfos ( Set < RetryInfo > retryInfos , RetryInfo retryInfo ) {
184- for (RetryInfo current : retryInfos ) {
183+ private static void addRetryInfo ( RetryInfo retryInfo , Set < RetryInfo > dest ) {
184+ for (RetryInfo current : dest ) {
185185 if (current .exception .isAssignableFrom (retryInfo .exception )) {
186- addToRetryInfos ( current .children , retryInfo );
186+ addRetryInfo ( retryInfo , current .children );
187187 return ;
188188 }
189189 if (retryInfo .exception .isAssignableFrom (current .exception )) {
190190 retryInfo .children .add (current );
191191 }
192192 }
193- retryInfos .removeAll (retryInfo .children );
194- retryInfos .add (retryInfo );
193+ dest .removeAll (retryInfo .children );
194+ dest .add (retryInfo );
195195 }
196196
197-
198- private static RetryInfo findMostSpecificRetryInfo (Set <RetryInfo > retryInfos ,
197+ private static RetryInfo findMostSpecificRetryInfo (Set <RetryInfo > retryInfo ,
199198 Class <? extends Exception > exception ) {
200- for (RetryInfo current : retryInfos ) {
199+ for (RetryInfo current : retryInfo ) {
201200 if (current .exception .isAssignableFrom (exception )) {
202201 RetryInfo match = findMostSpecificRetryInfo (current .children , exception );
203202 return match == null ? current : match ;
@@ -223,10 +222,10 @@ void verifyCaller(Callable<?> callable) {
223222 Method callMethod = getCallableMethod (callable .getClass ());
224223 for (Class <?> exceptionOrError : callMethod .getExceptionTypes ()) {
225224 Preconditions .checkArgument (Exception .class .isAssignableFrom (exceptionOrError ),
226- "Callable method exceptions must be dervied from Exception" );
225+ "Callable method exceptions must be derived from Exception" );
227226 @ SuppressWarnings ("unchecked" ) Class <? extends Exception > exception =
228227 (Class <? extends Exception >) exceptionOrError ;
229- Preconditions .checkArgument (findMostSpecificRetryInfo (retryInfos , exception ) != null ,
228+ Preconditions .checkArgument (findMostSpecificRetryInfo (retryInfo , exception ) != null ,
230229 "Declared exception '" + exception + "' is not covered by exception handler" );
231230 }
232231 }
@@ -241,16 +240,16 @@ public Set<Class<? extends Exception>> getNonRetriableExceptions() {
241240
242241 boolean shouldRetry (Exception ex ) {
243242 for (Interceptor interceptor : interceptors ) {
244- Interceptor .RetryResult retryResult = interceptor .shouldRetry (ex );
243+ Interceptor .RetryResult retryResult = interceptor .beforeEval (ex );
245244 if (retryResult != null ) {
246245 return retryResult .booleanValue ();
247246 }
248247 }
249- RetryInfo retryInfo = findMostSpecificRetryInfo (retryInfos , ex .getClass ());
248+ RetryInfo retryInfo = findMostSpecificRetryInfo (this . retryInfo , ex .getClass ());
250249 Interceptor .RetryResult retryResult =
251250 retryInfo == null ? Interceptor .RetryResult .ABORT : retryInfo .retry ;
252251 for (Interceptor interceptor : interceptors ) {
253- retryResult = firstNonNull (interceptor .shouldRetry (ex , retryResult ), retryResult );
252+ retryResult = firstNonNull (interceptor .afterEval (ex , retryResult ), retryResult );
254253 }
255254 return retryResult .booleanValue ();
256255 }
0 commit comments