org.apache.camel.processor.loadbalancer
Class FailOverLoadBalancer

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

public class FailOverLoadBalancer
extends LoadBalancerSupport
implements Traceable, CamelContextAware

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
 
Fields inherited from class org.apache.camel.support.ServiceSupport
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
 
Constructor Summary
FailOverLoadBalancer()
           
FailOverLoadBalancer(List<Class<?>> exceptions)
           
 
Method Summary
 CamelContext getCamelContext()
          Get the CamelContext
 List<Class<?>> getExceptions()
           
 int getMaximumFailoverAttempts()
           
 String getTraceLabel()
          Gets the trace label used for logging when tracing is enabled.
 boolean isRoundRobin()
           
 boolean isRunAllowed()
          Helper methods so the service knows if it should keep running.
protected  Exchange prepareExchangeForFailover(Exchange exchange)
          Prepares the exchange for failover
 boolean process(Exchange exchange, AsyncCallback callback)
          Processes the message exchange.
 void setCamelContext(CamelContext camelContext)
          Injects the CamelContext
 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.support.ServiceSupport
doResume, doShutdown, doSuspend, getStatus, getVersion, isStarted, isStarting, isStopped, isStopping, isSuspended, isSuspending, resume, shutdown, 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

getCamelContext

public CamelContext getCamelContext()
Description copied from interface: CamelContextAware
Get the CamelContext

Specified by:
getCamelContext in interface CamelContextAware
Returns:
camelContext the Camel context

setCamelContext

public void setCamelContext(CamelContext camelContext)
Description copied from interface: CamelContextAware
Injects the CamelContext

Specified by:
setCamelContext in interface CamelContextAware
Parameters:
camelContext - the Camel context

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

isRunAllowed

public boolean isRunAllowed()
Description copied from interface: StatefulService
Helper methods so the service knows if it should keep running. Returns false if the service is being stopped or is stopped.

Specified by:
isRunAllowed in interface StatefulService
Overrides:
isRunAllowed in class ServiceSupport
Returns:
true if the service should continue to run.

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 Exchange prepareExchangeForFailover(Exchange exchange)
Prepares the exchange for failover

Parameters:
exchange - the exchange
Returns:
a copy of the exchange to use for failover

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