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, BlockingSource, BlockingTarget, MessageSource, MessageTarget
Direct Known Subclasses:
DirectChannel, PublishSubscribeChannel, QueueChannel, ThreadLocalChannel

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
private  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  Message<?> doReceive(long timeout)
          Subclasses must implement this method.
protected abstract  boolean doSend(Message<?> message, long timeout)
          Subclasses must implement this method.
 java.lang.String getName()
          Return the name of this channel.
 Message<?> receive()
          Receive the first available message from this channel.
 Message<?> receive(long timeout)
          Receive the first available message from 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 beanName)
          Set the name of this channel to its bean name.
 void setInterceptors(java.util.List<ChannelInterceptor> interceptors)
          Set the list of channel interceptors.
 void setName(java.lang.String name)
          Set the name of this channel.
 java.lang.String 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.channel.MessageChannel
clear, purge
 

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

setName

public void setName(java.lang.String name)
Set the name of this channel.

Specified by:
setName in interface MessageChannel

getName

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

Specified by:
getName in interface MessageChannel

setBeanName

public void setBeanName(java.lang.String beanName)
Set the name of this channel to its bean name. 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

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.


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.

receive

public final Message<?> receive()
Receive the first available message from this channel. If the channel contains no messages, this method will block.

Specified by:
receive in interface BlockingSource
Specified by:
receive in interface MessageSource
Returns:
the first available message or null if the receiving thread is interrupted.

receive

public final Message<?> receive(long timeout)
Receive the first available message from this channel. If the channel contains no messages, this method will block until the allotted timeout elapses. If the specified timeout is 0, the method will return immediately. If less than zero, it will block indefinitely (see receive()).

Specified by:
receive in interface BlockingSource
Parameters:
timeout - the timeout in milliseconds
Returns:
the first available message or null if no message is available within the allotted time or the receiving 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.


doReceive

protected abstract Message<?> doReceive(long timeout)
Subclasses must implement this method. A non-negative timeout indicates how long to wait if the channel is empty (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 a message is available or the blocking thread is interrupted.