Spring Integration

org.springframework.integration.channel
Class AbstractMessageChannel

java.lang.Object
  extended by org.springframework.integration.context.IntegrationObjectSupport
      extended by org.springframework.integration.channel.AbstractMessageChannel
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, NamedComponent, TrackableComponent, MessageChannel
Direct Known Subclasses:
AbstractAmqpChannel, AbstractJmsChannel, AbstractPollableChannel, AbstractSubscribableChannel, SubscribableRedisChannel

public abstract class AbstractMessageChannel
extends IntegrationObjectSupport
implements MessageChannel, TrackableComponent

Base class for MessageChannel implementations providing common properties such as the channel name. Also provides the common functionality for sending and receiving Messages including the invocation of any ChannelInterceptors.

Author:
Mark Fisher, Oleg Zhurakousky

Nested Class Summary
protected  class AbstractMessageChannel.ChannelInterceptorList
          A convenience wrapper class for the list of ChannelInterceptors.
 
Field Summary
protected  org.apache.commons.logging.Log logger
           
 
Constructor Summary
AbstractMessageChannel()
           
 
Method Summary
 void addInterceptor(ChannelInterceptor interceptor)
          Add a channel interceptor to the end of the list.
protected abstract  boolean doSend(Message<?> message, long timeout)
          Subclasses must implement this method.
 java.lang.String getComponentType()
          Subclasses may implement this method to provide component type information.
protected  AbstractMessageChannel.ChannelInterceptorList getInterceptors()
          Exposes the interceptor list for subclasses.
 boolean send(Message<?> message)
          Send a message on this channel.
 boolean send(Message<?> message, long timeout)
          Send a message on this channel.
 void setConversionService(org.springframework.core.convert.ConversionService conversionService)
          Specify the ConversionService to use when trying to convert to one of this channel's supported datatypes for a Message whose payload does not already match.
 void setDatatypes(java.lang.Class<?>... datatypes)
          Specify the Message payload datatype(s) supported by this channel.
 void setInterceptors(java.util.List<ChannelInterceptor> interceptors)
          Set the list of channel interceptors.
 void setShouldTrack(boolean shouldTrack)
           
 
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, getBeanFactory, getComponentName, getConversionService, getTaskScheduler, onInit, setBeanFactory, setBeanName, setComponentName, 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
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

AbstractMessageChannel

public AbstractMessageChannel()
Method Detail

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 IntegrationObjectSupport

setShouldTrack

public void setShouldTrack(boolean shouldTrack)
Specified by:
setShouldTrack in interface TrackableComponent

setDatatypes

public void setDatatypes(java.lang.Class<?>... datatypes)
Specify the Message payload datatype(s) supported by this channel. If a payload type does not match directly, but the 'conversionService' is available, then type conversion will be attempted in the order of the elements provided in this array.

If this property is not set explicitly, any Message payload type will be accepted.

See Also:
setConversionService(ConversionService)

setInterceptors

public void setInterceptors(java.util.List<ChannelInterceptor> interceptors)
Set the list of channel interceptors. This will clear any existing interceptors.


addInterceptor

public void addInterceptor(ChannelInterceptor interceptor)
Add a channel interceptor to the end of the list.


setConversionService

public void setConversionService(org.springframework.core.convert.ConversionService conversionService)
Specify the ConversionService to use when trying to convert to one of this channel's supported datatypes for a Message whose payload does not already match. If this property is not set explicitly but the channel is managed within a context, it will attempt to locate a bean named "integrationConversionService" defined within that context. Finally, if that bean is not available, it will fallback to the "conversionService" bean, if available.

Overrides:
setConversionService in class IntegrationObjectSupport

getInterceptors

protected AbstractMessageChannel.ChannelInterceptorList getInterceptors()
Exposes the interceptor list for subclasses.


send

public final boolean send(Message<?> message)
Send a message on this channel. If the channel is at capacity, this method will block until either space becomes available or the sending thread is interrupted.

Specified by:
send in interface MessageChannel
Parameters:
message - the Message to send
Returns:
true if the message is sent successfully or false if the sending thread is interrupted.

send

public final boolean send(Message<?> message,
                          long timeout)
Send a message on this channel. If the channel is at capacity, this method will block until either the timeout occurs or the sending thread is interrupted. If the specified timeout is 0, the method will return immediately. If less than zero, it will block indefinitely (see send(Message)).

Specified by:
send in interface MessageChannel
Parameters:
message - the Message to send
timeout - the timeout in milliseconds
Returns:
true if the message is sent successfully, false if the message cannot be sent within the allotted time or the sending thread is interrupted.

doSend

protected abstract boolean doSend(Message<?> message,
                                  long timeout)
Subclasses must implement this method. A non-negative timeout indicates how long to wait if the channel is at capacity (if the value is 0, it must return immediately with or without success). A negative timeout value indicates that the method should block until either the message is accepted or the blocking thread is interrupted.


Spring Integration