Package org.springframework.retry.support

Examples of org.springframework.retry.support.RetryTemplate


                }
            };
        }
       
        public final Advice[] getAdviceChain() {
            RetryTemplate retryRule = new RetryTemplate();
            retryRule.setRetryPolicy(new NeverRetryPolicy());
           
            StatefulRetryOperationsInterceptorFactoryBean retryOperation = new StatefulRetryOperationsInterceptorFactoryBean();
            retryOperation.setRetryOperations(retryRule);
            retryOperation.setMessageKeyGeneretor(new DefaultKeyGenerator());
           
View Full Code Here


        /**
         * Do not have Spring AMQP re-try messages upon failure, leave it to Camel
         * @return An advice chain populated with a NeverRetryPolicy
         */
        public final Advice[] getAdviceChain() {
            RetryTemplate retryRule = new RetryTemplate();
            retryRule.setRetryPolicy(new NeverRetryPolicy());
           
            StatefulRetryOperationsInterceptorFactoryBean retryOperation = new StatefulRetryOperationsInterceptorFactoryBean();
            retryOperation.setRetryOperations(retryRule);
            retryOperation.setMessageKeyGeneretor(new DefaultKeyGenerator());
           
View Full Code Here

                }
            };
        }
       
        public final Advice[] getAdviceChain() {
            RetryTemplate retryRule = new RetryTemplate();
            retryRule.setRetryPolicy(new NeverRetryPolicy());
            StatefulRetryOperationsInterceptorFactoryBean retryOperation = new StatefulRetryOperationsInterceptorFactoryBean();
            retryOperation.setRetryOperations(retryRule);
            return new Advice[] { retryOperation.getObject() };
        }
View Full Code Here

        /**
         * Do not have Spring AMQP re-try messages upon failure, leave it to Camel
         * @return An advice chain populated with a NeverRetryPolicy
         */
        public final Advice[] getAdviceChain() {
            RetryTemplate retryRule = new RetryTemplate();
            retryRule.setRetryPolicy(new NeverRetryPolicy());
           
            StatefulRetryOperationsInterceptorFactoryBean retryOperation = new StatefulRetryOperationsInterceptorFactoryBean();
            retryOperation.setRetryOperations(retryRule);
            retryOperation.setMessageKeyGeneretor(new DefaultKeyGenerator());
           
View Full Code Here

        /**
         * Do not have Spring AMQP re-try messages upon failure, leave it to Camel
         * @return An advice chain populated with a NeverRetryPolicy
         */
        public final Advice[] getAdviceChain() {
            RetryTemplate retryRule = new RetryTemplate();
            retryRule.setRetryPolicy(new NeverRetryPolicy());
           
            StatefulRetryOperationsInterceptorFactoryBean retryOperation = new StatefulRetryOperationsInterceptorFactoryBean();
            retryOperation.setRetryOperations(retryRule);
            retryOperation.setMessageKeyGeneretor(new DefaultKeyGenerator());
           
View Full Code Here

  private NewMethodArgumentsIdentifier newMethodArgumentsIdentifier;

  private RetryOperations retryOperations;

  public StatefulRetryOperationsInterceptor() {
    RetryTemplate retryTemplate = new RetryTemplate();
    retryTemplate.setRetryPolicy(new NeverRetryPolicy());
    retryOperations = retryTemplate;
  }
View Full Code Here

        .recoverer(getRecoverer(target, method))
        .build();
  }

  private MethodInterceptor getStatefulInterceptor(Object target, Method method, Retryable retryable) {
    RetryTemplate template = new RetryTemplate();
    template.setRetryContextCache(this.retryContextCache);
    template.setRetryPolicy(getRetryPolicy(retryable));
    template.setBackOffPolicy(getBackoffPolicy(retryable.backoff()));

    return RetryInterceptorBuilder.stateful()
        .retryOperations(template)
        .recoverer(getRecoverer(target, method))
        .keyGenerator(this.methodArgumentsKeyGenerator)
View Full Code Here

  public void testExternalRetryWithFailAndNoRetry() throws Throwable {
    MockRetryCallback callback = new MockRetryCallback();

    RetryState retryState = new DefaultRetryState("foo");

    RetryTemplate retryTemplate = new RetryTemplate();
    MapRetryContextCache cache = new MapRetryContextCache();
    retryTemplate.setRetryContextCache(cache);
    retryTemplate.setRetryPolicy(new SimpleRetryPolicy(1, Collections
        .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true)));

    assertFalse(cache.containsKey("foo"));

    try {
      retryTemplate.execute(callback, retryState);
      // The first failed attempt we expect to retry...
      fail("Expected RuntimeException");
    }
    catch (RuntimeException e) {
      assertEquals(null, e.getMessage());
    }

    assertTrue(cache.containsKey("foo"));

    try {
      retryTemplate.execute(callback, retryState);
      // We don't get a second attempt...
      fail("Expected ExhaustedRetryException");
    }
    catch (ExhaustedRetryException e) {
      // This is now the "exhausted" message:
View Full Code Here

  public void testExternalRetryWithSuccessOnRetry() throws Throwable {
    MockRetryCallback callback = new MockRetryCallback();

    RetryState retryState = new DefaultRetryState("foo");

    RetryTemplate retryTemplate = new RetryTemplate();
    MapRetryContextCache cache = new MapRetryContextCache();
    retryTemplate.setRetryContextCache(cache);
    retryTemplate.setRetryPolicy(new SimpleRetryPolicy(2, Collections
        .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true)));

    assertFalse(cache.containsKey("foo"));

    Object result = "start_foo";
    try {
      result = retryTemplate.execute(callback, retryState);
      // The first failed attempt we expect to retry...
      fail("Expected RuntimeException");
    }
    catch (RuntimeException e) {
      assertNull(e.getMessage());
    }

    assertTrue(cache.containsKey("foo"));

    result = retryTemplate.execute(callback, retryState);

    assertFalse(cache.containsKey("foo"));

    assertEquals(2, callback.attempts);
    assertEquals("bar", result);
View Full Code Here

  @Test
  public void testExponentialBackOffIsExponential() throws Throwable {
    ExponentialBackOffPolicy policy = new ExponentialBackOffPolicy();
    policy.setInitialInterval(100);
    policy.setMultiplier(1.5);
    RetryTemplate template = new RetryTemplate();
    template.setBackOffPolicy(policy);
    final List<Long> times = new ArrayList<Long>();
    RetryState retryState = new DefaultRetryState("bar");
    for (int i = 0; i < 3; i++) {
      try {
        template.execute(new RetryCallback<String, Exception>() {
          public String doWithRetry(RetryContext context) throws Exception {
            times.add(System.currentTimeMillis());
            throw new Exception("Fail");
          }
        }, new RecoveryCallback<String>() {
View Full Code Here

TOP

Related Classes of org.springframework.retry.support.RetryTemplate

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.