Class MulticastProcessor

  • All Implemented Interfaces:
    AutoCloseable, org.apache.camel.AsyncProcessor, org.apache.camel.Navigate<org.apache.camel.Processor>, org.apache.camel.Processor, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.spi.ErrorHandlerAware, 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:
    RecipientListProcessor, Splitter

    public class MulticastProcessor
    extends org.apache.camel.support.AsyncProcessorSupport
    implements org.apache.camel.Navigate<org.apache.camel.Processor>, org.apache.camel.Traceable, org.apache.camel.spi.IdAware, org.apache.camel.spi.RouteIdAware, org.apache.camel.spi.ErrorHandlerAware
    Implements the Multicast pattern to send a message exchange to a number of endpoints, each endpoint receiving a copy of the message exchange.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.apache.camel.Processor onPrepare  
      protected org.apache.camel.spi.ProcessorExchangeFactory processorExchangeFactory  
      • 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
      MulticastProcessor​(org.apache.camel.CamelContext camelContext, org.apache.camel.Route route, Collection<org.apache.camel.Processor> processors)  
      MulticastProcessor​(org.apache.camel.CamelContext camelContext, org.apache.camel.Route route, Collection<org.apache.camel.Processor> processors, org.apache.camel.AggregationStrategy aggregationStrategy)  
      MulticastProcessor​(org.apache.camel.CamelContext camelContext, org.apache.camel.Route route, Collection<org.apache.camel.Processor> processors, org.apache.camel.AggregationStrategy aggregationStrategy, boolean parallelProcessing, ExecutorService executorService, boolean shutdownExecutorService, boolean streaming, boolean stopOnException, long timeout, org.apache.camel.Processor onPrepare, boolean shareUnitOfWork, boolean parallelAggregate)  
    • Field Detail

      • onPrepare

        protected final org.apache.camel.Processor onPrepare
      • processorExchangeFactory

        protected final org.apache.camel.spi.ProcessorExchangeFactory processorExchangeFactory
    • Constructor Detail

      • MulticastProcessor

        public MulticastProcessor​(org.apache.camel.CamelContext camelContext,
                                  org.apache.camel.Route route,
                                  Collection<org.apache.camel.Processor> processors)
      • MulticastProcessor

        public MulticastProcessor​(org.apache.camel.CamelContext camelContext,
                                  org.apache.camel.Route route,
                                  Collection<org.apache.camel.Processor> processors,
                                  org.apache.camel.AggregationStrategy aggregationStrategy)
      • MulticastProcessor

        public MulticastProcessor​(org.apache.camel.CamelContext camelContext,
                                  org.apache.camel.Route route,
                                  Collection<org.apache.camel.Processor> processors,
                                  org.apache.camel.AggregationStrategy aggregationStrategy,
                                  boolean parallelProcessing,
                                  ExecutorService executorService,
                                  boolean shutdownExecutorService,
                                  boolean streaming,
                                  boolean stopOnException,
                                  long timeout,
                                  org.apache.camel.Processor onPrepare,
                                  boolean shareUnitOfWork,
                                  boolean parallelAggregate)
    • 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
      • setErrorHandler

        public void setErrorHandler​(org.apache.camel.Processor errorHandler)
        Specified by:
        setErrorHandler in interface org.apache.camel.spi.ErrorHandlerAware
      • getErrorHandler

        public org.apache.camel.Processor getErrorHandler()
        Specified by:
        getErrorHandler in interface org.apache.camel.spi.ErrorHandlerAware
      • getTraceLabel

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

        public org.apache.camel.CamelContext getCamelContext()
      • doBuild

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

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

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

        protected void schedule​(Runnable runnable)
      • afterSend

        protected void afterSend​(ProcessorExchangePair pair,
                                 org.apache.camel.util.StopWatch watch)
      • doDone

        protected void doDone​(org.apache.camel.Exchange original,
                              org.apache.camel.Exchange subExchange,
                              Iterable<ProcessorExchangePair> pairs,
                              org.apache.camel.AsyncCallback callback,
                              boolean doneSync,
                              boolean forceExhaust)
        Common work which must be done when we are done multicasting.

        This logic applies for both running synchronous and asynchronous as there are multiple exist points when using the asynchronous routing engine. And therefore we want the logic in one method instead of being scattered.

        Parameters:
        original - the original exchange
        subExchange - the current sub exchange, can be null for the synchronous part
        pairs - the pairs with the exchanges to process
        callback - the callback
        doneSync - the doneSync parameter to call on callback
        forceExhaust - whether error handling is exhausted
      • doAggregate

        protected void doAggregate​(AtomicReference<org.apache.camel.Exchange> result,
                                   org.apache.camel.Exchange exchange,
                                   org.apache.camel.Exchange inputExchange)
        Aggregate the Exchange with the current result. This method is synchronized and is called directly when parallelAggregate is disabled (by default).
        Parameters:
        result - the current result
        exchange - the exchange to be added to the result
        inputExchange - the input exchange that was sent as input to this EIP
      • updateNewExchange

        protected void updateNewExchange​(org.apache.camel.Exchange exchange,
                                         int index,
                                         Iterable<ProcessorExchangePair> allPairs,
                                         boolean hasNext)
      • getExchangeIndex

        protected Integer getExchangeIndex​(org.apache.camel.Exchange exchange)
      • createProcessorExchangePair

        protected ProcessorExchangePair createProcessorExchangePair​(int index,
                                                                    org.apache.camel.Processor processor,
                                                                    org.apache.camel.Exchange exchange,
                                                                    org.apache.camel.Route route)
        Creates the ProcessorExchangePair which holds the processor and exchange to be send out.

        You must use this method to create the instances of ProcessorExchangePair as they need to be specially prepared before use.

        Parameters:
        index - the index
        processor - the processor
        exchange - the exchange
        route - the route context
        Returns:
        prepared for use
      • wrapInErrorHandler

        protected org.apache.camel.Processor wrapInErrorHandler​(org.apache.camel.Route route,
                                                                org.apache.camel.Exchange exchange,
                                                                org.apache.camel.Processor processor)
      • createUnitOfWorkProcessor

        protected org.apache.camel.Processor createUnitOfWorkProcessor​(org.apache.camel.Route route,
                                                                       org.apache.camel.Processor processor,
                                                                       org.apache.camel.Exchange exchange)
        Strategy to create the unit of work to be used for the sub route
        Parameters:
        processor - the processor
        exchange - the exchange
        Returns:
        the unit of work processor
      • prepareSharedUnitOfWork

        protected void prepareSharedUnitOfWork​(org.apache.camel.Exchange childExchange,
                                               org.apache.camel.Exchange parentExchange)
        Prepares the exchange for participating in a shared unit of work

        This ensures a child exchange can access its parent UnitOfWork when it participate in a shared unit of work.

        Parameters:
        childExchange - the child exchange
        parentExchange - the parent exchange
      • doStart

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

        protected ExecutorService createAggregateExecutorService​(String name)
        Strategy to create the thread pool for the aggregator background task which waits for and aggregates completed tasks when running in parallel mode.
        Parameters:
        name - the suggested name for the background thread
        Returns:
        the thread pool
      • 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
      • setToEndpoint

        protected static void setToEndpoint​(org.apache.camel.Exchange exchange,
                                            org.apache.camel.Processor processor)
      • getAggregationStrategy

        protected org.apache.camel.AggregationStrategy getAggregationStrategy​(org.apache.camel.Exchange exchange)
      • setAggregationStrategyOnExchange

        protected void setAggregationStrategyOnExchange​(org.apache.camel.Exchange exchange,
                                                        org.apache.camel.AggregationStrategy aggregationStrategy)
        Sets the given AggregationStrategy on the Exchange.
        Parameters:
        exchange - the exchange
        aggregationStrategy - the strategy
      • removeAggregationStrategyFromExchange

        protected void removeAggregationStrategyFromExchange​(org.apache.camel.Exchange exchange)
        Removes the associated AggregationStrategy from the Exchange which must be done after use.
        Parameters:
        exchange - the current exchange
      • isStreaming

        public boolean isStreaming()
        Is the multicast processor working in streaming mode?

        In streaming mode:

        • we use Iterable to ensure we can send messages as soon as the data becomes available
        • for parallel processing, we start aggregating responses as they get send back to the processor; this means the AggregationStrategy has to take care of handling out-of-order arrival of exchanges
      • isStopOnException

        public boolean isStopOnException()
        Should the multicast processor stop processing further exchanges in case of an exception occurred?
      • getProcessors

        public Collection<org.apache.camel.Processor> getProcessors()
        Returns the producers to multicast to
      • getTimeout

        public long getTimeout()
        An optional timeout in millis when using parallel processing
      • isParallelProcessing

        public boolean isParallelProcessing()
      • isParallelAggregate

        public boolean isParallelAggregate()
      • isShareUnitOfWork

        public boolean isShareUnitOfWork()
      • getAggregateExecutorService

        public ExecutorService getAggregateExecutorService()
      • setAggregateExecutorService

        public void setAggregateExecutorService​(ExecutorService aggregateExecutorService)
      • next

        public List<org.apache.camel.Processor> next()
        Specified by:
        next in interface org.apache.camel.Navigate<org.apache.camel.Processor>
      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface org.apache.camel.Navigate<org.apache.camel.Processor>