Spring Integration

org.springframework.integration.handler
Class MessageHandlerChain

java.lang.Object
  extended by org.springframework.integration.context.IntegrationObjectSupport
      extended by org.springframework.integration.handler.AbstractMessageHandler
          extended by org.springframework.integration.handler.MessageHandlerChain
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle, org.springframework.core.Ordered, NamedComponent, Orderable, MessageHandler, MessageProducer, TrackableComponent

public class MessageHandlerChain
extends AbstractMessageHandler
implements MessageProducer, org.springframework.context.SmartLifecycle

A composite MessageHandler implementation that invokes a chain of MessageHandler instances in order.

Each of the handlers except for the last one must implement the MessageProducer interface. The last handler must also if the chain itself has an output channel configured. No other assumptions are made about the type of handler.

It is expected that each handler will produce reply messages and send them to its output channel, although this is not enforced. It is possible to filter messages in the middle of the chain, for example using a MessageFilter. A MessageHandler returning null will have the same effect, although this option is less expressive.

This component can be used from the namespace to improve the readability of the configuration by removing channels that can be created implicitly.

 <chain>
     <filter ref="someFilter"/>
     <bean class="SomeMessageHandlerImplementation"/>
     <transformer ref="someTransformer"/>
     <aggregator ... />
 </chain>
 

Author:
Mark Fisher, Iwein Fuld, Gary Russell, Artem Bilan

Field Summary
 
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
logger
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
MessageHandlerChain()
           
 
Method Summary
 java.lang.String getComponentType()
          Subclasses may implement this method to provide component type information.
 int getPhase()
           
protected  void handleMessageInternal(Message<?> message)
           
 boolean isAutoStartup()
          SmartLifecycle implementation (delegates to the handlers)
 boolean isRunning()
           
protected  void onInit()
          Subclasses may implement this for initialization logic.
 void setAutoStartup(boolean autoStartup)
           
 void setComponentName(java.lang.String componentName)
          Sets the name of this component.
 void setHandlers(java.util.List<MessageHandler> handlers)
           
 void setOutputChannel(MessageChannel outputChannel)
          Specify the MessageChannel to which produced Messages should be sent.
 void setPhase(int phase)
           
 void setSendTimeout(long sendTimeout)
           
 void start()
           
 void stop()
           
 void stop(java.lang.Runnable callback)
           
 
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
getOrder, handleMessage, setOrder, setShouldTrack
 
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, getBeanFactory, getComponentName, getConversionService, getTaskScheduler, setBeanFactory, setBeanName, setConversionService, setTaskScheduler, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.integration.context.NamedComponent
getComponentName
 

Constructor Detail

MessageHandlerChain

public MessageHandlerChain()
Method Detail

setHandlers

public void setHandlers(java.util.List<MessageHandler> handlers)

setOutputChannel

public void setOutputChannel(MessageChannel outputChannel)
Description copied from interface: MessageProducer
Specify the MessageChannel to which produced Messages should be sent.

Specified by:
setOutputChannel in interface MessageProducer

setSendTimeout

public void setSendTimeout(long sendTimeout)

getComponentType

public java.lang.String getComponentType()
Description copied from class: IntegrationObjectSupport
Subclasses may implement this method to provide component type information.

Specified by:
getComponentType in interface NamedComponent
Overrides:
getComponentType in class AbstractMessageHandler

onInit

protected void onInit()
               throws java.lang.Exception
Description copied from class: IntegrationObjectSupport
Subclasses may implement this for initialization logic.

Overrides:
onInit in class IntegrationObjectSupport
Throws:
java.lang.Exception

handleMessageInternal

protected void handleMessageInternal(Message<?> message)
                              throws java.lang.Exception
Specified by:
handleMessageInternal in class AbstractMessageHandler
Throws:
java.lang.Exception

setComponentName

public void setComponentName(java.lang.String componentName)
Description copied from class: IntegrationObjectSupport
Sets the name of this component.

Overrides:
setComponentName in class IntegrationObjectSupport

isAutoStartup

public final boolean isAutoStartup()
SmartLifecycle implementation (delegates to the handlers)

Specified by:
isAutoStartup in interface org.springframework.context.SmartLifecycle

getPhase

public final int getPhase()
Specified by:
getPhase in interface org.springframework.context.Phased

isRunning

public final boolean isRunning()
Specified by:
isRunning in interface org.springframework.context.Lifecycle

start

public final void start()
Specified by:
start in interface org.springframework.context.Lifecycle

stop

public final void stop()
Specified by:
stop in interface org.springframework.context.Lifecycle

stop

public final void stop(java.lang.Runnable callback)
Specified by:
stop in interface org.springframework.context.SmartLifecycle

setAutoStartup

public void setAutoStartup(boolean autoStartup)

setPhase

public void setPhase(int phase)

Spring Integration