org.mule.routing.inbound
Class AbstractEventAggregator

java.lang.Object
  extended by org.mule.routing.AbstractRouter
      extended by org.mule.routing.inbound.SelectiveConsumer
          extended by org.mule.routing.inbound.AbstractEventAggregator
All Implemented Interfaces:
UMOInboundRouter, UMORouter
Direct Known Subclasses:
CorrelationAggregator

public abstract class AbstractEventAggregator
extends SelectiveConsumer

AbstractEventAggregator will aggregate a set of messages into a single message.


Field Summary
static String NO_CORRELATION_ID
           
 
Fields inherited from class org.mule.routing.inbound.SelectiveConsumer
logger
 
Constructor Summary
AbstractEventAggregator()
           
 
Method Summary
protected  EventGroup addEventGroup(EventGroup group)
          Add the given EventGroup to this aggregator's "group store".
protected abstract  UMOMessage aggregateEvents(EventGroup events)
          This method is invoked if the shouldAggregate method is called and returns true.
protected  EventGroup createEventGroup(UMOEvent event, Object groupId)
          Create a new EventGroup with the specified groupId.
protected  EventGroup getEventGroup(Object groupId)
          Look up the existing EventGroup with the given id.
protected  Object getEventGroupIdForEvent(UMOEvent event)
          Returns the identifier by which events will be correlated.
 UMOEvent[] process(UMOEvent event)
          A received UMOEvent is passed to this method for processing.
protected  void removeEventGroup(EventGroup group)
          Remove the group from this aggregator's "store".
protected abstract  boolean shouldAggregateEvents(EventGroup events)
          Determines if the event group is ready to be aggregated.
 
Methods inherited from class org.mule.routing.inbound.SelectiveConsumer
getFilter, isMatch, isTransformFirst, setFilter, setTransformFirst
 
Methods inherited from class org.mule.routing.AbstractRouter
getRouterStatistics, setRouterStatistics
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.mule.umo.routing.UMORouter
getRouterStatistics, setRouterStatistics
 

Field Detail

NO_CORRELATION_ID

public static final String NO_CORRELATION_ID
See Also:
Constant Field Values
Constructor Detail

AbstractEventAggregator

public AbstractEventAggregator()
Method Detail

process

public UMOEvent[] process(UMOEvent event)
                   throws MessagingException
Description copied from interface: UMOInboundRouter
A received UMOEvent is passed to this method for processing. The router can control processing by either 1. passing back a null to indicate that the router has either discarded the event of the event has been stored for further processing. A reaosn for storing the event might be that other events in it's correlation group are expected to be received. 2. Pass back an array of one or more events to be processed by the component. Often 1 event is returned, i.e. in the case of event aggregation. The router may return an array of events if a set of events have been resequenced or multiple events have been generated from a single event.

Specified by:
process in interface UMOInboundRouter
Overrides:
process in class SelectiveConsumer
Parameters:
event - the event received by the inbound endpoint before it is passed to the component
Returns:
null to indicate the event has been stored/destroyed or an array of events to be processed by the component
Throws:
MessagingException - if an error occurs during processing of the event

createEventGroup

protected EventGroup createEventGroup(UMOEvent event,
                                      Object groupId)
Create a new EventGroup with the specified groupId.

Parameters:
event - the event that caused creation of this group; can be used for additional information
groupId - the id to use for the new EventGroup
Returns:
a new EventGroup

getEventGroupIdForEvent

protected Object getEventGroupIdForEvent(UMOEvent event)
Returns the identifier by which events will be correlated. By default this is the value as returned by UMOMessageAdapter.getCorrelationId().

Parameters:
event - the event use for determining the correlation group id
Returns:
the id used to correlate related events

getEventGroup

protected EventGroup getEventGroup(Object groupId)
Look up the existing EventGroup with the given id.

Parameters:
groupId -
Returns:
the EventGroup with the given id or null if the group does not exist.

addEventGroup

protected EventGroup addEventGroup(EventGroup group)
Add the given EventGroup to this aggregator's "group store". Currently this is only a ConcurrentHashMap, and the group's id as returned by EventGroup.getGroupId() is used to match the group. Since group creation/lookup/storage can happen fully concurrent, we return the stored group. Callers are required to switch their method-local references when a different group is returned.

Parameters:
group - the EventGroup to "store"
Returns:
the stored EventGroup (may be different from the one passed as argument)

removeEventGroup

protected void removeEventGroup(EventGroup group)
Remove the group from this aggregator's "store". The group's id as returned by EventGroup.getGroupId() is used to match the group.

Parameters:
group - the EventGroup to remove

shouldAggregateEvents

protected abstract boolean shouldAggregateEvents(EventGroup events)
Determines if the event group is ready to be aggregated. if the group is ready to be aggregated (this is entirely up to the application. it could be determined by volume, last modified time or some oher criteria based on the last event received).

Parameters:
events -
Returns:
true if the group is ready for aggregation

aggregateEvents

protected abstract UMOMessage aggregateEvents(EventGroup events)
                                       throws AggregationException
This method is invoked if the shouldAggregate method is called and returns true. Once this method returns an aggregated message, the event group is removed from the router.

Parameters:
events - the event group for this request
Returns:
an aggregated message
Throws:
AggregationException - if the aggregation fails. in this scenario the whole event group is removed and passed to the exception handler for this componenet


Copyright © 2003-2008 MuleSource, Inc.. All Rights Reserved.