Class StreamResequencer

  • All Implemented Interfaces:
    AutoCloseable, org.apache.camel.AsyncProcessor, org.apache.camel.Navigate<org.apache.camel.Processor>, org.apache.camel.Processor, SequenceSender<org.apache.camel.Exchange>, 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

    public class StreamResequencer
    extends org.apache.camel.support.AsyncProcessorSupport
    implements SequenceSender<org.apache.camel.Exchange>, org.apache.camel.Navigate<org.apache.camel.Processor>, org.apache.camel.Traceable, org.apache.camel.spi.IdAware, org.apache.camel.spi.RouteIdAware
    A resequencer that re-orders a (continuous) stream of Exchanges. The algorithm implemented by ResequencerEngine is based on the detection of gaps in a message stream rather than on a fixed batch size. Gap detection in combination with timeouts removes the constraint of having to know the number of messages of a sequence (i.e. the batch size) in advance.

    Messages must contain a unique sequence number for which a predecessor and a successor is known. For example a message with the sequence number 3 has a predecessor message with the sequence number 2 and a successor message with the sequence number 4. The message sequence 2,3,5 has a gap because the successor of 3 is missing. The resequencer therefore has to retain message 5 until message 4 arrives (or a timeout occurs).

    Instances of this class poll for Exchanges from a given endpoint. Resequencing work and the delivery of messages to the next processor is done within the single polling thread.

    See Also:
    ResequencerEngine
    • Field Summary

      • 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
      StreamResequencer​(org.apache.camel.CamelContext camelContext, org.apache.camel.Processor processor, SequenceElementComparator<org.apache.camel.Exchange> comparator, org.apache.camel.Expression expression)
      Creates a new StreamResequencer instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void doBuild()  
      protected void doInit()  
      protected void doStart()  
      protected void doStop()  
      int getCapacity()
      Returns this resequencer's capacity.
      org.apache.camel.spi.ExceptionHandler getExceptionHandler()
      Returns this resequencer's exception handler.
      org.apache.camel.Expression getExpression()  
      String getId()  
      org.apache.camel.Processor getProcessor()
      Returns the next processor.
      String getRouteId()  
      long getTimeout()
      Returns this resequencer's timeout.
      String getTraceLabel()  
      boolean hasNext()  
      boolean isIgnoreInvalidExchanges()  
      boolean isRejectOld()  
      List<org.apache.camel.Processor> next()  
      boolean process​(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback)  
      void sendElement​(org.apache.camel.Exchange exchange)
      Sends the exchange to the next processor.
      void setCapacity​(int capacity)  
      void setDeliveryAttemptInterval​(long deliveryAttemptInterval)  
      void setId​(String id)  
      void setIgnoreInvalidExchanges​(boolean ignoreInvalidExchanges)
      Sets whether to ignore invalid exchanges which cannot be used by this stream resequencer.
      void setRejectOld​(Boolean rejectOld)  
      void setRouteId​(String routeId)  
      void setTimeout​(long timeout)  
      String toString()  
      • Methods inherited from class org.apache.camel.support.AsyncProcessorSupport

        process, processAsync
      • Methods inherited from class org.apache.camel.support.service.BaseService

        build, doFail, 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.spi.IdAware

        setGeneratedId
      • 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

      • StreamResequencer

        public StreamResequencer​(org.apache.camel.CamelContext camelContext,
                                 org.apache.camel.Processor processor,
                                 SequenceElementComparator<org.apache.camel.Exchange> comparator,
                                 org.apache.camel.Expression expression)
        Creates a new StreamResequencer instance.
        Parameters:
        processor - next processor that processes re-ordered exchanges.
        comparator - a sequence element comparator for exchanges.
    • Method Detail

      • getExpression

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

        public org.apache.camel.spi.ExceptionHandler getExceptionHandler()
        Returns this resequencer's exception handler.
      • getProcessor

        public org.apache.camel.Processor getProcessor()
        Returns the next processor.
      • getCapacity

        public int getCapacity()
        Returns this resequencer's capacity. The capacity is the maximum number of exchanges that can be managed by this resequencer at a given point in time. If the capacity if reached, polling from the endpoint will be skipped for timeout milliseconds giving exchanges the possibility to time out and to be delivered after the waiting period.
        Returns:
        this resequencer's capacity.
      • setCapacity

        public void setCapacity​(int capacity)
      • setTimeout

        public void setTimeout​(long timeout)
      • setDeliveryAttemptInterval

        public void setDeliveryAttemptInterval​(long deliveryAttemptInterval)
      • isIgnoreInvalidExchanges

        public boolean isIgnoreInvalidExchanges()
      • setRejectOld

        public void setRejectOld​(Boolean rejectOld)
      • isRejectOld

        public boolean isRejectOld()
      • setIgnoreInvalidExchanges

        public void setIgnoreInvalidExchanges​(boolean ignoreInvalidExchanges)
        Sets whether to ignore invalid exchanges which cannot be used by this stream resequencer.

        Default is false, by which an CamelExchangeException is thrown if the Exchange is invalid.

      • getTraceLabel

        public String getTraceLabel()
        Specified by:
        getTraceLabel in interface org.apache.camel.Traceable
      • 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
      • 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
      • 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
      • sendElement

        public void sendElement​(org.apache.camel.Exchange exchange)
                         throws Exception
        Sends the exchange to the next processor.
        Specified by:
        sendElement in interface SequenceSender<org.apache.camel.Exchange>
        Parameters:
        exchange - exchange to send.
        Throws:
        Exception - if delivery fails.
      • process

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

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

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