org.springframework.integration.channel
Class AbstractMessageChannel

java.lang.Object
  extended by org.springframework.integration.channel.AbstractMessageChannel
All Implemented Interfaces:
org.springframework.beans.factory.BeanNameAware, MessageChannel, BlockingTarget, MessageSource, MessageTarget
Direct Known Subclasses:
AbstractPollableChannel, DirectChannel, PublishSubscribeChannel

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

Base class for MessageChannel implementations providing common properties such as the channel name and DispatcherPolicy. 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.
 
Field Summary
private  AbstractMessageChannel.ChannelInterceptorList interceptors
           
private  org.apache.commons.logging.Log logger
           
private  java.lang.String name
           
 
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 setBeanName(java.lang.String name)
          Set the name of 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
 

Field Detail

logger

private final org.apache.commons.logging.Log logger

name

private volatile java.lang.String name

interceptors

private final AbstractMessageChannel.ChannelInterceptorList interceptors
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

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.


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 BlockingTarget
Specified by:
send in interface MessageTarget
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 BlockingTarget
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.