3

The constructor for the SimpleRetryPolicy allows you to specify which exceptions are retryable. Great!

However, this input is a map where the key is the class of the Throwable, and the value is a boolean. There isn't any documentation on what this boolean value is used for- does anyone here know?

Essentially, it populates an instance of a SubclassClassifier whose documentation is too difficult for my simple mind to understand:

A Classifier for a parameterised object type based on a map. Classifies objects according to their inheritance relation with the supplied type map. If the object to be classified is one of the keys of the provided map, or is a subclass of one of the keys, then the map entry value for that key is returned. Otherwise returns the default value which is null by default.

IcedDante
  • 6,145
  • 12
  • 57
  • 100

1 Answers1

4

See SimpleRetryPolicy.retryForException():

/**
 * Delegates to an exception classifier.
 *
 * @param ex
 * @return true if this exception or its ancestors have been registered as
 * retryable.
 */
private boolean retryForException(Throwable ex) {
    return retryableClassifier.classify(ex);
}

i.e. if the throwable is classified (is in the map), the boolean value of that map entry is returned.

This allows you to set up a set of exceptions where you explicitly state that you don't want to retry some exception.

Consider exception Bar extends Foo (and Bar has some sibling classes, say Baz, Qux).

If you add Foo:true to the map and Bar:false then Foo and all its subclasses except Bar are retryable.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • You started your answer with "See", did you intend to list the class that this javadoc came from? – IcedDante May 02 '16 at 19:51
  • After some googling, I think you intended to reference the SimpleRetryTemplate source code: [https://github.com/spring-projects/spring-retry/blob/master/src/main/java/org/springframework/retry/policy/SimpleRetryPolicy.java#L104](https://github.com/spring-projects/spring-retry/blob/master/src/main/java/org/springframework/retry/policy/SimpleRetryPolicy.java#L104) – IcedDante May 02 '16 at 19:52
  • 1
    I didn't intend to but have now :) – Gary Russell May 02 '16 at 19:53
  • With the example you provide, is it correct to say that `Baz` and `Qux` are *not* retryable in addition to `Foo`? – IcedDante May 02 '16 at 19:54
  • 2
    If `Baz` and `Qux` are also subclasses of `Foo` and not explicitly in the map then, yes, they **are** retryable because they are subclasses of (retryable) `Foo`. If the throwable is **not** in the map the classifier checks to see if any superclass of the throwable is in the map (in this case `Foo`). So this example: All `Foo`s (and subclasses, except `Bar`) are retryable. Classes not in the map (i.e. not subclasses of `Foo` in this case) are **not** retryable. If you want all classes, except `Bar` to be retryble add `Exception:true`. – Gary Russell May 02 '16 at 20:02