diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/ApplicationEventSource.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/ApplicationEventSource.java index f36837d44a..df44d61319 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/ApplicationEventSource.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/event/ApplicationEventSource.java @@ -21,9 +21,9 @@ import java.util.List; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; -import org.springframework.integration.channel.ChannelPublisher; import org.springframework.integration.channel.MessageChannel; import org.springframework.integration.message.GenericMessage; +import org.springframework.integration.message.MessageExchangeTemplate; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -33,13 +33,18 @@ import org.springframework.util.CollectionUtils; * * @author Mark Fisher */ -public class ApplicationEventSource extends ChannelPublisher implements ApplicationListener { +public class ApplicationEventSource implements ApplicationListener { + + private final MessageChannel channel; private List> eventTypes = new ArrayList>(); + private final MessageExchangeTemplate messageExchangeTemplate = new MessageExchangeTemplate(); + public ApplicationEventSource(MessageChannel channel) { - super(channel); + Assert.notNull(channel, "channel must not be null"); + this.channel = channel; } @@ -67,7 +72,8 @@ public class ApplicationEventSource extends ChannelPublisher implements Applicat } private boolean sendMessage(ApplicationEvent event) { - return this.publish(new GenericMessage(event)); + return this.messageExchangeTemplate.send( + new GenericMessage(event), this.channel); } } diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/jms/ChannelPublishingJmsListener.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/jms/ChannelPublishingJmsListener.java index 6d03f0fed8..1c1a854389 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/jms/ChannelPublishingJmsListener.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/jms/ChannelPublishingJmsListener.java @@ -18,12 +18,13 @@ package org.springframework.integration.adapter.jms; import javax.jms.MessageListener; -import org.springframework.integration.channel.ChannelPublisher; import org.springframework.integration.channel.MessageChannel; import org.springframework.integration.message.Message; import org.springframework.integration.message.MessageDeliveryException; +import org.springframework.integration.message.MessageExchangeTemplate; import org.springframework.integration.message.MessagingException; import org.springframework.jms.support.converter.MessageConverter; +import org.springframework.util.Assert; /** * JMS {@link MessageListener} implementation that converts the received JMS @@ -31,13 +32,18 @@ import org.springframework.jms.support.converter.MessageConverter; * * @author Mark Fisher */ -public class ChannelPublishingJmsListener extends ChannelPublisher implements MessageListener { +public class ChannelPublishingJmsListener implements MessageListener { + + private final MessageChannel channel; private final MessageConverter converter; + private final MessageExchangeTemplate messageExchangeTemplate = new MessageExchangeTemplate(); + public ChannelPublishingJmsListener(MessageChannel channel, MessageConverter converter) { - super(channel); + Assert.notNull(channel, "channel must not be null"); + this.channel = channel; this.converter = (converter != null && converter instanceof HeaderMappingMessageConverter) ? converter : new HeaderMappingMessageConverter(converter); } @@ -46,8 +52,8 @@ public class ChannelPublishingJmsListener extends ChannelPublisher implements Me public void onMessage(javax.jms.Message jmsMessage) { try { Message messageToSend = (Message) this.converter.fromMessage(jmsMessage); - if (!this.publish(messageToSend)){ - throw new MessageDeliveryException(messageToSend, "failed to send Message to channel: " + this.getChannel()); + if (!this.messageExchangeTemplate.send(messageToSend, this.channel)) { + throw new MessageDeliveryException(messageToSend, "failed to send Message to channel: " + this.channel); } } catch (Exception e) { diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelPublisher.java b/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelPublisher.java deleted file mode 100644 index 62fb11b0ec..0000000000 --- a/org.springframework.integration/src/main/java/org/springframework/integration/channel/ChannelPublisher.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2002-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.integration.channel; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.integration.message.Message; -import org.springframework.util.Assert; - -/** - * Sends to a channel and provides a configurable timeout. Convenient for either - * subclassing or delegation from components that need to publish to a channel. - * - * @author Mark Fisher - */ -public class ChannelPublisher { - - private final Log logger = LogFactory.getLog(this.getClass()); - - private volatile MessageChannel channel; - - private volatile long timeout = 0; - - - public ChannelPublisher() { - } - - public ChannelPublisher(MessageChannel channel) { - this.setChannel(channel); - } - - - public void setChannel(MessageChannel channel) { - Assert.notNull(channel, "channel must not be null"); - this.channel = channel; - } - - public void setTimeout(long timeout) { - this.timeout = timeout; - } - - protected MessageChannel getChannel() { - return this.channel; - } - - public boolean publish(Message message) { - if (this.channel == null) { - if (logger.isWarnEnabled()) { - logger.warn("unable to send message, no channel available"); - } - return false; - } - if (message == null) { - if (logger.isWarnEnabled()) { - logger.warn("null messages are not supported"); - } - return false; - } - return (this.timeout < 0) ? this.channel.send(message) : this.channel.send(message, this.timeout); - } - -}