org.apache.servicemix.eip.support
Class AbstractAggregator

java.lang.Object
  extended by org.apache.servicemix.common.endpoints.AbstractEndpoint
      extended by org.apache.servicemix.common.endpoints.SimpleEndpoint
          extended by org.apache.servicemix.common.endpoints.ProviderEndpoint
              extended by org.apache.servicemix.eip.EIPEndpoint
                  extended by org.apache.servicemix.eip.support.AbstractAggregator
All Implemented Interfaces:
Endpoint
Direct Known Subclasses:
SplitAggregator

public abstract class AbstractAggregator
extends EIPEndpoint

Aggregator can be used to wait and combine several messages. This component implements the Aggregator pattern. Closed aggregations are being kept in a Store. By default, we will use a simple MemoryStore, but you can set your own StoreFactory to use other implementations. TODO: distributed lock manager TODO: persistent / transactional timer

Version:
$Revision: 376451 $
Author:
gnodet

Nested Class Summary
static class AbstractAggregator.ClosedAggregateException
          Error used to report that the aggregate has already been closed
 
Field Summary
 
Fields inherited from class org.apache.servicemix.eip.EIPEndpoint
lockManager, store, storeFactory, timerManager, wsdlExchangeTarget, wsdlResource
 
Fields inherited from class org.apache.servicemix.common.endpoints.AbstractEndpoint
definition, description, endpoint, interfaceName, service, serviceUnit
 
Constructor Summary
AbstractAggregator()
           
 
Method Summary
protected abstract  boolean addMessage(java.lang.Object aggregate, javax.jbi.messaging.NormalizedMessage message, javax.jbi.messaging.MessageExchange exchange)
          Add a newly received message to this aggregation
protected abstract  void buildAggregate(java.lang.Object aggregate, javax.jbi.messaging.NormalizedMessage message, javax.jbi.messaging.MessageExchange exchange, boolean timeout)
          Fill the given JBI message with the aggregation result.
protected  void closeAggregation(java.lang.String correlationId)
          Mark an aggregation as closed
protected abstract  java.lang.Object createAggregation(java.lang.String correlationID)
          Creates a new empty aggregation.
 org.apache.servicemix.store.StoreFactory getClosedAggregatesStoreFactory()
          Access the currently configured StoreFactory for storing closed aggregations
protected abstract  java.lang.String getCorrelationID(javax.jbi.messaging.MessageExchange exchange, javax.jbi.messaging.NormalizedMessage message)
          Retrieve the correlation ID of the given exchange
 ExchangeTarget getTarget()
           
protected abstract  java.util.Date getTimeout(java.lang.Object aggregate)
          Returns the date when the onTimeout method should be called if the aggregation is not completed yet, or null if the aggregation has no timeout.
protected  boolean isAggregationClosed(java.lang.String correlationId)
          Check if the aggregation with the given correlation id is closed or not.
 boolean isCopyAttachments()
           
 boolean isCopyProperties()
           
 boolean isReportClosedAggregatesAsErrors()
           
 boolean isReportErrors()
           
 boolean isReportTimeoutAsErrors()
           
 boolean isRescheduleTimeouts()
           
 boolean isSynchronous()
           
protected  void onTimeout(java.lang.String processCorrelationId, java.lang.String correlationId, org.apache.servicemix.timers.Timer timer)
           
 void process(javax.jbi.messaging.MessageExchange exchange)
           
protected  void processAsync(javax.jbi.messaging.MessageExchange exchange)
           
protected  void processSync(javax.jbi.messaging.MessageExchange exchange)
           
protected  void sendAggregate(java.lang.String processCorrelationId, java.lang.String correlationId, java.lang.Object aggregation, boolean timeout, boolean sync)
           
 void setClosedAggregatesStoreFactory(org.apache.servicemix.store.StoreFactory closedAggregatesStoreFactory)
          Set a new StoreFactory for creating the Store to hold closed aggregations.
 void setCopyAttachments(boolean copyAttachments)
          Copy all attachments from the incoming messages to the aggregated message.
 void setCopyProperties(boolean copyProperties)
          Copy all properties from the incoming messages to the aggregated message.
 void setReportClosedAggregatesAsErrors(boolean reportClosedAggregatesAsErrors)
          Sets whether the aggregator should report errors on incoming exchanges received after a given aggregate has been closed.
 void setReportErrors(boolean reportErrors)
          Sets whether the aggregator should report errors happening when sending the aggregate on all exchanges that compose the aggregate.
 void setReportTimeoutAsErrors(boolean reportTimeoutAsErrors)
          Sets whether the aggregator should reports errors on incoming exchanges already received when a timeout occurs.
 void setRescheduleTimeouts(boolean rescheduleTimeouts)
          Boolean flag controlling if aggregate timeouts are rescheduled each time a new message is added to the aggregate.
 void setSynchronous(boolean synchronous)
          Boolean flag that Controls whether the aggregate (when ready) will be sent synchronously or not.
 void setTarget(ExchangeTarget target)
          The exchange target that will be used to send the aggregate to.
 void start()
           
 
Methods inherited from class org.apache.servicemix.eip.EIPEndpoint
chooseFirstEndpointWithDescriptor, copyAttachments, copyProperties, getDefinition, getDefinitionFromDescription, getDefinitionFromWsdlExchangeTarget, getDefinitionFromWsdlResource, getDescription, getDescriptionForExchangeTarget, getEndpointsForExchangeTarget, getLockManager, getStore, getStoreFactory, getTimerManager, getWsdlExchangeTarget, getWsdlResource, setLockManager, setStore, setStoreFactory, setTimerManager, setWsdlExchangeTarget, setWsdlResource, stop
 
Methods inherited from class org.apache.servicemix.common.endpoints.ProviderEndpoint
activate, deactivate, getRole, processInOnly, processInOut
 
Methods inherited from class org.apache.servicemix.common.endpoints.SimpleEndpoint
done, fail, getChannel, getContext, getExchangeFactory, send, sendSync
 
Methods inherited from class org.apache.servicemix.common.endpoints.AbstractEndpoint
getEndpoint, getInterfaceName, getKey, getService, getServiceUnit, isExchangeOkay, prepareExchange, setDefinition, setDescription, setEndpoint, setInterfaceName, setService, setServiceUnit, toString, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractAggregator

public AbstractAggregator()
Method Detail

isSynchronous

public boolean isSynchronous()
Returns:
the synchronous

setSynchronous

public void setSynchronous(boolean synchronous)
Boolean flag that Controls whether the aggregate (when ready) will be sent synchronously or not. On ServiceMix 3.x, this can have an effect upon the flow and transaction semantics. The default value is false.

Parameters:
synchronous - the synchronous to set

isRescheduleTimeouts

public boolean isRescheduleTimeouts()
Returns:
the rescheduleTimeouts

setRescheduleTimeouts

public void setRescheduleTimeouts(boolean rescheduleTimeouts)
Boolean flag controlling if aggregate timeouts are rescheduled each time a new message is added to the aggregate. If false, the timeout will expire when the specified amount of time elapsed after the first message is received for this aggregate. If true, the timeout will expire when the specified amount of time elapsed after the last message is received. The default value is false.

Parameters:
rescheduleTimeouts - the rescheduleTimeouts to set

getTarget

public ExchangeTarget getTarget()
Returns:
the target

setTarget

public void setTarget(ExchangeTarget target)
The exchange target that will be used to send the aggregate to.

Parameters:
target - the target to set

isCopyProperties

public boolean isCopyProperties()

setCopyProperties

public void setCopyProperties(boolean copyProperties)
Copy all properties from the incoming messages to the aggregated message. Default value is true.

Parameters:
copyProperties -

isCopyAttachments

public boolean isCopyAttachments()

setCopyAttachments

public void setCopyAttachments(boolean copyAttachments)
Copy all attachments from the incoming messages to the aggregated message. Default value is true.

Parameters:
copyAttachments -

isReportErrors

public boolean isReportErrors()

setReportErrors

public void setReportErrors(boolean reportErrors)
Sets whether the aggregator should report errors happening when sending the aggregate on all exchanges that compose the aggregate. The default value is false, meaning that if any error occur, this error will be lost. Note that if this flag is set to true, all exchanges received as part of a given aggregate will be hold until the aggregate is sent and the DONE / ERROR status is received back.

Parameters:
reportErrors - boolean indicating if errors should be reported back to consumers

isReportClosedAggregatesAsErrors

public boolean isReportClosedAggregatesAsErrors()

setReportClosedAggregatesAsErrors

public void setReportClosedAggregatesAsErrors(boolean reportClosedAggregatesAsErrors)
Sets whether the aggregator should report errors on incoming exchanges received after a given aggregate has been closed. The default value is false, meaning that such exchanges will be silently sent back with a DONE status and discarded with respect to the aggregation process.

Parameters:
reportClosedAggregatesAsErrors - boolean indicating if exchanges received for a closed aggregates should be send back with an ERROR status

setReportTimeoutAsErrors

public void setReportTimeoutAsErrors(boolean reportTimeoutAsErrors)
Sets whether the aggregator should reports errors on incoming exchanges already received when a timeout occurs. The default value is false, meaning that such exchanges will be silently sent back a DONE status.

Parameters:
reportTimeoutAsErrors - boolean indicating if exchanges received prior to a timeout should be sent back with an ERROR status

isReportTimeoutAsErrors

public boolean isReportTimeoutAsErrors()
Returns:
the reportTimeoutAsErrors

processSync

protected void processSync(javax.jbi.messaging.MessageExchange exchange)
                    throws java.lang.Exception
Specified by:
processSync in class EIPEndpoint
Throws:
java.lang.Exception

getClosedAggregatesStoreFactory

public org.apache.servicemix.store.StoreFactory getClosedAggregatesStoreFactory()
Access the currently configured StoreFactory for storing closed aggregations


setClosedAggregatesStoreFactory

public void setClosedAggregatesStoreFactory(org.apache.servicemix.store.StoreFactory closedAggregatesStoreFactory)
Set a new StoreFactory for creating the Store to hold closed aggregations. If it hasn't been set, a simple MemoryStoreFactory will be used by default.

Parameters:
closedAggregatesStoreFactory -

processAsync

protected void processAsync(javax.jbi.messaging.MessageExchange exchange)
                     throws java.lang.Exception
Specified by:
processAsync in class EIPEndpoint
Throws:
java.lang.Exception

start

public void start()
           throws java.lang.Exception
Specified by:
start in interface Endpoint
Overrides:
start in class EIPEndpoint
Throws:
java.lang.Exception

process

public void process(javax.jbi.messaging.MessageExchange exchange)
             throws java.lang.Exception
Specified by:
process in interface Endpoint
Overrides:
process in class EIPEndpoint
Throws:
java.lang.Exception

sendAggregate

protected void sendAggregate(java.lang.String processCorrelationId,
                             java.lang.String correlationId,
                             java.lang.Object aggregation,
                             boolean timeout,
                             boolean sync)
                      throws java.lang.Exception
Throws:
java.lang.Exception

onTimeout

protected void onTimeout(java.lang.String processCorrelationId,
                         java.lang.String correlationId,
                         org.apache.servicemix.timers.Timer timer)

isAggregationClosed

protected boolean isAggregationClosed(java.lang.String correlationId)
                               throws java.lang.Exception
Check if the aggregation with the given correlation id is closed or not. Called when the aggregation has not been found in the store.

Parameters:
correlationId -
Returns:
Throws:
AbstractAggregator.ClosedAggregateException
java.lang.Exception

closeAggregation

protected void closeAggregation(java.lang.String correlationId)
                         throws java.lang.Exception
Mark an aggregation as closed

Parameters:
correlationId -
Throws:
AbstractAggregator.ClosedAggregateException
java.lang.Exception

getCorrelationID

protected abstract java.lang.String getCorrelationID(javax.jbi.messaging.MessageExchange exchange,
                                                     javax.jbi.messaging.NormalizedMessage message)
                                              throws java.lang.Exception
Retrieve the correlation ID of the given exchange

Parameters:
exchange -
message -
Returns:
the correlationID
Throws:
AbstractAggregator.ClosedAggregateException
java.lang.Exception

createAggregation

protected abstract java.lang.Object createAggregation(java.lang.String correlationID)
                                               throws java.lang.Exception
Creates a new empty aggregation.

Parameters:
correlationID -
Returns:
a newly created aggregation
Throws:
java.lang.Exception

getTimeout

protected abstract java.util.Date getTimeout(java.lang.Object aggregate)
Returns the date when the onTimeout method should be called if the aggregation is not completed yet, or null if the aggregation has no timeout.

Parameters:
aggregate -
Returns:

addMessage

protected abstract boolean addMessage(java.lang.Object aggregate,
                                      javax.jbi.messaging.NormalizedMessage message,
                                      javax.jbi.messaging.MessageExchange exchange)
                               throws java.lang.Exception
Add a newly received message to this aggregation

Parameters:
aggregate -
message -
exchange -
Returns:
true if the aggregate id complete
Throws:
java.lang.Exception

buildAggregate

protected abstract void buildAggregate(java.lang.Object aggregate,
                                       javax.jbi.messaging.NormalizedMessage message,
                                       javax.jbi.messaging.MessageExchange exchange,
                                       boolean timeout)
                                throws java.lang.Exception
Fill the given JBI message with the aggregation result.

Parameters:
aggregate -
message -
exchange -
timeout - false if the aggregation has completed or true if this aggregation has timed out
Throws:
java.lang.Exception


Copyright © 2005-2011 FuseSource. All Rights Reserved.