Class Splitter

  • All Implemented Interfaces:
    AutoCloseable, org.apache.camel.DelegateProcessor, org.apache.camel.Navigate<org.apache.camel.Processor>, org.apache.camel.Processor, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.StatefulService, org.apache.camel.SuspendableService

    public class Splitter
    extends org.apache.camel.support.processor.DelegateProcessor
    A processor that splits an exchange into multiple exchanges by using a rule. The rule generates the individual sub exchanges (i.e. the result exchanges of the split). An AggregationStrategy allows aggregation of the sub exchanges.
    Author:
    Jens Riemschneider
    • Field Summary

      • Fields inherited from class org.apache.camel.support.processor.DelegateProcessor

        processor
      • 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
      Splitter​(org.apache.camel.Expression splitRule, org.apache.camel.Processor processor)
      Creates a splitter
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Splitter aggregate​(org.apache.camel.AggregationStrategy strategy)
      Sets the strategy to aggregate data over all sub exchanges created by the splitter This method allows for chain configuration
      protected void finalizeAggregate​(org.apache.camel.Exchange origExchange, org.apache.camel.Exchange aggregate)
      Creates the actual aggregation result of the processor This method is called by processNext(Exchange) to calculate the aggregation result of the splitter.
      protected void finalizeSubExchange​(org.apache.camel.Exchange origExchange, org.apache.camel.Exchange subExchange, SplitIndex index)
      Updates the contents of sub exchanges This method is called by processNext(Exchange) before sending a sub exchange to the destination processor.
      protected void processNext​(org.apache.camel.Exchange origExchange)
      Processes the given exchange This method is the entry point for splitting the given exchange into its parts via the split rule.
      • Methods inherited from class org.apache.camel.support.processor.DelegateProcessor

        doStart, doStop, getProcessor, hasNext, next, process, setProcessor, toString
      • Methods inherited from class org.apache.camel.support.service.BaseService

        build, doBuild, doFail, doInit, doLifecycleChange, doResume, doShutdown, 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 interface org.apache.camel.Service

        build, close, init, start, stop
      • Methods inherited from interface org.apache.camel.ShutdownableService

        shutdown
      • Methods inherited from interface org.apache.camel.StatefulService

        getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending
      • Methods inherited from interface org.apache.camel.SuspendableService

        isSuspended, resume, suspend
    • Constructor Detail

      • Splitter

        public Splitter​(org.apache.camel.Expression splitRule,
                        org.apache.camel.Processor processor)
        Creates a splitter
        Parameters:
        splitRule - expression that performs the splitting of the original exchange
        processor - destination processor for all sub exchanges. Can be null if the destination is set later via DelegateProcessor.setProcessor(Processor), e.g. via an intercept.
    • Method Detail

      • aggregate

        public Splitter aggregate​(org.apache.camel.AggregationStrategy strategy)
        Sets the strategy to aggregate data over all sub exchanges created by the splitter This method allows for chain configuration
        Parameters:
        strategy - the aggregation strategy
        Returns:
        the splitter for chaining
      • processNext

        protected void processNext​(org.apache.camel.Exchange origExchange)
                            throws Exception
        Processes the given exchange This method is the entry point for splitting the given exchange into its parts via the split rule. Subclasses can change the created sub exchanges by overriding finalizeSubExchange(Exchange, Exchange, SplitIndex) and the aggregate result by overriding finalizeAggregate(Exchange, Exchange).
        Overrides:
        processNext in class org.apache.camel.support.processor.DelegateProcessor
        Parameters:
        origExchange - exchange that should be split by this processor
        Throws:
        Exception
      • finalizeAggregate

        protected void finalizeAggregate​(org.apache.camel.Exchange origExchange,
                                         org.apache.camel.Exchange aggregate)
        Creates the actual aggregation result of the processor This method is called by processNext(Exchange) to calculate the aggregation result of the splitter. The base implementation in this class simply copies the results of the aggregate into the original exchange. Sub classes should call this base method implementation to ensure compatibility with upcoming version.
        Parameters:
        origExchange - the exchange that was originally passed to DelegateProcessor.process(Exchange). The base implementation changes the content of this exchange to ensure that further processing in the route is performed with the aggregated result.
        aggregate - the aggregation result. This is the exchange that was determined by passing all processed sub exchanges to the AggregationStrategy defined by aggregate(AggregationStrategy). This parameter can be null if the AggregationStrategy returned null.
      • finalizeSubExchange

        protected void finalizeSubExchange​(org.apache.camel.Exchange origExchange,
                                           org.apache.camel.Exchange subExchange,
                                           SplitIndex index)
        Updates the contents of sub exchanges This method is called by processNext(Exchange) before sending a sub exchange to the destination processor. It is the final chance to change the contents (body, header, etc.) of the sub exchange. The base implementation of this method currently performs no operations. However, it is recommended to call it in sub classes to ensure compatibility with upcoming version of this class.
        Parameters:
        origExchange - original exchange passed to DelegateProcessor.process(Exchange)
        subExchange - sub exchange that was split off. The content of this exchange can be changed by this method.
        index - index of the sub exchange in the result list of the split