Class RoutingSlip

  • All Implemented Interfaces:
    AutoCloseable, org.apache.camel.AsyncProcessor, org.apache.camel.Processor, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.spi.HasId, org.apache.camel.spi.IdAware, org.apache.camel.spi.RouteIdAware, org.apache.camel.StatefulService, org.apache.camel.SuspendableService, org.apache.camel.Traceable
    Direct Known Subclasses:
    DynamicRouter

    public class RoutingSlip
    extends org.apache.camel.support.AsyncProcessorSupport
    implements org.apache.camel.Traceable, org.apache.camel.spi.IdAware, org.apache.camel.spi.RouteIdAware
    Implements a Routing Slip pattern where the list of actual endpoints to send a message exchange to are dependent on the value of a message header.

    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.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected static interface  RoutingSlip.RoutingSlipIterator
      The iterator to be used for retrieving the next routing slip(s) to be used.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int cacheSize  
      protected org.apache.camel.CamelContext camelContext  
      protected org.apache.camel.AsyncProcessor errorHandler  
      protected org.apache.camel.Expression expression  
      protected String header  
      protected String id  
      protected boolean ignoreInvalidEndpoints  
      protected org.apache.camel.spi.ProducerCache producerCache  
      protected String routeId  
      protected String uriDelimiter  
      • Fields inherited from class org.apache.camel.support.service.BaseService

        BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
    • Constructor Summary

      Constructors 
      Constructor Description
      RoutingSlip​(org.apache.camel.CamelContext camelContext)  
      RoutingSlip​(org.apache.camel.CamelContext camelContext, org.apache.camel.Expression expression, String uriDelimiter)  
    • Field Detail

      • routeId

        protected String routeId
      • producerCache

        protected org.apache.camel.spi.ProducerCache producerCache
      • cacheSize

        protected int cacheSize
      • ignoreInvalidEndpoints

        protected boolean ignoreInvalidEndpoints
      • header

        protected String header
      • expression

        protected org.apache.camel.Expression expression
      • uriDelimiter

        protected String uriDelimiter
      • camelContext

        protected final org.apache.camel.CamelContext camelContext
      • errorHandler

        protected org.apache.camel.AsyncProcessor errorHandler
    • Constructor Detail

      • RoutingSlip

        public RoutingSlip​(org.apache.camel.CamelContext camelContext)
      • RoutingSlip

        public RoutingSlip​(org.apache.camel.CamelContext camelContext,
                           org.apache.camel.Expression expression,
                           String uriDelimiter)
    • Method Detail

      • getId

        public String getId()
        Specified by:
        getId in interface org.apache.camel.spi.HasId
      • setId

        public void setId​(String id)
        Specified by:
        setId in interface org.apache.camel.spi.IdAware
      • getRouteId

        public String getRouteId()
        Specified by:
        getRouteId in interface org.apache.camel.spi.RouteIdAware
      • setRouteId

        public void setRouteId​(String routeId)
        Specified by:
        setRouteId in interface org.apache.camel.spi.RouteIdAware
      • getExpression

        public org.apache.camel.Expression getExpression()
      • getUriDelimiter

        public String getUriDelimiter()
      • setDelimiter

        public void setDelimiter​(String delimiter)
      • isIgnoreInvalidEndpoints

        public boolean isIgnoreInvalidEndpoints()
      • setIgnoreInvalidEndpoints

        public void setIgnoreInvalidEndpoints​(boolean ignoreInvalidEndpoints)
      • getCacheSize

        public int getCacheSize()
      • setCacheSize

        public void setCacheSize​(int cacheSize)
      • getErrorHandler

        public org.apache.camel.AsyncProcessor getErrorHandler()
      • setErrorHandler

        public void setErrorHandler​(org.apache.camel.AsyncProcessor errorHandler)
      • getTraceLabel

        public String getTraceLabel()
        Specified by:
        getTraceLabel in interface org.apache.camel.Traceable
      • process

        public boolean process​(org.apache.camel.Exchange exchange,
                               org.apache.camel.AsyncCallback callback)
        Specified by:
        process in interface org.apache.camel.AsyncProcessor
      • createRoutingSlipIterator

        protected RoutingSlip.RoutingSlipIterator createRoutingSlipIterator​(org.apache.camel.Exchange exchange,
                                                                            org.apache.camel.Expression expression)
                                                                     throws Exception
        Creates the route slip iterator to be used.
        Parameters:
        exchange - the exchange
        expression - the expression
        Returns:
        the iterator, should never be null
        Throws:
        Exception
      • prepareRecipient

        protected static Object prepareRecipient​(org.apache.camel.Exchange exchange,
                                                 Object recipient)
                                          throws org.apache.camel.NoTypeConversionAvailableException
        Throws:
        org.apache.camel.NoTypeConversionAvailableException
      • getExistingEndpoint

        protected static org.apache.camel.Endpoint getExistingEndpoint​(org.apache.camel.Exchange exchange,
                                                                       Object recipient)
      • resolveEndpoint

        protected org.apache.camel.Endpoint resolveEndpoint​(org.apache.camel.Exchange exchange,
                                                            Object recipient,
                                                            boolean prototype)
                                                     throws Exception
        Throws:
        Exception
      • prepareExchangeForRoutingSlip

        protected org.apache.camel.Exchange prepareExchangeForRoutingSlip​(org.apache.camel.Exchange current,
                                                                          org.apache.camel.Endpoint endpoint)
      • createErrorHandler

        protected org.apache.camel.AsyncProcessor createErrorHandler​(org.apache.camel.Route route,
                                                                     org.apache.camel.Exchange exchange,
                                                                     org.apache.camel.AsyncProcessor processor,
                                                                     org.apache.camel.Endpoint endpoint)
      • processExchange

        protected boolean processExchange​(org.apache.camel.Endpoint endpoint,
                                          org.apache.camel.Exchange exchange,
                                          org.apache.camel.Exchange original,
                                          org.apache.camel.AsyncCallback originalCallback,
                                          RoutingSlip.RoutingSlipIterator iter,
                                          boolean prototype)
      • doStart

        protected void doStart()
                        throws Exception
        Overrides:
        doStart in class org.apache.camel.support.AsyncProcessorSupport
        Throws:
        Exception
      • doStop

        protected void doStop()
                       throws Exception
        Overrides:
        doStop in class org.apache.camel.support.AsyncProcessorSupport
        Throws:
        Exception
      • doShutdown

        protected void doShutdown()
                           throws Exception
        Overrides:
        doShutdown in class org.apache.camel.support.service.BaseService
        Throws:
        Exception
      • getEndpointUtilizationStatistics

        public org.apache.camel.spi.EndpointUtilizationStatistics getEndpointUtilizationStatistics()
      • newRoutingSlipProcessorForErrorHandler

        public org.apache.camel.AsyncProcessor newRoutingSlipProcessorForErrorHandler()
        Creates the embedded processor to use when wrapping this routing slip in an error handler.