From 0094ff726991d3870ee8a7c3e2c39879d1c5f7b8 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Sun, 23 Jul 2006 10:05:29 +0000 Subject: [PATCH] added spring dependent connection factory implementations which autodefault the spring bean names for the clientIDPrefix property making it easier to introspect the running system. Fixes AMQ-840 git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@424700 13f79535-47bb-0310-9956-ffa450edef68 --- .../spring/ActiveMQConnectionFactory.java | 55 +++++++++++++++++++ .../spring/ActiveMQXAConnectionFactory.java | 55 +++++++++++++++++++ .../org/apache/activemq/spring/package.html | 9 +++ 3 files changed, 119 insertions(+) create mode 100644 activemq-core/src/main/java/org/apache/activemq/spring/ActiveMQConnectionFactory.java create mode 100644 activemq-core/src/main/java/org/apache/activemq/spring/ActiveMQXAConnectionFactory.java create mode 100755 activemq-core/src/main/java/org/apache/activemq/spring/package.html 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 new file mode 100644 index 0000000000..eaa69adab1 --- /dev/null +++ b/activemq-core/src/main/java/org/apache/activemq/spring/ActiveMQConnectionFactory.java @@ -0,0 +1,55 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.spring; + +import org.springframework.beans.factory.BeanNameAware; +import org.springframework.beans.factory.InitializingBean; + +/** + * A Spring enhanced connection + * factory which will automatically use the Spring bean name as the clientIDPrefix property + * so that connections created have client IDs related to your Spring.xml file for + * easier comprehension from JMX. + * + * @version $Revision: $ + */ +public class ActiveMQConnectionFactory extends org.apache.activemq.ActiveMQConnectionFactory implements InitializingBean, BeanNameAware { + + private String beanName; + private boolean useBeanNameAsClientIdPrefix; + + public void afterPropertiesSet() throws Exception { + if (isUseBeanNameAsClientIdPrefix() && getClientIDPrefix() == null) { + setClientIDPrefix(getBeanName()); + } + } + + public String getBeanName() { + return beanName; + } + + public void setBeanName(String beanName) { + this.beanName = beanName; + } + + public boolean isUseBeanNameAsClientIdPrefix() { + return useBeanNameAsClientIdPrefix; + } + + public void setUseBeanNameAsClientIdPrefix(boolean useBeanNameAsClientIdPrefix) { + this.useBeanNameAsClientIdPrefix = useBeanNameAsClientIdPrefix; + } +} 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 new file mode 100644 index 0000000000..00e524cb4b --- /dev/null +++ b/activemq-core/src/main/java/org/apache/activemq/spring/ActiveMQXAConnectionFactory.java @@ -0,0 +1,55 @@ +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.spring; + +import org.springframework.beans.factory.BeanNameAware; +import org.springframework.beans.factory.InitializingBean; + +/** + * A Spring enhanced XA connection + * factory which will automatically use the Spring bean name as the clientIDPrefix property + * so that connections created have client IDs related to your Spring.xml file for + * easier comprehension from JMX. + * + * @version $Revision: $ + */ +public class ActiveMQXAConnectionFactory extends org.apache.activemq.ActiveMQXAConnectionFactory implements InitializingBean, BeanNameAware { + + private String beanName; + private boolean useBeanNameAsClientIdPrefix; + + public void afterPropertiesSet() throws Exception { + if (isUseBeanNameAsClientIdPrefix() && getClientIDPrefix() == null) { + setClientIDPrefix(getBeanName()); + } + } + + public String getBeanName() { + return beanName; + } + + public void setBeanName(String beanName) { + this.beanName = beanName; + } + + public boolean isUseBeanNameAsClientIdPrefix() { + return useBeanNameAsClientIdPrefix; + } + + public void setUseBeanNameAsClientIdPrefix(boolean useBeanNameAsClientIdPrefix) { + this.useBeanNameAsClientIdPrefix = useBeanNameAsClientIdPrefix; + } +} diff --git a/activemq-core/src/main/java/org/apache/activemq/spring/package.html b/activemq-core/src/main/java/org/apache/activemq/spring/package.html new file mode 100755 index 0000000000..dabe2fc407 --- /dev/null +++ b/activemq-core/src/main/java/org/apache/activemq/spring/package.html @@ -0,0 +1,9 @@ + + + + + +Helper classes for working with the JMS client and Spring. + + +