diff --git a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java index ba6bf2a5cb..3ca7036f35 100644 --- a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java +++ b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/FileWritingMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 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. @@ -25,7 +25,6 @@ import java.nio.charset.Charset; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.InitializingBean; import org.springframework.core.io.Resource; import org.springframework.integration.core.Message; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; @@ -57,7 +56,7 @@ import org.springframework.util.FileCopyUtils; * @author Iwein Fuld * @author Alex Peters */ -public class FileWritingMessageHandler extends AbstractReplyProducingMessageHandler implements InitializingBean { +public class FileWritingMessageHandler extends AbstractReplyProducingMessageHandler { private static final String TEMPORARY_FILE_SUFFIX =".writing"; @@ -136,7 +135,8 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand this.charset = Charset.forName(charset); } - public void afterPropertiesSet() { + @Override + public final void onInit() { if (!this.destinationDirectory.exists() && this.autoCreateDirectory) { this.destinationDirectory.mkdirs(); } diff --git a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java index d7f6839f99..2f6d339e04 100644 --- a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java +++ b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 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. @@ -29,7 +29,6 @@ import javax.jms.TemporaryQueue; import javax.jms.TemporaryTopic; import javax.jms.Topic; -import org.springframework.beans.factory.InitializingBean; import org.springframework.integration.core.Message; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; @@ -51,7 +50,7 @@ import org.springframework.util.Assert; * @author Arjen Poutsma * @author Juergen Hoeller */ -public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler implements InitializingBean { +public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler { private volatile Destination requestDestination; @@ -265,7 +264,8 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler imp return session.createTemporaryQueue(); } - public void afterPropertiesSet() { + @Override + public final void onInit() { synchronized (this.initializationMonitor) { if (this.initialized) { return; diff --git a/org.springframework.integration.jmx/src/main/java/org/springframework/integration/jmx/NotificationPublishingMessageHandler.java b/org.springframework.integration.jmx/src/main/java/org/springframework/integration/jmx/NotificationPublishingMessageHandler.java index 10194c29b7..a6c8a1f742 100644 --- a/org.springframework.integration.jmx/src/main/java/org/springframework/integration/jmx/NotificationPublishingMessageHandler.java +++ b/org.springframework.integration.jmx/src/main/java/org/springframework/integration/jmx/NotificationPublishingMessageHandler.java @@ -22,8 +22,6 @@ import javax.management.MalformedObjectNameException; import javax.management.Notification; import javax.management.ObjectName; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.InitializingBean; @@ -52,8 +50,6 @@ public class NotificationPublishingMessageHandler extends AbstractMessageHandler private volatile String defaultNotificationType; - private volatile ListableBeanFactory beanFactory; - public NotificationPublishingMessageHandler(ObjectName objectName) { Assert.notNull(objectName, "JMX ObjectName is required"); @@ -91,14 +87,11 @@ public class NotificationPublishingMessageHandler extends AbstractMessageHandler this.defaultNotificationType = defaultNotificationType; } - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - Assert.isTrue(beanFactory instanceof ListableBeanFactory, "A ListableBeanFactory is required."); - this.beanFactory = (ListableBeanFactory) beanFactory; - } - - public void afterPropertiesSet() throws Exception { + @Override + public final void onInit() throws Exception { + Assert.isTrue(this.getBeanFactory() instanceof ListableBeanFactory, "A ListableBeanFactory is required."); Map exporters = BeanFactoryUtils.beansOfTypeIncludingAncestors( - this.beanFactory, MBeanExporter.class); + (ListableBeanFactory) this.getBeanFactory(), MBeanExporter.class); Assert.isTrue(exporters.size() == 1, "No unique MBeanExporter is available in the current context (found " + exporters.size() + ")."); diff --git a/org.springframework.integration.jmx/src/main/java/org/springframework/integration/jmx/OperationInvokingMessageHandler.java b/org.springframework.integration.jmx/src/main/java/org/springframework/integration/jmx/OperationInvokingMessageHandler.java index 306df1dddb..68e20b0e3e 100644 --- a/org.springframework.integration.jmx/src/main/java/org/springframework/integration/jmx/OperationInvokingMessageHandler.java +++ b/org.springframework.integration.jmx/src/main/java/org/springframework/integration/jmx/OperationInvokingMessageHandler.java @@ -99,7 +99,8 @@ public class OperationInvokingMessageHandler extends AbstractReplyProducingMessa this.defaultOperationName = defaultOperationName; } - public void afterPropertiesSet() { + @Override + public final void onInit() { Assert.notNull(this.server, "MBeanServer is required."); } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/aggregator/AbstractMessageBarrierHandler.java b/org.springframework.integration/src/main/java/org/springframework/integration/aggregator/AbstractMessageBarrierHandler.java index aaef44033b..61d1130fab 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/aggregator/AbstractMessageBarrierHandler.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/aggregator/AbstractMessageBarrierHandler.java @@ -27,11 +27,9 @@ import java.util.concurrent.ScheduledFuture; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.integration.channel.MessageChannelTemplate; -import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.core.Message; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.core.MessageHeaders; @@ -108,8 +106,6 @@ public abstract class AbstractMessageBarrierHandler reaperFutureTask; private volatile boolean initialized; @@ -173,25 +169,19 @@ public abstract class AbstractMessageBarrierHandler 0) { @@ -216,8 +206,8 @@ public abstract class AbstractMessageBarrierHandler keysInBuffer = new DelayQueue(); - private volatile TaskScheduler taskScheduler; private volatile ScheduledFuture reaperFutureTask; private volatile long reaperInterval = DEFAULT_REAPER_INTERVAL; private volatile long timeout = DEFAULT_TIMEOUT; @@ -130,7 +128,7 @@ public class CorrelatingMessageHandler extends AbstractMessageHandler } public void setTaskScheduler(TaskScheduler taskScheduler) { - this.taskScheduler = taskScheduler; + super.setTaskScheduler(taskScheduler); } public void setTimeout(long timeout) { @@ -162,11 +160,6 @@ public class CorrelatingMessageHandler extends AbstractMessageHandler this.sendPartialResultOnTimeout = sendPartialResultOnTimeout; } - public void setBeanFactory(BeanFactory beanFactory) { - if (this.taskScheduler == null) { - this.taskScheduler = IntegrationContextUtils.getRequiredTaskScheduler(beanFactory); - } - } @Override protected void handleMessageInternal(Message message) throws Exception { @@ -215,6 +208,7 @@ public class CorrelatingMessageHandler extends AbstractMessageHandler }; } + @SuppressWarnings("unchecked") private void store(Message message, Object correlationKey) { Message toStore = message; if (!correlationKey.equals(message.getHeaders().getCorrelationId())) { @@ -238,8 +232,8 @@ public class CorrelatingMessageHandler extends AbstractMessageHandler if (this.isRunning()) { return; } - Assert.state(this.taskScheduler != null, "'taskScheduler' must not be null"); - this.reaperFutureTask = this.taskScheduler.scheduleWithFixedDelay( + Assert.state(this.getTaskScheduler() != null, "'taskScheduler' must not be null"); + this.reaperFutureTask = this.getTaskScheduler().scheduleWithFixedDelay( new PrunerTask(), this.reaperInterval); } } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java b/org.springframework.integration/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java index e6256de33e..e73a3c8190 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/handler/AbstractMessageHandler.java @@ -22,6 +22,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.core.Ordered; import org.springframework.integration.channel.ChannelResolutionException; import org.springframework.integration.channel.ChannelResolver; +import org.springframework.integration.context.IntegrationObjectSupport; import org.springframework.integration.core.Message; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.core.MessagingException; @@ -37,7 +38,7 @@ import org.springframework.util.Assert; * * @author Mark Fisher */ -public abstract class AbstractMessageHandler implements MessageHandler, Ordered { +public abstract class AbstractMessageHandler extends IntegrationObjectSupport implements MessageHandler, Ordered { protected final Log logger = LogFactory.getLog(this.getClass()); diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java b/org.springframework.integration/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java index 9cf5804ffa..1eae2ff6a2 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/handler/AbstractReplyProducingMessageHandler.java @@ -16,9 +16,6 @@ package org.springframework.integration.handler; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.integration.channel.BeanFactoryChannelResolver; import org.springframework.integration.channel.ChannelResolver; import org.springframework.integration.channel.MessageChannelTemplate; import org.springframework.integration.core.Message; @@ -37,15 +34,13 @@ import org.springframework.util.Assert; * @author Iwein Fuld */ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessageHandler - implements MessageProducer, BeanFactoryAware { + implements MessageProducer { public static final long DEFAULT_SEND_TIMEOUT = 1000; private MessageChannel outputChannel; - private volatile ChannelResolver channelResolver; - private volatile boolean requiresReply = false; private final MessageChannelTemplate channelTemplate; @@ -77,7 +72,7 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa */ public void setChannelResolver(ChannelResolver channelResolver) { Assert.notNull(channelResolver, "'channelResolver' must not be null"); - this.channelResolver = channelResolver; + super.setChannelResolver(channelResolver); } /** @@ -88,12 +83,6 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa this.requiresReply = requiresReply; } - public void setBeanFactory(BeanFactory beanFactory) { - if (this.channelResolver == null) { - this.channelResolver = new BeanFactoryChannelResolver(beanFactory); - } - } - /** * {@inheritDoc} */ @@ -110,7 +99,7 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa } return; } - MessageChannel replyChannel = resolveReplyChannel(message, this.outputChannel, this.channelResolver); + MessageChannel replyChannel = resolveReplyChannel(message, this.outputChannel, this.getChannelResolver()); MessageHeaders requestHeaders = message.getHeaders(); this.handleResult(result, requestHeaders, replyChannel); } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractChannelNameResolvingMessageRouter.java b/org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractChannelNameResolvingMessageRouter.java index 5a84437257..f001db6b45 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractChannelNameResolvingMessageRouter.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/router/AbstractChannelNameResolvingMessageRouter.java @@ -21,15 +21,10 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.beans.factory.InitializingBean; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.support.ConversionServiceFactory; -import org.springframework.integration.channel.BeanFactoryChannelResolver; import org.springframework.integration.channel.ChannelResolutionException; import org.springframework.integration.channel.ChannelResolver; -import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.core.Message; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.core.MessagingException; @@ -42,24 +37,17 @@ import org.springframework.util.Assert; * @author Mark Fisher * @author Jonas Partner */ -public abstract class AbstractChannelNameResolvingMessageRouter extends AbstractMessageRouter - implements BeanFactoryAware, InitializingBean { - - private volatile ChannelResolver channelResolver; - - private volatile ConversionService conversionService; +public abstract class AbstractChannelNameResolvingMessageRouter extends AbstractMessageRouter { private volatile String prefix; private volatile String suffix; - private volatile BeanFactory beanFactory; - private volatile boolean ignoreChannelNameResolutionFailures; public void setChannelResolver(ChannelResolver channelResolver) { - this.channelResolver = channelResolver; + super.setChannelResolver(channelResolver); } public void setPrefix(String prefix) { @@ -70,29 +58,23 @@ public abstract class AbstractChannelNameResolvingMessageRouter extends Abstract this.suffix = suffix; } - public void setBeanFactory(BeanFactory beanFactory) { - this.beanFactory = beanFactory; - } - public void setIgnoreChannelNameResolutionFailures(boolean ignoreChannelNameResolutionFailures) { this.ignoreChannelNameResolutionFailures = ignoreChannelNameResolutionFailures; } - public void afterPropertiesSet() { - if (this.channelResolver == null) { - Assert.notNull(beanFactory, - "either a ChannelResolver or BeanFactory is required"); - this.channelResolver = new BeanFactoryChannelResolver(this.beanFactory); - } + @Override + public final void onInit() { + Assert.notNull(this.getChannelResolver(), + "either a ChannelResolver or BeanFactory is required"); } protected MessageChannel resolveChannelForName(String channelName, Message message) { - Assert.state(this.channelResolver != null, + Assert.state(this.getChannelResolver() != null, "unable to resolve channel names, no ChannelResolver available"); MessageChannel channel = null; try { - channel = this.channelResolver.resolveChannelName(channelName); + channel = this.getChannelResolver().resolveChannelName(channelName); } catch (ChannelResolutionException e) { if (!ignoreChannelNameResolutionFailures) @@ -141,7 +123,7 @@ public abstract class AbstractChannelNameResolvingMessageRouter extends Abstract else if (channelIndicator instanceof Collection) { addToCollection(channels, (Collection) channelIndicator, message); } - else if (this.getConversionService().canConvert(channelIndicator.getClass(), String.class)) { + else if (this.getRequiredConversionService().canConvert(channelIndicator.getClass(), String.class)) { addChannelFromString(channels, this.getConversionService().convert(channelIndicator, String.class), message); } @@ -165,16 +147,11 @@ public abstract class AbstractChannelNameResolvingMessageRouter extends Abstract } } - private ConversionService getConversionService() { - if (this.conversionService == null) { - if (this.beanFactory != null) { - this.conversionService = IntegrationContextUtils.getConversionService(this.beanFactory); - } - if (this.conversionService == null) { - this.conversionService = ConversionServiceFactory.createDefaultConversionService(); - } + private ConversionService getRequiredConversionService() { + if (this.getConversionService() == null) { + this.setConversionService(ConversionServiceFactory.createDefaultConversionService()); } - return this.conversionService; + return this.getConversionService(); } /** diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/router/RecipientListRouter.java b/org.springframework.integration/src/main/java/org/springframework/integration/router/RecipientListRouter.java index 483ffe56d6..5df5020a02 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/router/RecipientListRouter.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/router/RecipientListRouter.java @@ -90,7 +90,8 @@ public class RecipientListRouter extends AbstractMessageRouter implements Initia this.channelMap = channelMap; } - public void afterPropertiesSet() { + @Override + public final void onInit() { Assert.notEmpty(this.channelMap, "a non-empty channel map is required"); } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/splitter/AbstractMessageSplitter.java b/org.springframework.integration/src/main/java/org/springframework/integration/splitter/AbstractMessageSplitter.java index b70d92cf53..c92726fc9d 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/splitter/AbstractMessageSplitter.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/splitter/AbstractMessageSplitter.java @@ -26,6 +26,7 @@ import org.springframework.integration.core.MessageChannel; import org.springframework.integration.core.MessageHeaders; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; import org.springframework.integration.message.MessageBuilder; +import org.springframework.integration.support.ComponentMetadata; /** * Base class for Message-splitting handlers. @@ -34,9 +35,6 @@ import org.springframework.integration.message.MessageBuilder; */ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMessageHandler { - public static final String COMPONENT_TYPE_LABEL = "splitter"; - - @Override @SuppressWarnings("unchecked") protected final Object handleRequestMessage(Message message) { @@ -93,6 +91,11 @@ public abstract class AbstractMessageSplitter extends AbstractReplyProducingMess } } + @Override + protected void populateComponentMetadata(ComponentMetadata metadata) { + metadata.setComponentType("splitter"); + } + /** * Subclasses must override this method to split the received Message. The * return value may be a Collection or Array. The individual elements may