org.apache.camel.processor.loadbalancer
Class FailOverLoadBalancer

java.lang.Object
  extended by org.apache.camel.impl.ServiceSupport
      extended by org.apache.camel.processor.loadbalancer.LoadBalancerSupport
          extended by org.apache.camel.processor.loadbalancer.FailOverLoadBalancer
All Implemented Interfaces:
AsyncProcessor, Navigate<Processor>, Processor, LoadBalancer, Traceable, Service, ShutdownableService

public class FailOverLoadBalancer
extends LoadBalancerSupport
implements Traceable

This FailOverLoadBalancer will failover to use next processor when an exception occurred

This implementation mirrors the logic from the Pipeline in the async variation as the failover load balancer is a specialized pipeline. So the trick is to keep doing the same as the pipeline to ensure it works the same and the async routing engine is flawless.


Field Summary
 
Fields inherited from class org.apache.camel.processor.loadbalancer.LoadBalancerSupport
log
 
Constructor Summary
FailOverLoadBalancer()
           
FailOverLoadBalancer(List<Class<?>> exceptions)
           
 
Method Summary
 List<Class<?>> getExceptions()
           
 int getMaximumFailoverAttempts()
           
 String getTraceLabel()
          Gets the trace label used for logging when tracing is enabled.
 boolean isRoundRobin()
           
protected  void prepareExchangeForFailover(Exchange exchange)
          Prepares the exchange for failover
 boolean process(Exchange exchange, AsyncCallback callback)
          Processes the message exchange.
 void setMaximumFailoverAttempts(int maximumFailoverAttempts)
           
 void setRoundRobin(boolean roundRobin)
           
protected  boolean shouldFailOver(Exchange exchange)
          Should the given failed Exchange failover?
 String toString()
           
 
Methods inherited from class org.apache.camel.processor.loadbalancer.LoadBalancerSupport
addProcessor, doStart, doStop, getProcessors, hasNext, next, process, removeProcessor
 
Methods inherited from class org.apache.camel.impl.ServiceSupport
addChildService, doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspended, isSuspending, removeChildService, resume, shutdown, start, start, stop, suspend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FailOverLoadBalancer

public FailOverLoadBalancer()

FailOverLoadBalancer

public FailOverLoadBalancer(List<Class<?>> exceptions)
Method Detail

getExceptions

public List<Class<?>> getExceptions()

isRoundRobin

public boolean isRoundRobin()

setRoundRobin

public void setRoundRobin(boolean roundRobin)

getMaximumFailoverAttempts

public int getMaximumFailoverAttempts()

setMaximumFailoverAttempts

public void setMaximumFailoverAttempts(int maximumFailoverAttempts)

shouldFailOver

protected boolean shouldFailOver(Exchange exchange)
Should the given failed Exchange failover?

Parameters:
exchange - the exchange that failed
Returns:
true to failover

process

public boolean process(Exchange exchange,
                       AsyncCallback callback)
Description copied from interface: AsyncProcessor
Processes the message exchange. Similar to Processor.process(org.apache.camel.Exchange), but the caller supports having the exchange asynchronously processed.

If there was a failure processing then the caused Exception would be set on the Exchange.

Specified by:
process in interface AsyncProcessor
Parameters:
exchange - the message exchange
callback - the AsyncCallback will be invoked when the processing of the exchange is completed. If the exchange is completed synchronously, then the callback is also invoked synchronously. The callback should therefore be careful of starting recursive loop.
Returns:
(doneSync) true to continue execute synchronously, false to continue being executed asynchronously
See Also:
AsyncProcessorHelper.process(AsyncProcessor, Exchange, AsyncCallback)

prepareExchangeForFailover

protected void prepareExchangeForFailover(Exchange exchange)
Prepares the exchange for failover

Parameters:
exchange - the exchange

toString

public String toString()
Overrides:
toString in class Object

getTraceLabel

public String getTraceLabel()
Description copied from interface: Traceable
Gets the trace label used for logging when tracing is enabled.

The label should be short and precise.

Specified by:
getTraceLabel in interface Traceable
Returns:
the label


Apache CAMEL