Package org.apache.camel.processor
Class MulticastProcessor
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.support.AsyncProcessorSupport
-
- org.apache.camel.processor.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.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.RouteIdAwareImplements the Multicast pattern to send a message exchange to a number of endpoints, each endpoint receiving a copy of the message exchange.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classMulticastProcessor.MulticastTask
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.camel.ProcessoronPrepare
-
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)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, boolean stopOnAggregateException)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafterSend(ProcessorExchangePair pair, org.apache.camel.util.StopWatch watch)protected org.apache.camel.util.StopWatchbeforeSend(ProcessorExchangePair pair)protected ExecutorServicecreateAggregateExecutorService(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.protected org.apache.camel.ProcessorcreateErrorHandler(org.apache.camel.Route route, org.apache.camel.Exchange exchange, org.apache.camel.Processor processor)protected ProcessorExchangePaircreateProcessorExchangePair(int index, org.apache.camel.Processor processor, org.apache.camel.Exchange exchange, org.apache.camel.Route route)Creates theProcessorExchangePairwhich holds the processor and exchange to be send out.protected Iterable<ProcessorExchangePair>createProcessorExchangePairs(org.apache.camel.Exchange exchange)protected org.apache.camel.ProcessorcreateUnitOfWorkProcessor(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 routeprotected voiddoAggregate(AtomicReference<org.apache.camel.Exchange> result, org.apache.camel.Exchange exchange, org.apache.camel.Exchange inputExchange)Aggregate theExchangewith the current result.protected voiddoDone(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.protected voiddoInit()protected voiddoShutdown()protected voiddoStart()protected voiddoStop()ExecutorServicegetAggregateExecutorService()org.apache.camel.AggregationStrategygetAggregationStrategy()UsegetAggregationStrategy(org.apache.camel.Exchange)instead.protected org.apache.camel.AggregationStrategygetAggregationStrategy(org.apache.camel.Exchange exchange)org.apache.camel.CamelContextgetCamelContext()protected IntegergetExchangeIndex(org.apache.camel.Exchange exchange)StringgetId()Collection<org.apache.camel.Processor>getProcessors()Returns the producers to multicast toStringgetRouteId()longgetTimeout()An optional timeout in millis when using parallel processingStringgetTraceLabel()booleanhasNext()booleanisParallelAggregate()booleanisParallelProcessing()booleanisShareUnitOfWork()booleanisStopOnAggregateException()booleanisStopOnException()Should the multicast processor stop processing further exchanges in case of an exception occurred?booleanisStreaming()Is the multicast processor working in streaming mode?List<org.apache.camel.Processor>next()protected voidprepareSharedUnitOfWork(org.apache.camel.Exchange childExchange, org.apache.camel.Exchange parentExchange)Prepares the exchange for participating in a shared unit of workbooleanprocess(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback)protected voidremoveAggregationStrategyFromExchange(org.apache.camel.Exchange exchange)Removes the associatedAggregationStrategyfrom theExchangewhich must be done after use.protected voidschedule(Runnable runnable)protected voidschedule(Executor executor, Runnable runnable, long delay, TimeUnit unit)voidsetAggregateExecutorService(ExecutorService aggregateExecutorService)protected voidsetAggregationStrategyOnExchange(org.apache.camel.Exchange exchange, org.apache.camel.AggregationStrategy aggregationStrategy)Sets the givenAggregationStrategyon theExchange.voidsetId(String id)voidsetRouteId(String routeId)protected static voidsetToEndpoint(org.apache.camel.Exchange exchange, org.apache.camel.Processor processor)StringtoString()protected voidupdateNewExchange(org.apache.camel.Exchange exchange, int index, Iterable<ProcessorExchangePair> allPairs, boolean hasNext)-
Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doLifecycleChange, doResume, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
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)
-
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, boolean stopOnAggregateException)
-
-
Method Detail
-
getId
public String getId()
- Specified by:
getIdin interfaceorg.apache.camel.spi.HasId
-
setId
public void setId(String id)
- Specified by:
setIdin interfaceorg.apache.camel.spi.IdAware
-
getRouteId
public String getRouteId()
- Specified by:
getRouteIdin interfaceorg.apache.camel.spi.RouteIdAware
-
setRouteId
public void setRouteId(String routeId)
- Specified by:
setRouteIdin interfaceorg.apache.camel.spi.RouteIdAware
-
getTraceLabel
public String getTraceLabel()
- Specified by:
getTraceLabelin interfaceorg.apache.camel.Traceable
-
getCamelContext
public org.apache.camel.CamelContext getCamelContext()
-
doInit
protected void doInit() throws Exception- Overrides:
doInitin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
process
public boolean process(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback)- Specified by:
processin interfaceorg.apache.camel.AsyncProcessor
-
schedule
protected void schedule(Runnable runnable)
-
beforeSend
protected org.apache.camel.util.StopWatch beforeSend(ProcessorExchangePair pair)
-
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 exchangesubExchange- the current sub exchange, can be null for the synchronous partpairs- the pairs with the exchanges to processcallback- the callbackdoneSync- the doneSync parameter to call on callbackforceExhaust- whether or not 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 theExchangewith the current result. This method is synchronized and is called directly when parallelAggregate is disabled (by default).- Parameters:
result- the current resultexchange- the exchange to be added to the resultinputExchange- 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)
-
createProcessorExchangePairs
protected Iterable<ProcessorExchangePair> createProcessorExchangePairs(org.apache.camel.Exchange exchange) throws Exception
- Throws:
Exception
-
createProcessorExchangePair
protected ProcessorExchangePair createProcessorExchangePair(int index, org.apache.camel.Processor processor, org.apache.camel.Exchange exchange, org.apache.camel.Route route)
Creates theProcessorExchangePairwhich holds the processor and exchange to be send out. You must use this method to create the instances ofProcessorExchangePairas they need to be specially prepared before use.- Parameters:
index- the indexprocessor- the processorexchange- the exchangeroute- the route context- Returns:
- prepared for use
-
createErrorHandler
protected org.apache.camel.Processor createErrorHandler(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 processorexchange- 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 parentUnitOfWorkwhen it participate in a shared unit of work.- Parameters:
childExchange- the child exchangeparentExchange- the parent exchange
-
doStart
protected void doStart() throws Exception- Overrides:
doStartin classorg.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:
doStopin classorg.apache.camel.support.AsyncProcessorSupport- Throws:
Exception
-
doShutdown
protected void doShutdown() throws Exception- Overrides:
doShutdownin classorg.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 givenAggregationStrategyon theExchange.- Parameters:
exchange- the exchangeaggregationStrategy- the strategy
-
removeAggregationStrategyFromExchange
protected void removeAggregationStrategyFromExchange(org.apache.camel.Exchange exchange)
Removes the associatedAggregationStrategyfrom theExchangewhich 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
Iterableto 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
AggregationStrategyhas to take care of handling out-of-order arrival of exchanges
- we use
-
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
-
getAggregationStrategy
public org.apache.camel.AggregationStrategy getAggregationStrategy()
UsegetAggregationStrategy(org.apache.camel.Exchange)instead.
-
isParallelProcessing
public boolean isParallelProcessing()
-
isParallelAggregate
public boolean isParallelAggregate()
-
isStopOnAggregateException
public boolean isStopOnAggregateException()
-
isShareUnitOfWork
public boolean isShareUnitOfWork()
-
getAggregateExecutorService
public ExecutorService getAggregateExecutorService()
-
setAggregateExecutorService
public void setAggregateExecutorService(ExecutorService aggregateExecutorService)
-
next
public List<org.apache.camel.Processor> next()
- Specified by:
nextin interfaceorg.apache.camel.Navigate<org.apache.camel.Processor>
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfaceorg.apache.camel.Navigate<org.apache.camel.Processor>
-
-