Added AbstractMessageConsumingEndpoint. MessageDispatchers now expect MessageConsumer instances as subscribers, and the MessageEndpoint no longer has a send() method or a getSource() method. All consumer endpoints now use 'inputChannel' as the property (instead of source). The MessageBus is less involved in endpoint activation now, since endpoints that need to poll a channel can create, configure, and schedule their own poller.
This commit is contained in:
@@ -23,7 +23,7 @@ import java.io.OutputStream;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.endpoint.AbstractMessageConsumingEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.integration.message.MessagingException;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ByteStreamTarget extends AbstractEndpoint {
|
||||
public class ByteStreamTarget extends AbstractMessageConsumingEndpoint {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
@@ -54,13 +54,13 @@ public class ByteStreamTarget extends AbstractEndpoint {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean sendInternal(Message message) {
|
||||
public void processMessage(Message<?> message) {
|
||||
Object payload = message.getPayload();
|
||||
if (payload == null) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(this.getClass().getSimpleName() + " received null object");
|
||||
}
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (payload instanceof String) {
|
||||
@@ -74,7 +74,6 @@ public class ByteStreamTarget extends AbstractEndpoint {
|
||||
" only supports byte array and String-based messages");
|
||||
}
|
||||
this.stream.flush();
|
||||
return true;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new MessagingException("IO failure occurred in target", e);
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.endpoint.AbstractMessageConsumingEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -41,7 +41,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class CharacterStreamTarget extends AbstractEndpoint {
|
||||
public class CharacterStreamTarget extends AbstractMessageConsumingEndpoint {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
@@ -118,13 +118,13 @@ public class CharacterStreamTarget extends AbstractEndpoint {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendInternal(Message message) {
|
||||
public void processMessage(Message<?> message) {
|
||||
Object payload = message.getPayload();
|
||||
if (payload == null) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("target received null payload");
|
||||
}
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (payload instanceof String) {
|
||||
@@ -143,7 +143,6 @@ public class CharacterStreamTarget extends AbstractEndpoint {
|
||||
writer.newLine();
|
||||
}
|
||||
writer.flush();
|
||||
return true;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new MessagingException("IO failure occurred in target", e);
|
||||
|
||||
@@ -72,10 +72,10 @@ public class ConsoleTargetParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
String channelName = element.getAttribute("channel");
|
||||
if (StringUtils.hasText(channelName)) {
|
||||
builder.addPropertyReference("source", channelName);
|
||||
builder.addPropertyReference("inputChannel", channelName);
|
||||
}
|
||||
else {
|
||||
builder.addPropertyReference("source", this.createDirectChannel(element, parserContext));
|
||||
builder.addPropertyReference("inputChannel", this.createDirectChannel(element, parserContext));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ByteStreamTargetTests {
|
||||
public void testSingleByteArray() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ByteStreamTarget target = new ByteStreamTarget(stream);
|
||||
target.send(new GenericMessage<byte[]>(new byte[] {1,2,3}));
|
||||
target.onMessage(new GenericMessage<byte[]>(new byte[] {1,2,3}));
|
||||
byte[] result = stream.toByteArray();
|
||||
assertEquals(3, result.length);
|
||||
assertEquals(1, result[0]);
|
||||
@@ -63,7 +63,7 @@ public class ByteStreamTargetTests {
|
||||
public void testSingleString() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
ByteStreamTarget target = new ByteStreamTarget(stream);
|
||||
target.send(new StringMessage("foo"));
|
||||
target.onMessage(new StringMessage("foo"));
|
||||
byte[] result = stream.toByteArray();
|
||||
assertEquals(3, result.length);
|
||||
assertEquals("foo", new String(result));
|
||||
|
||||
@@ -50,7 +50,7 @@ public class CharacterStreamTargetTests {
|
||||
public void testSingleString() {
|
||||
StringWriter writer = new StringWriter();
|
||||
CharacterStreamTarget target = new CharacterStreamTarget(writer);
|
||||
target.send(new StringMessage("foo"));
|
||||
target.onMessage(new StringMessage("foo"));
|
||||
assertEquals("foo", writer.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ConsoleTargetParserTests {
|
||||
Charset writerCharset = Charset.forName(((OutputStreamWriter) writer).getEncoding());
|
||||
assertEquals(Charset.defaultCharset(), writerCharset);
|
||||
this.resetStreams();
|
||||
target.send(new StringMessage("foo"));
|
||||
target.onMessage(new StringMessage("foo"));
|
||||
assertEquals("foo", out.toString());
|
||||
assertEquals("", err.toString());
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public class ConsoleTargetParserTests {
|
||||
Charset writerCharset = Charset.forName(((OutputStreamWriter) writer).getEncoding());
|
||||
assertEquals(Charset.forName("UTF-8"), writerCharset);
|
||||
this.resetStreams();
|
||||
target.send(new StringMessage("bar"));
|
||||
target.onMessage(new StringMessage("bar"));
|
||||
assertEquals("bar", out.toString());
|
||||
assertEquals("", err.toString());
|
||||
}
|
||||
@@ -128,7 +128,7 @@ public class ConsoleTargetParserTests {
|
||||
Charset writerCharset = Charset.forName(((OutputStreamWriter) writer).getEncoding());
|
||||
assertEquals(Charset.defaultCharset(), writerCharset);
|
||||
this.resetStreams();
|
||||
target.send(new StringMessage("bad"));
|
||||
target.onMessage(new StringMessage("bad"));
|
||||
assertEquals("", out.toString());
|
||||
assertEquals("bad", err.toString());
|
||||
}
|
||||
@@ -148,7 +148,7 @@ public class ConsoleTargetParserTests {
|
||||
Charset writerCharset = Charset.forName(((OutputStreamWriter) writer).getEncoding());
|
||||
assertEquals(Charset.defaultCharset(), writerCharset);
|
||||
this.resetStreams();
|
||||
target.send(new StringMessage("foo"));
|
||||
target.onMessage(new StringMessage("foo"));
|
||||
assertEquals("foo\n", out.toString());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user