Ejemplo n.º 1
0
 @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
 @Override
 public void process(Exchange exchange) throws Exception {
   if (exchange.getIn().getBody() instanceof InputStream) {
     exchange.getIn().setBody(exchange.getContext().getStreamCachingStrategy().cache(exchange));
   }
   Exchange tempExchange = exchange.copy(true);
   try {
     for (int retry = 0; retry < endpoint.getMaxTries(); ++retry) {
       if (endpoint.getRetryDelay() > 0 && retry > 0) {
         Thread.sleep(endpoint.getRetryDelay());
       }
       endpoint.getTargetProducer().process(tempExchange);
       if (tempExchange.getException() == null) {
         onSuccess(tempExchange);
         return; // success
       }
       FailRetryException failure =
           getExceptionMatching(tempExchange.getException(), FailRetryException.class);
       if (failure != null) {
         if (!failure.isConsumed()) {
           failure.setConsumed(); // make it non-failure for surrounding retries
           return; // forward exception
         }
       }
       if (getExceptionMatching(tempExchange.getException(), endpoint.getException()) != null) {
         // retry
         LOGGER.debug("{} try {} failed", endpoint.getEndpointUri(), retry + 1);
         tempExchange = exchange.copy(true);
         if (exchange.getIn().getBody() instanceof StreamCache) {
           StreamCache is = (StreamCache) exchange.getIn().getBody();
           is.reset();
         }
       } else {
         return; // forward exception
       }
     }
     onExhausted(exchange);
     tempExchange.setException(
         new RetryExhaustedException("Retry exhausted", tempExchange.getException()));
   } finally {
     ExchangeHelper.copyResults(exchange, tempExchange);
   }
 }
Ejemplo n.º 2
0
 private void onSuccess(Exchange tempExchange) throws Exception {
   LOGGER.debug("{} success", endpoint.getEndpointUri());
   if (endpoint.getOnSuccess() != null) {
     endpoint.getOnSuccess().process(PipelineHelper.createNextExchange(tempExchange.copy()));
   }
 }
Ejemplo n.º 3
0
 private void onExhausted(Exchange exchange) throws Exception {
   LOGGER.info("{} exhausted maxRetries={}", endpoint.getEndpointUri(), endpoint.getMaxTries());
   if (endpoint.getOnExhausted() != null) {
     endpoint.getOnExhausted().process(exchange);
   }
 }