@Override public boolean shouldSkip(Throwable t, int skipCount) throws SkipLimitExceededException { for (SkipPolicy policy : skipPolicies) { if (policy.shouldSkip(t, skipCount)) { return true; } } return false; }
/** * Convenience method for calling process skip policy, so that it can be * called from multiple places. * * @param policy the skip policy * @param e the cause of the skip * @param skipCount the current skip count */ private boolean shouldSkip(SkipPolicy policy, Throwable e, int skipCount) { try { return policy.shouldSkip(e, skipCount); } catch (SkipLimitExceededException ex) { throw ex; } catch (RuntimeException ex) { throw new SkipListenerFailedException("Fatal exception in SkipPolicy.", ex, e); } }
/** * Convenience method for calling process skip policy. * * @param policy the skip policy * @param e the cause of the skip * @param skipCount the current skip count */ private boolean shouldSkip(SkipPolicy policy, Throwable e, int skipCount) { try { return policy.shouldSkip(e, skipCount); } catch (SkipException ex) { throw ex; } catch (RuntimeException ex) { throw new SkipPolicyFailedException("Fatal exception in SkipPolicy.", ex, e); } }
/** * Wrap a {@link SkipPolicy} and make it consistent with known fatal exceptions. * * @param skipPolicy an existing skip policy * @return a skip policy that will not skip fatal exceptions */ protected SkipPolicy getFatalExceptionAwareProxy(SkipPolicy skipPolicy) { NeverSkipItemSkipPolicy neverSkipPolicy = new NeverSkipItemSkipPolicy(); Map<Class<? extends Throwable>, SkipPolicy> map = new HashMap<>(); for (Class<? extends Throwable> fatal : nonSkippableExceptionClasses) { map.put(fatal, neverSkipPolicy); } SubclassClassifier<Throwable, SkipPolicy> classifier = new SubclassClassifier<>(skipPolicy); classifier.setTypeMap(map); ExceptionClassifierSkipPolicy skipPolicyWrapper = new ExceptionClassifierSkipPolicy(); skipPolicyWrapper.setExceptionClassifier(classifier); return skipPolicyWrapper; }
protected SkipPolicy createSkipPolicy() { SkipPolicy skipPolicy = this.skipPolicy; Map<Class<? extends Throwable>, Boolean> map = new HashMap<>( skippableExceptionClasses); map.put(ForceRollbackForWriteSkipException.class, true); LimitCheckingItemSkipPolicy limitCheckingItemSkipPolicy = new LimitCheckingItemSkipPolicy(skipLimit, map); if (skipPolicy == null) { Assert.state(!(skippableExceptionClasses.isEmpty() && skipLimit > 0), "If a skip limit is provided then skippable exceptions must also be specified"); skipPolicy = limitCheckingItemSkipPolicy; } else if (limitCheckingItemSkipPolicy != null) { skipPolicy = new CompositeSkipPolicy(new SkipPolicy[] { skipPolicy, limitCheckingItemSkipPolicy }); } return skipPolicy; }
private LimitCheckingItemSkipPolicy getFatalSubsetSkipPolicy() { Map<Class<? extends Throwable>, Boolean> skippableExceptions = new HashMap<>(); skippableExceptions.put(WriteFailedException.class, false); skippableExceptions.put(ItemWriterException.class, true); return new LimitCheckingItemSkipPolicy(1, skippableExceptions); }
/** * 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; }
@Override public Exception getException(String msg, RuntimeException cause, Throwable e) throws Exception { return new SkipListenerFailedException(msg, cause, e); }
@Override public Exception getException(String msg, Throwable e) throws Exception { return new NonSkippableReadException(msg, e); }
@Override public Exception getException(String msg, RuntimeException cause, Throwable e) throws Exception { return new SkipPolicyFailedException(msg, cause, e); }
/** * condition: skippable < fatal; exception is unclassified * * expected: false; default classification */ @Test public void testSkippableSubset_unclassified() { assertFalse(getSkippableSubsetSkipPolicy().shouldSkip(new RuntimeException(), 0)); }
/** * condition: fatal < skippable; exception is unclassified * * expected: false; default classification */ @Test public void testFatalSubset_unclassified() { assertFalse(getFatalSubsetSkipPolicy().shouldSkip(new RuntimeException(), 0)); }
@Override public Exception getException(String msg, Throwable e) throws Exception { return new NonSkippableWriteException(msg, e); }
/** * Convenience method for calling process skip policy. * * @param policy the skip policy * @param e the cause of the skip * @param skipCount the current skip count */ private boolean shouldSkip(SkipPolicy policy, Throwable e, int skipCount) { try { return policy.shouldSkip(e, skipCount); } catch (SkipException ex) { throw ex; } catch (RuntimeException ex) { throw new SkipPolicyFailedException("Fatal exception in SkipPolicy.", ex, e); } }
/** * 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); }
private LimitCheckingItemSkipPolicy getSkippableSubsetSkipPolicy() { Map<Class<? extends Throwable>, Boolean> skippableExceptions = new HashMap<>(); skippableExceptions.put(WriteFailedException.class, true); skippableExceptions.put(ItemWriterException.class, false); return new LimitCheckingItemSkipPolicy(1, skippableExceptions); }
/** * condition: skippable < fatal; exception is skippable * * expected: true */ @Test public void testSkippableSubset_skippable() { assertTrue(getSkippableSubsetSkipPolicy().shouldSkip(new WriteFailedException(""), 0)); }
/** * condition: fatal < skippable; exception is skippable * * expected: true */ @Test public void testFatalSubset_skippable() { assertTrue(getFatalSubsetSkipPolicy().shouldSkip(new WriterNotOpenException(""), 0)); }
/** * condition: skippable < fatal; exception is fatal * * expected: false */ @Test public void testSkippableSubset_fatal() { assertFalse(getSkippableSubsetSkipPolicy().shouldSkip(new WriterNotOpenException(""), 0)); }
/** * condition: fatal < skippable; exception is fatal * * expected: false */ @Test public void testFatalSubset_fatal() { assertFalse(getFatalSubsetSkipPolicy().shouldSkip(new WriteFailedException(""), 0)); } }