From 4e9d1178dafb736a21d2a56a02de305e9ad43b21 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Wed, 12 Nov 2008 02:10:20 +0000 Subject: [PATCH] AbstractEndpoint now has a channelResolver property (initialized in the setBeanFactory(..) method), and therefore the GatewayProxyFactoryBean is no longer BeanFactoryAware directly (inherits from AbstractEndpoint). --- .../endpoint/AbstractEndpoint.java | 12 ++++++++-- .../gateway/GatewayProxyFactoryBean.java | 22 ++++--------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/AbstractEndpoint.java b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/AbstractEndpoint.java index 415730ebc3..ef3fc54416 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/AbstractEndpoint.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/AbstractEndpoint.java @@ -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(); diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java index 097c01fab2..0531a926c5 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java @@ -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 gatewayMap = new HashMap(); - 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();