# Class: com.pnfsoftware.jeb.util.events.AggregatorDispatcher

An [event](IEvent) aggregator\-dispatcher. This object is useful when the frequency of events reception is getting high \- and as a consequence, event processing time getting larger \(relatively\) than the incoming event period. Events are aggregated and [dispatched](#onMultipleEvents(List)) only after either many events have been received or a timeout has elapsed.

## Constructor: AggregatorDispatcher

Description: Create a new aggregator\-dispatcher with a capacity of 100, and a resolution of 250 ms.

## Constructor: AggregatorDispatcher
- parameter: `capacity`, type: `int`
- parameter: `triggerResolution`, type: `long`

Description: Create a new aggregator\-dispatcher.
parameter: capacity: event capacity, at least 1: after that many events are received,            [#onMultipleEvents(List)](#onMultipleEvents(List)) routine is called
parameter: triggerResolution: a resolution in milliseconds: the period at which the event queue is            automatically dispatched and cleaned, regardless of whether the capacity was            reached. Careful: 0 is a valid resolution at which the auto\-dispatcher is            disabled, ie, events are dispatched ONLY when the aggregator is at full capacity
throws: if the capacity is not positive or the trigger resolution is             negative

## Method: capacity
- return type: `int`

Description: Get the maximum number of queued events before an immediate dispatch is triggered.
return: the dispatch capacity

## Method: onEvent
- parameter: `e`, type: `com.pnfsoftware.jeb.util.events.IEvent`


## Method: onMultipleEvents
- parameter: `events`, type: `java.util.List<com.pnfsoftware.jeb.util.events.IEvent>`

Description: This method is called by the aggregator\-dispatcher whenever any of the following condition occurs: [enough events](#capacity()) were collected; or [enough time](#resolution()) has elapsed. 

 Thread notes: This method may be called by the thread that generated the event, or any other worker thread used by the aggregator\-dispatcher. Execution of this method is serialized: the next execution of [#onMultipleEvents(List)](#onMultipleEvents(List)) will not start until the previous execution has terminated.
parameter: events: the list of collected events

## Method: resolution
- return type: `long`

Description: Get the timed dispatch resolution.
return: the dispatch resolution in milliseconds, or 0 if timed dispatch is disabled

## Method: unattended
- return type: `int`

Description: Get the number of events currently waiting to be dispatched.
return: the number of queued events

