Package org.springframework.classify

Examples of org.springframework.classify.BinaryExceptionClassifier


   */
  public SimpleRetryPolicy(int maxAttempts, Map<Class<? extends Throwable>, Boolean> retryableExceptions,
      boolean traverseCauses) {
    super();
    this.maxAttempts = maxAttempts;
    this.retryableClassifier = new BinaryExceptionClassifier(retryableExceptions);
    this.retryableClassifier.setTraverseCauses(traverseCauses);
  }
View Full Code Here


      if (transactionTimeout != null) {
        attribute.setTimeout(transactionTimeout);
      }
      Collection<Class<? extends Throwable>> exceptions = noRollbackExceptionClasses == null ? new HashSet<Class<? extends Throwable>>()
          : noRollbackExceptionClasses;
      final BinaryExceptionClassifier classifier = new BinaryExceptionClassifier(exceptions, false);
      builder.transactionAttribute(new DefaultTransactionAttribute(attribute) {
        @Override
        public boolean rollbackOn(Throwable ex) {
          return classifier.classify(ex);
        }
      });
    }
    if (streams != null) {
      for (ItemStream stream : streams) {
View Full Code Here

        return item;
      }
    });
    processor.setProcessSkipPolicy(new AlwaysSkipItemSkipPolicy());
    processor
    .setRollbackClassifier(new BinaryExceptionClassifier(
        Collections
        .<Class<? extends Throwable>> singleton(DataIntegrityViolationException.class),
        false));
    Chunk<String> inputs = new Chunk<String>(Arrays.asList("1", "2"));
    processor.process(contribution, inputs);
View Full Code Here

          return null;
        }
        return item;
      }
    });
    processor.setRollbackClassifier(new BinaryExceptionClassifier(Collections
        .<Class<? extends Throwable>> singleton(IllegalArgumentException.class), false));
    processor.afterPropertiesSet();
    Chunk<String> inputs = new Chunk<String>(Arrays.asList("1", "2", "skip", "skip", "3", "fail", "fail", "4", "5"));
    processor.process(contribution, inputs);
    assertEquals(5, list.size());
View Full Code Here

   * 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));
  }
View Full Code Here

   * 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);
  }
View Full Code Here

   * @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);
  }
View Full Code Here

   *
   * @return an exception classifier: maps to true if an exception should cause rollback
   */
  protected Classifier<Throwable, Boolean> getRollbackClassifier() {

    Classifier<Throwable, Boolean> classifier = new BinaryExceptionClassifier(noRollbackExceptionClasses, false);

    // Try to avoid pathological cases where we cannot force a rollback
    // (should be pretty uncommon):
    if (!classifier.classify(new ForceRollbackForWriteSkipException("test", new RuntimeException()))
        || !classifier.classify(new ExhaustedRetryException("test"))) {

      final Classifier<Throwable, Boolean> binary = classifier;

      Collection<Class<? extends Throwable>> types = new HashSet<Class<? extends Throwable>>();
      types.add(ForceRollbackForWriteSkipException.class);
      types.add(ExhaustedRetryException.class);
      final Classifier<Throwable, Boolean> panic = new BinaryExceptionClassifier(types, true);

      classifier = new Classifier<Throwable, Boolean>() {
        @Override
        public Boolean classify(Throwable classifiable) {
          // Rollback if either the user's list or our own applies
          return panic.classify(classifiable) || binary.classify(classifiable);
        }
      };

    }

View Full Code Here

    RetryTemplate retryTemplate = new RetryTemplate();
    retryTemplate.setRetryPolicy(new SimpleRetryPolicy(attempts,
        Collections.<Class<? extends Throwable>, Boolean> singletonMap(
            Exception.class, true)));
    BinaryExceptionClassifier classifier = new BinaryExceptionClassifier(
        Collections
            .<Class<? extends Throwable>> singleton(IllegalArgumentException.class),
        false);
    retryTemplate.execute(callback, new DefaultRetryState("foo", classifier));
    assertEquals(attempts, callback.attempts);
View Full Code Here

  @Test
  public void testSwitchToStatelessForNoRollback() throws Throwable {
    retryTemplate.setRetryPolicy(new SimpleRetryPolicy(1, Collections
        .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true)));
    // Roll back for these:
    BinaryExceptionClassifier classifier = new BinaryExceptionClassifier(Collections
        .<Class<? extends Throwable>> singleton(DataAccessException.class));
    // ...but not these:
    assertFalse(classifier.classify(new RuntimeException()));
    final String input = "foo";
    RetryState state = new DefaultRetryState(input, classifier);
    RetryCallback<String, Exception> callback = new RetryCallback<String, Exception>() {
      public String doWithRetry(RetryContext context) throws Exception {
        throw new RuntimeException("Barf!");
View Full Code Here

TOP

Related Classes of org.springframework.classify.BinaryExceptionClassifier

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.