org.apache.camel.processor
Class Throttler

java.lang.Object
  extended by org.apache.camel.support.ServiceSupport
      extended by org.apache.camel.processor.DelegateAsyncProcessor
          extended by org.apache.camel.processor.DelayProcessorSupport
              extended by org.apache.camel.processor.Throttler
All Implemented Interfaces:
AsyncProcessor, DelegateProcessor, Navigate<Processor>, Processor, Service, ShutdownableService, StatefulService, SuspendableService, Traceable

public class Throttler
extends DelayProcessorSupport
implements Traceable

A Throttler will set a limit on the maximum number of message exchanges which can be sent to a processor within a specific time period.

This pattern can be extremely useful if you have some external system which meters access; such as only allowing 100 requests per second; or if huge load can cause a particular system to malfunction or to reduce its throughput you might want to introduce some throttling.

Version:

Nested Class Summary
protected  class Throttler.TimeSlot
           
 
Field Summary
 
Fields inherited from class org.apache.camel.processor.DelayProcessorSupport
log
 
Fields inherited from class org.apache.camel.processor.DelegateAsyncProcessor
processor
 
Fields inherited from class org.apache.camel.support.ServiceSupport
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
 
Constructor Summary
Throttler(CamelContext camelContext, Processor processor, Expression maxRequestsPerPeriodExpression, long timePeriodMillis, ScheduledExecutorService executorService, boolean shutdownExecutorService)
           
 
Method Summary
protected  long calculateDelay(Exchange exchange)
           
 long getCurrentMaximumRequestsPerPeriod()
          Gets the current maximum request per period value.
 Expression getMaximumRequestsPerPeriodExpression()
           
 long getTimePeriodMillis()
           
 String getTraceLabel()
          Gets the trace label used for logging when tracing is enabled.
protected  Throttler.TimeSlot nextSlot()
           
 void setMaximumRequestsPerPeriodExpression(Expression maxRequestsPerPeriodExpression)
          Sets the maximum number of requests per time period expression
 void setTimePeriodMillis(long timePeriodMillis)
          Sets the time period during which the maximum number of requests apply
 String toString()
           
 
Methods inherited from class org.apache.camel.processor.DelayProcessorSupport
currentSystemTime, delay, doShutdown, doStart, handleSleepInterruptedException, isAsyncDelayed, isCallerRunsWhenRejected, process, setAsyncDelayed, setCallerRunsWhenRejected
 
Methods inherited from class org.apache.camel.processor.DelegateAsyncProcessor
doStop, getProcessor, hasNext, next, process, processNext, setProcessor, setProcessor
 
Methods inherited from class org.apache.camel.support.ServiceSupport
doResume, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspended, isSuspending, resume, shutdown, start, stop, suspend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Throttler

public Throttler(CamelContext camelContext,
                 Processor processor,
                 Expression maxRequestsPerPeriodExpression,
                 long timePeriodMillis,
                 ScheduledExecutorService executorService,
                 boolean shutdownExecutorService)
Method Detail

toString

public String toString()
Overrides:
toString in class DelegateAsyncProcessor

getTraceLabel

public String getTraceLabel()
Description copied from interface: Traceable
Gets the trace label used for logging when tracing is enabled.

The label should be short and precise.

Specified by:
getTraceLabel in interface Traceable
Returns:
the label

setMaximumRequestsPerPeriodExpression

public void setMaximumRequestsPerPeriodExpression(Expression maxRequestsPerPeriodExpression)
Sets the maximum number of requests per time period expression


getMaximumRequestsPerPeriodExpression

public Expression getMaximumRequestsPerPeriodExpression()

getTimePeriodMillis

public long getTimePeriodMillis()

getCurrentMaximumRequestsPerPeriod

public long getCurrentMaximumRequestsPerPeriod()
Gets the current maximum request per period value.


setTimePeriodMillis

public void setTimePeriodMillis(long timePeriodMillis)
Sets the time period during which the maximum number of requests apply


calculateDelay

protected long calculateDelay(Exchange exchange)
Specified by:
calculateDelay in class DelayProcessorSupport

nextSlot

protected Throttler.TimeSlot nextSlot()


Apache CAMEL