Moved channelTemplate definition and initialization callback from AbstractEndpoint to the more specific AbstractMessageProducingEndpoint.

This commit is contained in:
Mark Fisher
2008-10-10 00:03:41 +00:00
parent 8368836336
commit cfcbad200a
2 changed files with 8 additions and 36 deletions

View File

@@ -20,9 +20,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.channel.MessageChannelTemplate;
import org.springframework.integration.scheduling.TaskScheduler;
import org.springframework.integration.scheduling.TaskSchedulerAware;
@@ -31,7 +28,7 @@ import org.springframework.integration.scheduling.TaskSchedulerAware;
*
* @author Mark Fisher
*/
public abstract class AbstractEndpoint implements MessageEndpoint, TaskSchedulerAware, BeanNameAware, InitializingBean {
public abstract class AbstractEndpoint implements MessageEndpoint, TaskSchedulerAware, BeanNameAware {
protected final Log logger = LogFactory.getLog(this.getClass());
@@ -39,8 +36,6 @@ public abstract class AbstractEndpoint implements MessageEndpoint, TaskScheduler
private volatile TaskScheduler taskScheduler;
private final MessageChannelTemplate channelTemplate = new MessageChannelTemplate();
public void setBeanName(String name) {
this.name = name;
@@ -54,28 +49,6 @@ public abstract class AbstractEndpoint implements MessageEndpoint, TaskScheduler
this.taskScheduler = taskScheduler;
}
protected MessageChannelTemplate getChannelTemplate() {
return this.channelTemplate;
}
public final void afterPropertiesSet() {
try {
this.initialize();
}
catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new ConfigurationException("failed to initialize endpoint '" + this + "'", e);
}
}
/**
* Subclasses may override this method for custom initialization requirements.
*/
protected void initialize() throws Exception {
}
public String toString() {
return (this.name != null) ? this.name : super.toString();
}

View File

@@ -16,7 +16,9 @@
package org.springframework.integration.endpoint;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.MessageChannelTemplate;
import org.springframework.integration.message.Message;
import org.springframework.util.Assert;
@@ -26,26 +28,23 @@ import org.springframework.util.Assert;
*
* @author Mark Fisher
*/
public abstract class AbstractMessageProducingEndpoint extends AbstractEndpoint {
public abstract class AbstractMessageProducingEndpoint extends AbstractEndpoint implements InitializingBean {
private volatile MessageChannel outputChannel;
private final MessageChannelTemplate channelTemplate = new MessageChannelTemplate();
public void setOutputChannel(MessageChannel outputChannel) {
this.outputChannel = outputChannel;
}
protected MessageChannel getOutputChannel() {
return this.outputChannel;
}
@Override
protected void initialize() {
public void afterPropertiesSet() {
Assert.notNull(this.outputChannel, "outputChannel is required");
}
protected boolean sendMessage(Message<?> message) {
return this.getChannelTemplate().send(message, this.outputChannel);
return this.channelTemplate.send(message, this.outputChannel);
}
}