org.mule.routing.response
Class AbstractResponseAggregator

java.lang.Object
  extended byorg.mule.routing.response.AbstractResponseRouter
      extended byorg.mule.routing.response.AbstractResponseAggregator
All Implemented Interfaces:
UMOResponseRouter, UMORouter
Direct Known Subclasses:
ResponseCorrelationAggregator, SingleResponseRouter

public abstract class AbstractResponseAggregator
extends AbstractResponseRouter

AbstractResponseAggregator provides a base class for implementing response aggregator routers. This provides a thread-safe implemenetation and allows developers to customise how and when events are grouped and collated. Response Agrregators are used to collect responses that are usually sent to replyTo endpoints set on outbound routers. When an event is sent out via an outbound router, the response router will block the response flow on an UMOComponent until the Response Router resolves a reply or times out.


Field Summary
protected  ConcurrentMap eventGroups
          Map of EventGroup objects.
protected  ConcurrentMap responseEvents
          The collection of messages that are ready to be returned to the callee.
 
Fields inherited from class org.mule.routing.response.AbstractResponseRouter
correlationExtractor, logger
 
Constructor Summary
AbstractResponseAggregator()
           
 
Method Summary
protected  EventGroup addEvent(UMOEvent event)
          Adds the event to an event group.
protected abstract  UMOMessage aggregateEvents(EventGroup events)
          This method is invoked if the shouldAggregate method is called and returns true.
protected  EventGroup createEventGroup(Object id, UMOEvent event)
          Creates a new event group with the given Id and can use other properties on the event Custom implementations can even overload the eventGroup object here
 UMOMessage getResponse(UMOMessage message)
          This method is called by the responding callee thread and should return the aggregated response message
 void process(UMOEvent event)
          This method is invoked when an event is received via an endpoint on this Response Router.
protected  void removeEventGroup(Object id)
           
protected abstract  boolean shouldAggregate(EventGroup events)
          Determines if the event group is ready to be aggregated.
 
Methods inherited from class org.mule.routing.response.AbstractResponseRouter
getCallResponseAggregateIdentifier, getCorrelationExtractor, getReplyAggregateIdentifier, getRouterStatistics, getTimeout, setCorrelationExtractor, setPropertyExtractorAsString, setRouterStatistics, setTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

responseEvents

protected ConcurrentMap responseEvents
The collection of messages that are ready to be returned to the callee. Keyed by Message ID


eventGroups

protected final ConcurrentMap eventGroups
Map of EventGroup objects. These represent one or mre messages to be agregated. These are keyed on Message ID. There will be one responseEvent for every EventGroup.

Constructor Detail

AbstractResponseAggregator

public AbstractResponseAggregator()
Method Detail

process

public void process(UMOEvent event)
             throws RoutingException
Description copied from interface: UMOResponseRouter
This method is invoked when an event is received via an endpoint on this Response Router. It is responsible for tieing up the event it receives with responses waiting to return back to the callee. This method will be called by a different thread to the getResponse method. The getResponse() method block the response execution until the process method signals that a match is found.

Parameters:
event -
Throws:
RoutingException

addEvent

protected EventGroup addEvent(UMOEvent event)
                       throws RoutingException
Adds the event to an event group. Groups are defined by the correlationId on the message. If no 'correlation Id' is returned from calling getReplyAggregateIdentifier() a routing exception will be thrown

Parameters:
event - the reply event received by the response router
Returns:
The event group for the current event or a new group if the current event doesn't belong to an existing group
Throws:
RoutingException

createEventGroup

protected EventGroup createEventGroup(Object id,
                                      UMOEvent event)
Creates a new event group with the given Id and can use other properties on the event Custom implementations can even overload the eventGroup object here

Parameters:
id - The Event group Id for the new Group
event - the current event
Returns:
a New event group for the incoming event

removeEventGroup

protected void removeEventGroup(Object id)

getResponse

public UMOMessage getResponse(UMOMessage message)
                       throws RoutingException
This method is called by the responding callee thread and should return the aggregated response message

Parameters:
message -
Returns:
Throws:
RoutingException
See Also:
UMOMessage, UMOComponent

shouldAggregate

protected abstract boolean shouldAggregate(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 event gorep is ready for aggregation

aggregateEvents

protected abstract UMOMessage aggregateEvents(EventGroup events)
                                       throws RoutingException
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:
RoutingException - if the aggregation fails. in this scenario the whole event group is removed and passed to the exception handler for this componenet


Copyright © 2003-2006 MuleSource Inc.. All Rights Reserved.