org.springframework.integration.channel
Class SimpleChannel

java.lang.Object
  extended by org.springframework.integration.channel.SimpleChannel
All Implemented Interfaces:
org.springframework.beans.factory.BeanNameAware, MessageChannel

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

Simple implementation of a message channel. Each Message is placed in a queue whose capacity may be specified upon construction. If no capacity is specified, the DEFAULT_CAPACITY will be used.

Author:
Mark Fisher

Field Summary
static int DEFAULT_CAPACITY
           
 
Constructor Summary
SimpleChannel()
          Create a channel with the default queue capacity.
SimpleChannel(DispatcherPolicy dispatcherPolicy)
          Create a channel with the default queue capacity and the specified dispatcher policy.
SimpleChannel(int capacity)
          Create a channel with the specified queue capacity.
SimpleChannel(int capacity, DispatcherPolicy dispatcherPolicy)
          Create a channel with the specified queue capacity and dispatcher policy.
 
Method Summary
 DispatcherPolicy getDispatcherPolicy()
          Return this channel's dispatcher policy
 java.lang.String getName()
          Return the name of this channel.
 Message receive()
          Receive the message at the head of the queue.
 Message receive(long timeout)
          Receive the message at the head of the queue.
 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 setName(java.lang.String name)
          Set the name of this channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CAPACITY

public static final int DEFAULT_CAPACITY
See Also:
Constant Field Values
Constructor Detail

SimpleChannel

public SimpleChannel(int capacity,
                     DispatcherPolicy dispatcherPolicy)
Create a channel with the specified queue capacity and dispatcher policy.


SimpleChannel

public SimpleChannel(int capacity)
Create a channel with the specified queue capacity.


SimpleChannel

public SimpleChannel(DispatcherPolicy dispatcherPolicy)
Create a channel with the default queue capacity and the specified dispatcher policy.


SimpleChannel

public SimpleChannel()
Create a channel with the default queue capacity.

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

getDispatcherPolicy

public DispatcherPolicy getDispatcherPolicy()
Description copied from interface: MessageChannel
Return this channel's dispatcher policy

Specified by:
getDispatcherPolicy 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

send

public boolean send(Message message)
Send a message on this channel. If the queue is full, 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 boolean send(Message message,
                    long timeout)
Send a message on this channel. If the queue is full, this method will block until either the timeout occurs or the sending thread is interrupted. If the specified timeout is less than 1, the method will return immediately.

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.

receive

public Message receive()
Receive the message at the head of the queue. If the queue is empty, this method will block.

Specified by:
receive in interface MessageChannel
Returns:
the Message at the head of the queue or null if the receiving thread is interrupted.

receive

public Message receive(long timeout)
Receive the message at the head of the queue. If the queue is empty, this method will block until the allotted timeout elapses. If the specified timeout is less than 1, the method will return immediately.

Specified by:
receive in interface MessageChannel
Parameters:
timeout - the timeout in milliseconds
Returns:
the message at the head of the queue or null in case no message is available within the allotted time or the receiving thread is interrupted.