@Override public boolean rollbackOn(Throwable ex) { return classifier.classify(ex); } });
/** * @param skipLimit the number of skippable exceptions that are allowed to * be skipped * @param skippableExceptions exception classes that can be skipped * (non-critical) */ public LimitCheckingItemSkipPolicy(int skipLimit, Map<Class<? extends Throwable>, Boolean> skippableExceptions) { this(skipLimit, new BinaryExceptionClassifier(skippableExceptions)); }
/** * A convenience method of creating a router classifier based on a plain old * Java Object. The object provided must have precisely one public method * that either has the <code>@Classifier</code> annotation or accepts a single argument * and outputs a String. This will be used to create an input classifier for * the router component. * * @param delegate the delegate object used to create a router classifier */ public void setRouterDelegate(Object delegate) { this.router = new ClassifierAdapter<C,String>(delegate); }
/** * Setter for policy map used to create a classifier. Either this property * or the exception classifier directly should be set, but not both. * * @param policyMap a map of Throwable class to {@link RetryPolicy} that * will be used to create a {@link Classifier} to locate a policy. */ public void setPolicyMap(Map<Class<? extends Throwable>, RetryPolicy> policyMap) { this.exceptionClassifier = new SubclassClassifier<Throwable, RetryPolicy>(policyMap, new NeverRetryPolicy()); }
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") public T classify(C classifiable) { if (classifier != null) { return classifier.classify(classifiable); } return (T) invoker.invokeMethod(classifiable); }
/** * Create a {@link SimpleRetryPolicy} with the specified number of retry * attempts. If traverseCauses is true, the exception causes will be traversed until * a match is found. The default value indicates whether to retry or not for exceptions * (or super classes) are not found in the map. * * @param maxAttempts the maximum number of attempts * @param retryableExceptions the map of exceptions that are retryable based on the * map value (true/false). * @param traverseCauses is this clause traversable * @param defaultValue the default action. */ public SimpleRetryPolicy(int maxAttempts, Map<Class<? extends Throwable>, Boolean> retryableExceptions, boolean traverseCauses, boolean defaultValue) { super(); this.maxAttempts = maxAttempts; this.retryableClassifier = new BinaryExceptionClassifier(retryableExceptions, defaultValue); this.retryableClassifier.setTraverseCauses(traverseCauses); }
/** * Consult the classifier and find a delegate policy, and then use that to * determine the outcome. * * @param t the throwable to consider * @param skipCount the current skip count * @return true if the exception can be skipped * @throws SkipLimitExceededException if a limit is exceeded */ @Override public boolean shouldSkip(Throwable t, int skipCount) throws SkipLimitExceededException { return classifier.classify(t).shouldSkip(t, skipCount); }
/** * A convenience method for creating a pattern matching classifier for the * matcher component. * * @param map maps pattern keys with wildcards to output values */ public void setMatcherMap(Map<String, T> map) { this.matcher = new PatternMatchingClassifier<T>(map); }
/** * Create a classifier from the provided map. The keys are patterns, using * '?' as a single character and '*' as multi-character wildcard. * * @param values the values to use in the {@link PatternMatcher} */ public PatternMatchingClassifier(Map<String, T> values) { super(); this.values = new PatternMatcher<T>(values); }
/** * Create a new {@link Classifier} from the delegate provided. Use the * constructor as an alternative to the {@link #setDelegate(Object)} method. * * @param delegate the delegate */ public ClassifierAdapter(Object delegate) { setDelegate(delegate); }
/** * Classify the input by matching it against the patterns provided in * {@link #setPatternMap(Map)}. The most specific pattern that matches will * be used to locate a value. * * @return the value matching the most specific pattern possible * * @throws IllegalStateException if no matching value is found. */ public T classify(String classifiable) { T value = values.match(classifiable); return value; }
public boolean rollbackFor(Throwable exception) { if (rollbackClassifier == null) { return true; } return rollbackClassifier.classify(exception); }
/** * Setter for policy map. This property should not be changed dynamically - * set it once, e.g. in configuration, and then don't change it during a * running application. Either this property or the exception classifier * directly should be set, but not both. * * @param policyMap a map of String to {@link SkipPolicy} that will be used * to create a {@link Classifier} to locate a policy. */ public void setPolicyMap(Map<Class<? extends Throwable>, SkipPolicy> policyMap) { SubclassClassifier<Throwable, SkipPolicy> subclassClassifier = new SubclassClassifier<>( policyMap, new NeverSkipItemSkipPolicy()); this.classifier = subclassClassifier; }
/** * Set up the classifier through a convenient map from throwable class to * boolean (true if skippable). * * @param skippableExceptions the skippable exceptions to set */ public void setSkippableExceptionMap(Map<Class<? extends Throwable>, Boolean> skippableExceptions) { this.skippableExceptionClassifier = new BinaryExceptionClassifier(skippableExceptions); }
/** * 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); }
/** * A map from pattern to value * @param values the pattern map to set */ public void setPatternMap(Map<String, T> values) { this.values = new PatternMatcher<T>(values); }
@Override public boolean rollbackOn(Throwable ex) { return classifier.classify(ex); }
/** * Create an exception handler from its mandatory properties. * * @param retryPolicy the retry policy that will be under effect when an * exception is encountered * @param exceptionHandler the delegate to use if an exception actually * needs to be handled * @param fatalExceptionClasses exceptions */ public SimpleRetryExceptionHandler(RetryPolicy retryPolicy, ExceptionHandler exceptionHandler, Collection<Class<? extends Throwable>> fatalExceptionClasses) { this.retryPolicy = retryPolicy; this.exceptionHandler = exceptionHandler; this.fatalExceptionClassifier = new BinaryExceptionClassifier(fatalExceptionClasses); }
/** * Delegates to injected {@link ItemProcessor} instances according to the * classification by the {@link Classifier}. */ @Override public O process(I item) throws Exception { return processItem(classifier.classify(item), item); }