AbstractEndpoint now has a channelResolver property (initialized in the setBeanFactory(..) method), and therefore the GatewayProxyFactoryBean is no longer BeanFactoryAware directly (inherits from AbstractEndpoint).

This commit is contained in:
Mark Fisher
2008-11-12 02:10:20 +00:00
parent 76834d94ee
commit 4e9d1178da
2 changed files with 14 additions and 20 deletions

View File

@@ -19,6 +19,8 @@ package org.springframework.integration.endpoint;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.integration.channel.BeanFactoryChannelResolver;
import org.springframework.integration.channel.ChannelResolver;
import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.scheduling.TaskScheduler;
import org.springframework.integration.util.LifecycleSupport;
@@ -35,6 +37,8 @@ public abstract class AbstractEndpoint extends LifecycleSupport implements Messa
private volatile BeanFactory beanFactory;
private volatile ChannelResolver channelResolver;
private volatile TaskScheduler taskScheduler;
@@ -42,10 +46,10 @@ public abstract class AbstractEndpoint extends LifecycleSupport implements Messa
this.beanName = beanName;
}
// TODO: make this final (see TODO in GatewayProxyFactoryBean)
public void setBeanFactory(BeanFactory beanFactory) {
public final void setBeanFactory(BeanFactory beanFactory) {
Assert.notNull(beanFactory, "beanFactory must not be null");
this.beanFactory = beanFactory;
this.channelResolver = new BeanFactoryChannelResolver(beanFactory);
TaskScheduler taskScheduler = IntegrationContextUtils.getTaskScheduler(beanFactory);
if (taskScheduler != null) {
this.setTaskScheduler(taskScheduler);
@@ -65,6 +69,10 @@ public abstract class AbstractEndpoint extends LifecycleSupport implements Messa
return this.taskScheduler;
}
protected ChannelResolver getChannelResolver() {
return this.channelResolver;
}
@Override
public String toString() {
return (this.beanName != null) ? this.beanName : super.toString();

View File

@@ -28,14 +28,9 @@ import org.springframework.aop.support.AopUtils;
import org.springframework.beans.SimpleTypeConverter;
import org.springframework.beans.TypeConverter;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.Lifecycle;
import org.springframework.integration.annotation.Gateway;
import org.springframework.integration.channel.BeanFactoryChannelResolver;
import org.springframework.integration.channel.ChannelResolver;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageChannel;
@@ -51,8 +46,7 @@ import org.springframework.util.StringUtils;
*
* @author Mark Fisher
*/
public class GatewayProxyFactoryBean extends AbstractEndpoint implements FactoryBean, MethodInterceptor, BeanClassLoaderAware, BeanFactoryAware,
InitializingBean {
public class GatewayProxyFactoryBean extends AbstractEndpoint implements FactoryBean, MethodInterceptor, BeanClassLoaderAware {
private volatile Class<?> serviceInterface;
@@ -72,8 +66,6 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint implements Factory
private final Map<Method, MessagingGateway> gatewayMap = new HashMap<Method, MessagingGateway>();
private volatile ChannelResolver channelResolver;
private volatile boolean initialized;
private final Object initializationMonitor = new Object();
@@ -137,12 +129,6 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint implements Factory
this.beanClassLoader = beanClassLoader;
}
@Override // TODO: remove this and move channelResolver to parent class
public void setBeanFactory(BeanFactory beanFactory) {
super.setBeanFactory(beanFactory);
this.channelResolver = new BeanFactoryChannelResolver(beanFactory);
}
@Override
protected void onInit() throws Exception {
synchronized (this.initializationMonitor) {
@@ -230,15 +216,15 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint implements Factory
long requestTimeout = this.defaultRequestTimeout;
long replyTimeout = this.defaultReplyTimeout;
if (gatewayAnnotation != null) {
Assert.state(this.channelResolver != null, "ChannelResolver is required");
Assert.state(this.getChannelResolver() != null, "ChannelResolver is required");
String requestChannelName = gatewayAnnotation.requestChannel();
if (StringUtils.hasText(requestChannelName)) {
requestChannel = this.channelResolver.resolveChannelName(requestChannelName);
requestChannel = this.getChannelResolver().resolveChannelName(requestChannelName);
Assert.notNull(requestChannel, "failed to resolve request channel '" + requestChannelName + "'");
}
String replyChannelName = gatewayAnnotation.replyChannel();
if (StringUtils.hasText(replyChannelName)) {
replyChannel = this.channelResolver.resolveChannelName(replyChannelName);
replyChannel = this.getChannelResolver().resolveChannelName(replyChannelName);
Assert.notNull(replyChannel, "failed to resolve reply channel '" + replyChannelName + "'");
}
requestTimeout = gatewayAnnotation.requestTimeout();