From 09fab742ff0aa2106f567717991a3b4c6b1390e1 Mon Sep 17 00:00:00 2001 From: David Jencks Date: Tue, 9 Feb 2010 19:56:21 +0000 Subject: [PATCH] AMQ-2601 Make amq more blueprint-friendly, move away from spring lifecycle interfaces git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@908182 13f79535-47bb-0310-9956-ffa450edef68 --- activemq-all/pom.xml | 5 +++ activemq-camel/pom.xml | 5 +++ .../camel/component/CamelEndpointLoader.java | 20 +++++++-- activemq-core/pom.xml | 5 +++ .../apache/activemq/broker/BrokerService.java | 17 ++++++++ .../activemq/broker/util/CommandAgent.java | 43 +++++++------------ .../broker/util/LoggingBrokerPlugin.java | 12 ++++-- .../activemq/filter/DestinationMapEntry.java | 11 ++++- .../spring/ActiveMQConnectionFactory.java | 10 ++++- .../spring/ActiveMQXAConnectionFactory.java | 10 ++++- .../activemq/spring/SpringSslContext.java | 11 +++-- .../apache/activemq/util/osgi/Activator.java | 11 ++++- .../activemq/xbean/XBeanBrokerService.java | 16 ++++++- activemq-pool/pom.xml | 5 +++ .../pool/PooledConnectionFactoryBean.java | 33 +++++++------- pom.xml | 6 +++ 16 files changed, 158 insertions(+), 62 deletions(-) diff --git a/activemq-all/pom.xml b/activemq-all/pom.xml index dc98ef55b2..5565eb6876 100644 --- a/activemq-all/pom.xml +++ b/activemq-all/pom.xml @@ -49,6 +49,10 @@ ${pom.groupId} kahadb + + org.apache.geronimo.specs + geronimo-annotation_1.0_spec + @@ -78,6 +82,7 @@ org.apache.geronimo.specs:geronimo-jms_1.1_spec org.apache.geronimo.specs:geronimo-jta_1.0.1B_spec org.apache.geronimo.specs:geronimo-j2ee-management_1.0_spec + org.apache.geronimo.specs:geronimo-annotation_1.0_spec commons-logging:commons-logging-api diff --git a/activemq-camel/pom.xml b/activemq-camel/pom.xml index 856905c9a5..6abd8f9179 100755 --- a/activemq-camel/pom.xml +++ b/activemq-camel/pom.xml @@ -106,6 +106,11 @@ ${pom.groupId} activemq-pool + + org.apache.geronimo.specs + geronimo-annotation_1.0_spec + true + diff --git a/activemq-camel/src/main/java/org/apache/activemq/camel/component/CamelEndpointLoader.java b/activemq-camel/src/main/java/org/apache/activemq/camel/component/CamelEndpointLoader.java index a10e1499f6..7d00b64307 100644 --- a/activemq-camel/src/main/java/org/apache/activemq/camel/component/CamelEndpointLoader.java +++ b/activemq-camel/src/main/java/org/apache/activemq/camel/component/CamelEndpointLoader.java @@ -19,6 +19,8 @@ package org.apache.activemq.camel.component; import java.util.Set; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import javax.jms.Connection; import javax.jms.ConnectionFactory; @@ -37,15 +39,14 @@ import org.apache.camel.component.jms.JmsQueueEndpoint; import org.apache.camel.util.ObjectHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.InitializingBean; /** * A helper bean which populates a {@link CamelContext} with ActiveMQ Queue endpoints * * @version $Revision: 1.1 $ + * @org.apache.xbean.XBean */ -public class CamelEndpointLoader implements InitializingBean, DisposableBean, CamelContextAware { +public class CamelEndpointLoader implements CamelContextAware { private static final transient Log LOG = LogFactory.getLog(CamelEndpointLoader.class); private CamelContext camelContext; private EnhancedConnection connection; @@ -59,6 +60,12 @@ public class CamelEndpointLoader implements InitializingBean, DisposableBean, Ca this.camelContext = camelContext; } + /** + * + * @throws Exception + * @org.apache.xbean.InitMethod + */ + @PostConstruct public void afterPropertiesSet() throws Exception { ObjectHelper.notNull(camelContext, "camelContext"); if (connection == null) { @@ -112,6 +119,13 @@ public class CamelEndpointLoader implements InitializingBean, DisposableBean, Ca } } + + /** + * + * @throws Exception + * @org.apache.xbean.DestroyMethod + */ + @PreDestroy public void destroy() throws Exception { if (connection != null) { connection.close(); diff --git a/activemq-core/pom.xml b/activemq-core/pom.xml index 736fb418e7..a5c48ce757 100755 --- a/activemq-core/pom.xml +++ b/activemq-core/pom.xml @@ -135,6 +135,11 @@ org.apache.geronimo.specs geronimo-j2ee-management_1.0_spec + + org.apache.geronimo.specs + geronimo-annotation_1.0_spec + true + org.apache.geronimo.specs geronimo-jacc_1.1_spec diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java index 1456ec9f9c..06a056d9f0 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java @@ -31,6 +31,9 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import org.apache.activemq.ActiveMQConnectionMetaData; @@ -99,6 +102,7 @@ import org.apache.commons.logging.LogFactory; * which can be used to configure the broker as its lazily created. * * @version $Revision: 1.1 $ + * @org.apache.xbean.XBean */ public class BrokerService implements Service { protected CountDownLatch slaveStartSignal = new CountDownLatch(1); @@ -432,6 +436,13 @@ public class BrokerService implements Service { // Service interface // ------------------------------------------------------------------------- + + /** + * + * @throws Exception + * @org. apache.xbean.InitMethod + */ + @PostConstruct public void start() throws Exception { if (stopped.get() || !started.compareAndSet(false, true)) { // lets just ignore redundant start() calls @@ -507,6 +518,12 @@ public class BrokerService implements Service { } } + /** + * + * @throws Exception + * @org.apache .xbean.DestroyMethod + */ + @PreDestroy public void stop() throws Exception { if (!started.get()) { return; diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/util/CommandAgent.java b/activemq-core/src/main/java/org/apache/activemq/broker/util/CommandAgent.java index bbc8248842..e270a39163 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/util/CommandAgent.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/util/CommandAgent.java @@ -16,6 +16,8 @@ */ package org.apache.activemq.broker.util; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.Destination; @@ -23,16 +25,12 @@ import javax.jms.ExceptionListener; import javax.jms.JMSException; import javax.jms.MessageConsumer; import javax.jms.Session; - import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.Service; import org.apache.activemq.advisory.AdvisorySupport; import org.apache.activemq.util.ServiceStopper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.FactoryBean; -import org.springframework.beans.factory.InitializingBean; /** * An agent which listens to commands on a JMS destination @@ -40,7 +38,7 @@ import org.springframework.beans.factory.InitializingBean; * @version $Revision$ * @org.apache.xbean.XBean */ -public class CommandAgent implements Service, InitializingBean, DisposableBean, FactoryBean, ExceptionListener { +public class CommandAgent implements Service, ExceptionListener { private static final Log LOG = LogFactory.getLog(CommandAgent.class); private String brokerUrl = "vm://localhost"; @@ -53,6 +51,12 @@ public class CommandAgent implements Service, InitializingBean, DisposableBean, private Session session; private MessageConsumer consumer; + /** + * + * @throws Exception + * @org.apache.xbean.InitMethod + */ + @PostConstruct public void start() throws Exception { session = getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); listener = new CommandMessageListener(session); @@ -64,6 +68,12 @@ public class CommandAgent implements Service, InitializingBean, DisposableBean, consumer.setMessageListener(listener); } + /** + * + * @throws Exception + * @org.apache.xbean.DestroyMethod + */ + @PreDestroy public void stop() throws Exception { ServiceStopper stopper = new ServiceStopper(); if (consumer != null) { @@ -93,29 +103,6 @@ public class CommandAgent implements Service, InitializingBean, DisposableBean, stopper.throwFirstException(); } - // the following methods ensure that we are created on startup and the - // lifecycles respected - // TODO there must be a simpler way? - public void afterPropertiesSet() throws Exception { - start(); - } - - public void destroy() throws Exception { - stop(); - } - - public Object getObject() throws Exception { - return this; - } - - public Class getObjectType() { - return getClass(); - } - - public boolean isSingleton() { - return true; - } - // Properties // ------------------------------------------------------------------------- public String getBrokerUrl() { diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/util/LoggingBrokerPlugin.java b/activemq-core/src/main/java/org/apache/activemq/broker/util/LoggingBrokerPlugin.java index cd5a3e02da..5d4c415fca 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/util/LoggingBrokerPlugin.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/util/LoggingBrokerPlugin.java @@ -18,6 +18,8 @@ package org.apache.activemq.broker.util; import java.io.IOException; import java.util.Set; + +import javax.annotation.PostConstruct; import org.apache.activemq.broker.BrokerPluginSupport; import org.apache.activemq.broker.Connection; import org.apache.activemq.broker.ConnectionContext; @@ -44,7 +46,6 @@ import org.apache.activemq.command.TransactionId; import org.apache.activemq.usage.Usage; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.InitializingBean; /** * A simple Broker intercepter which allows you to enable/disable logging. @@ -52,8 +53,7 @@ import org.springframework.beans.factory.InitializingBean; * @org.apache.xbean.XBean */ -public class LoggingBrokerPlugin extends BrokerPluginSupport implements - InitializingBean { +public class LoggingBrokerPlugin extends BrokerPluginSupport { private static final Log LOG = LogFactory.getLog(LoggingBrokerPlugin.class); @@ -65,6 +65,12 @@ public class LoggingBrokerPlugin extends BrokerPluginSupport implements private boolean logProducerEvents = false; private boolean logInternalEvents = false; + /** + * + * @throws Exception + * @org.apache.xbean.InitMethod + */ + @PostConstruct public void afterPropertiesSet() throws Exception { LOG.info("Created LoggingBrokerPlugin: " + this.toString()); } diff --git a/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapEntry.java b/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapEntry.java index 4505d441a3..256481f331 100644 --- a/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapEntry.java +++ b/activemq-core/src/main/java/org/apache/activemq/filter/DestinationMapEntry.java @@ -16,18 +16,19 @@ */ package org.apache.activemq.filter; +import javax.annotation.PostConstruct; import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQTopic; -import org.springframework.beans.factory.InitializingBean; /** * A base class for entry objects used to construct a destination based policy * map. * * @version $Revision: 1.1 $ + * @org.apache.xbean.XBean */ -public abstract class DestinationMapEntry implements InitializingBean, Comparable { +public abstract class DestinationMapEntry implements Comparable { private ActiveMQDestination destination; @@ -64,6 +65,12 @@ public abstract class DestinationMapEntry implements InitializingBean, Comparabl this.destination = destination; } + /** + * + * @throws Exception + * @org.apache.xbean.InitMethod + */ + @PostConstruct public void afterPropertiesSet() throws Exception { if (destination == null) { throw new IllegalArgumentException("You must specify the 'destination' property"); diff --git a/activemq-core/src/main/java/org/apache/activemq/spring/ActiveMQConnectionFactory.java b/activemq-core/src/main/java/org/apache/activemq/spring/ActiveMQConnectionFactory.java index de2aa311bb..eaf08741de 100644 --- a/activemq-core/src/main/java/org/apache/activemq/spring/ActiveMQConnectionFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/spring/ActiveMQConnectionFactory.java @@ -16,8 +16,8 @@ */ package org.apache.activemq.spring; +import javax.annotation.PostConstruct; import org.springframework.beans.factory.BeanNameAware; -import org.springframework.beans.factory.InitializingBean; /** * A Spring enhanced connection @@ -29,11 +29,17 @@ import org.springframework.beans.factory.InitializingBean; * * @version $Revision: $ */ -public class ActiveMQConnectionFactory extends org.apache.activemq.ActiveMQConnectionFactory implements InitializingBean, BeanNameAware { +public class ActiveMQConnectionFactory extends org.apache.activemq.ActiveMQConnectionFactory implements BeanNameAware { private String beanName; private boolean useBeanNameAsClientIdPrefix; + /** + * + * @throws Exception + * @org.apache.xbean.InitMethod + */ + @PostConstruct public void afterPropertiesSet() throws Exception { if (isUseBeanNameAsClientIdPrefix() && getClientIDPrefix() == null) { setClientIDPrefix(getBeanName()); diff --git a/activemq-core/src/main/java/org/apache/activemq/spring/ActiveMQXAConnectionFactory.java b/activemq-core/src/main/java/org/apache/activemq/spring/ActiveMQXAConnectionFactory.java index 8ee2f1b0e3..67a3ae4607 100644 --- a/activemq-core/src/main/java/org/apache/activemq/spring/ActiveMQXAConnectionFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/spring/ActiveMQXAConnectionFactory.java @@ -16,8 +16,8 @@ */ package org.apache.activemq.spring; +import javax.annotation.PostConstruct; import org.springframework.beans.factory.BeanNameAware; -import org.springframework.beans.factory.InitializingBean; /** * A Spring enhanced XA connection @@ -29,11 +29,17 @@ import org.springframework.beans.factory.InitializingBean; * * @version $Revision: $ */ -public class ActiveMQXAConnectionFactory extends org.apache.activemq.ActiveMQXAConnectionFactory implements InitializingBean, BeanNameAware { +public class ActiveMQXAConnectionFactory extends org.apache.activemq.ActiveMQXAConnectionFactory implements BeanNameAware { private String beanName; private boolean useBeanNameAsClientIdPrefix; + /** + * + * @throws Exception + * @org.apache.xbean.InitMethod + */ + @PostConstruct public void afterPropertiesSet() throws Exception { if (isUseBeanNameAsClientIdPrefix() && getClientIDPrefix() == null) { setClientIDPrefix(getBeanName()); diff --git a/activemq-core/src/main/java/org/apache/activemq/spring/SpringSslContext.java b/activemq-core/src/main/java/org/apache/activemq/spring/SpringSslContext.java index 168482d294..0edb90cd73 100644 --- a/activemq-core/src/main/java/org/apache/activemq/spring/SpringSslContext.java +++ b/activemq-core/src/main/java/org/apache/activemq/spring/SpringSslContext.java @@ -24,13 +24,12 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import javax.annotation.PostConstruct; import javax.net.ssl.KeyManager; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; - import org.apache.activemq.broker.SslContext; -import org.springframework.beans.factory.InitializingBean; import org.springframework.core.io.Resource; /** @@ -40,7 +39,7 @@ import org.springframework.core.io.Resource; * * @version $Revision$ */ -public class SpringSslContext extends SslContext implements InitializingBean { +public class SpringSslContext extends SslContext { private String keyStoreType="jks"; private String trustStoreType="jks"; @@ -55,6 +54,12 @@ public class SpringSslContext extends SslContext implements InitializingBean { private String keyStorePassword; private String trustStorePassword; + /** + * + * @throws Exception + * @org.apache.xbean.InitMethod + */ + @PostConstruct public void afterPropertiesSet() throws Exception { keyManagers.addAll(createKeyManagers()); trustManagers.addAll(createTrustManagers()); diff --git a/activemq-core/src/main/java/org/apache/activemq/util/osgi/Activator.java b/activemq-core/src/main/java/org/apache/activemq/util/osgi/Activator.java index 9818bcb412..a1cee6855d 100644 --- a/activemq-core/src/main/java/org/apache/activemq/util/osgi/Activator.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/osgi/Activator.java @@ -39,7 +39,7 @@ import org.osgi.framework.SynchronousBundleListener; /** * An OSGi bundle activator for ActiveMQ which adapts the {@link org.apache.activemq.util.FactoryFinder} - * to the OSGi enviorment. + * to the OSGi environment. * */ public class Activator implements BundleActivator, SynchronousBundleListener, ObjectFactory { @@ -50,6 +50,15 @@ public class Activator implements BundleActivator, SynchronousBundleListener, Ob private final ConcurrentMap bundleWrappers = new ConcurrentHashMap(); private BundleContext bundleContext; + /** + * constructor for use as a blueprint bean rather than bundle activator + * @param bundleContext + */ + public Activator(BundleContext bundleContext) throws Exception { + start(bundleContext); + } + + // ================================================================ // BundleActivator interface impl // ================================================================ diff --git a/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerService.java b/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerService.java index 89ad2c5b58..528e6c7733 100644 --- a/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerService.java +++ b/activemq-core/src/main/java/org/apache/activemq/xbean/XBeanBrokerService.java @@ -18,6 +18,8 @@ package org.apache.activemq.xbean; import java.io.IOException; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.usage.SystemUsage; import org.apache.commons.logging.Log; @@ -45,7 +47,7 @@ import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext; * {code} * @version $Revision: 1.1 $ */ -public class XBeanBrokerService extends BrokerService implements InitializingBean, DisposableBean, ApplicationContextAware { +public class XBeanBrokerService extends BrokerService implements ApplicationContextAware { private static final transient Log LOG = LogFactory.getLog(XBeanBrokerService.class); private boolean start = true; @@ -55,6 +57,12 @@ public class XBeanBrokerService extends BrokerService implements InitializingBea public XBeanBrokerService() { } + /** + * + * @throws Exception + * @org.apache.xbean.InitMethod + */ + @PostConstruct public void afterPropertiesSet() throws Exception { ensureSystemUsageHasStore(); if (start) { @@ -89,6 +97,12 @@ public class XBeanBrokerService extends BrokerService implements InitializingBea } } + /** + * + * @throws Exception + * @org.apache.xbean.DestroyMethod + */ + @PreDestroy public void destroy() throws Exception { stop(); } diff --git a/activemq-pool/pom.xml b/activemq-pool/pom.xml index aa9cdf32b2..c239bb0702 100755 --- a/activemq-pool/pom.xml +++ b/activemq-pool/pom.xml @@ -70,6 +70,11 @@ org.apache.geronimo.specs geronimo-jta_1.0.1B_spec + + org.apache.geronimo.specs + geronimo-annotation_1.0_spec + true + commons-pool commons-pool diff --git a/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnectionFactoryBean.java b/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnectionFactoryBean.java index 9e82620666..4e76d9d71f 100644 --- a/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnectionFactoryBean.java +++ b/activemq-pool/src/main/java/org/apache/activemq/pool/PooledConnectionFactoryBean.java @@ -16,15 +16,13 @@ */ package org.apache.activemq.pool; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import javax.jms.ConnectionFactory; import javax.transaction.TransactionManager; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.pool.ObjectPoolFactory; -import org.springframework.beans.factory.FactoryBean; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.DisposableBean; /** * Simple factory bean used to create a jencks connection pool. @@ -43,8 +41,9 @@ import org.springframework.beans.factory.DisposableBean; * the same value than its resourceName property. This will make sure the transaction manager * maps correctly the connection factory to the recovery process. * + * @org.apache.xbean.XBean */ -public class PooledConnectionFactoryBean implements FactoryBean, InitializingBean, DisposableBean { +public class PooledConnectionFactoryBean { private static final Log LOGGER = LogFactory.getLog(PooledConnectionFactoryBean.class); @@ -56,18 +55,6 @@ public class PooledConnectionFactoryBean implements FactoryBean, InitializingBea private String resourceName; private ObjectPoolFactory poolFactory; - public Object getObject() throws Exception { - return pooledConnectionFactory; - } - - public Class getObjectType() { - return ConnectionFactory.class; - } - - public boolean isSingleton() { - return true; - } - public int getMaxConnections() { return maxConnections; } @@ -116,6 +103,12 @@ public class PooledConnectionFactoryBean implements FactoryBean, InitializingBea this.poolFactory = poolFactory; } + /** + * + * @throws Exception + * @org.apache.xbean.InitMethod + */ + @PostConstruct public void afterPropertiesSet() throws Exception { if (pooledConnectionFactory == null && transactionManager != null && resourceName != null) { try { @@ -164,6 +157,12 @@ public class PooledConnectionFactoryBean implements FactoryBean, InitializingBea } } + /** + * + * @throws Exception + * @org.apache.xbean.DestroyMethod + */ + @PreDestroy public void destroy() throws Exception { if (pooledConnectionFactory != null) { pooledConnectionFactory.stop(); diff --git a/pom.xml b/pom.xml index e08921693b..f81bc1e810 100755 --- a/pom.xml +++ b/pom.xml @@ -368,6 +368,12 @@ geronimo-servlet_2.5_spec 1.2 + + + org.apache.geronimo.specs + geronimo-annotation_1.0_spec + 1.1.1 +