Comments and formatting.
This commit is contained in:
@@ -19,14 +19,20 @@ package org.springframework.integration.channel;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* Base channel interface defining common behavior for message reception and sending.
|
||||
* Base channel interface defining common behavior for message sending and receiving.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public interface MessageChannel {
|
||||
|
||||
/**
|
||||
* Set the name of this channel. Must be unique within a context.
|
||||
*/
|
||||
void setName(String name);
|
||||
|
||||
/**
|
||||
* Return the name of this channel.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
@@ -34,41 +40,40 @@ public interface MessageChannel {
|
||||
*
|
||||
* @param message the {@link Message} to send
|
||||
*
|
||||
* @return <code>true</code> if the message is sent
|
||||
* successfully, <code>false</false> if interrupted
|
||||
* @return <code>true</code> if the message is sent successfully,
|
||||
* <code>false</false> if interrupted
|
||||
*/
|
||||
boolean send(Message message);
|
||||
|
||||
/**
|
||||
* Send a message, blocking until either the message is
|
||||
* accepted or the specified timeout period elapses.
|
||||
* Send a message, blocking until either the message is accepted or the
|
||||
* specified timeout period elapses.
|
||||
*
|
||||
* @param message the {@link Message} to send
|
||||
* @param timeout the timeout in milliseconds
|
||||
*
|
||||
* @return <code>true</code> if the message is sent
|
||||
* successfully, <code>false</false> if the specified
|
||||
* timeout period elapses or the send is interrupted
|
||||
* @return <code>true</code> if the message is sent successfully,
|
||||
* <code>false</false> if the specified timeout period elapses or
|
||||
* the send is interrupted
|
||||
*/
|
||||
boolean send(Message message, long timeout);
|
||||
|
||||
/**
|
||||
* Receive a message, blocking indefinitely if necessary.
|
||||
*
|
||||
* @return the next available {@link Message} or
|
||||
* <code>null</code> if interrupted
|
||||
* @return the next available {@link Message} or <code>null</code> if
|
||||
* interrupted
|
||||
*/
|
||||
Message receive();
|
||||
|
||||
/**
|
||||
* Receive a message, blocking until either a message is
|
||||
* available or the specified timeout period elapses.
|
||||
* Receive a message, blocking until either a message is available or the
|
||||
* specified timeout period elapses.
|
||||
*
|
||||
* @param timeout the timeout in milliseconds
|
||||
*
|
||||
* @return the next available {@link Message} or
|
||||
* <code>null</code> if the specified timeout period
|
||||
* elapses or the message reception is interrupted
|
||||
* @return the next available {@link Message} or <code>null</code> if the
|
||||
* specified timeout period elapses or the message reception is interrupted
|
||||
*/
|
||||
Message receive(long timeout);
|
||||
|
||||
|
||||
@@ -35,17 +35,15 @@ public class PointToPointChannel implements MessageChannel, BeanNameAware {
|
||||
|
||||
private static final int DEFAULT_CAPACITY = 25;
|
||||
|
||||
|
||||
private String name;
|
||||
|
||||
private BlockingQueue<Message> queue;
|
||||
|
||||
private BlockingQueue<Message<?>> queue;
|
||||
|
||||
/**
|
||||
* Create a channel with the specified queue capacity.
|
||||
*/
|
||||
public PointToPointChannel(int capacity) {
|
||||
queue = new LinkedBlockingQueue<Message>(capacity);
|
||||
queue = new LinkedBlockingQueue<Message<?>>(capacity);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,17 +54,29 @@ public class PointToPointChannel implements MessageChannel, BeanNameAware {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the name of this channel.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of this channel.
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public void setBeanName(String beanName) {
|
||||
this.setName(beanName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -173,7 +183,7 @@ public class PointToPointChannel implements MessageChannel, BeanNameAware {
|
||||
while (timeout <= 0 || System.currentTimeMillis() - start < timeout) {
|
||||
Object[] elements = this.queue.toArray();
|
||||
for (int i = (elements.length - 1); i >= 0; i--) {
|
||||
Message m = (Message) elements[i];
|
||||
Message<?> m = (Message<?>) elements[i];
|
||||
if (selector.accept(m) && this.queue.remove(m)) {
|
||||
return m;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user