org.springframework.integration.channel
Class AbstractMessageChannel

java.lang.Object
  extended by org.springframework.integration.channel.AbstractMessageChannel
All Implemented Interfaces:
org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, MessageChannel
Direct Known Subclasses:
AbstractPollableChannel, AbstractSubscribableChannel

public abstract class AbstractMessageChannel
extends java.lang.Object
implements MessageChannel, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware

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

Nested Class Summary
protected  class AbstractMessageChannel.ChannelInterceptorList
          A convenience wrapper class for the list of ChannelInterceptors.
 
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.
protected  AbstractMessageChannel.ChannelInterceptorList getInterceptors()
          Exposes the interceptor list for subclasses.
 java.lang.String getName()
          Return the name of this channel.
 boolean send(Message<?> message)
          Send a message on this channel.
 boolean send(Message<?> message, long timeout)
          Send a message on this channel.
 void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
           
 void setBeanName(java.lang.String name)
          Set the name of 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.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractMessageChannel

public AbstractMessageChannel()
Method Detail

setBeanName

public void setBeanName(java.lang.String name)
Set the name of this channel. This will be invoked automatically whenever the channel is configured explicitly with a bean definition.

Specified by:
setBeanName in interface org.springframework.beans.factory.BeanNameAware

getName

public java.lang.String getName()
Return the name of this channel.

Specified by:
getName in interface MessageChannel

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 fallback to a bean named "conversionService" defined within that context.


setBeanFactory

public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
Specified by:
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware

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.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

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.