org.apache.camel.processor
Class Throttler

java.lang.Object
  extended by org.apache.camel.impl.ServiceSupport
      extended by org.apache.camel.processor.DelegateProcessor
          extended by org.apache.camel.processor.DelayProcessorSupport
              extended by org.apache.camel.processor.Throttler
All Implemented Interfaces:
Navigate, Processor, Traceable, Service

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 systme to malfunction or to reduce its throughput you might want to introduce some throttling.

Version:
$Revision: 788621 $

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.DelegateProcessor
processor
 
Constructor Summary
Throttler(Processor processor, long maximumRequestsPerPeriod)
           
Throttler(Processor processor, long maximumRequestsPerPeriod, long timePeriodMillis)
           
 
Method Summary
protected  void delay(Exchange exchange)
           
 long getMaximumRequestsPerPeriod()
           
 long getTimePeriodMillis()
           
 String getTraceLabel()
          Gets the trace label used for logging when tracing is enabled.
protected  Throttler.TimeSlot nextSlot()
           
 void setMaximumRequestsPerPeriod(long maximumRequestsPerPeriod)
          Sets the maximum number of requests per time period
 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, doStop, handleSleepInteruptedException, isFastStop, process, setFastStop, sleep, waitUntil
 
Methods inherited from class org.apache.camel.processor.DelegateProcessor
doStart, getProcessor, hasNext, next, proceed, processNext, setProcessor
 
Methods inherited from class org.apache.camel.impl.ServiceSupport
addChildService, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, removeChildService, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Throttler

public Throttler(Processor processor,
                 long maximumRequestsPerPeriod)

Throttler

public Throttler(Processor processor,
                 long maximumRequestsPerPeriod,
                 long timePeriodMillis)
Method Detail

toString

public String toString()
Overrides:
toString in class DelegateProcessor

getTraceLabel

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

The lable should be short and precise.

Specified by:
getTraceLabel in interface Traceable
Returns:
the label

getMaximumRequestsPerPeriod

public long getMaximumRequestsPerPeriod()

setMaximumRequestsPerPeriod

public void setMaximumRequestsPerPeriod(long maximumRequestsPerPeriod)
Sets the maximum number of requests per time period


getTimePeriodMillis

public long getTimePeriodMillis()

setTimePeriodMillis

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


delay

protected void delay(Exchange exchange)
              throws Exception
Specified by:
delay in class DelayProcessorSupport
Throws:
Exception

nextSlot

protected Throttler.TimeSlot nextSlot()


Apache CAMEL