Howdy folks, Here's a patch that brings in the activemq gbean modules into geronimo. It's partly what was in activemq 4.x and integrated into geronimo 1.2-dead merged with the changes in the 3.x branch.
It compiles at least and looks like a reasonable start. Once further integration work gets done we may need to tweak a little more. here's my +1 got get this committed. I guess I just need 3 more. Index: modules/activemq-gbean/project.properties =================================================================== --- modules/activemq-gbean/project.properties (revision 0) +++ modules/activemq-gbean/project.properties (revision 0) @@ -0,0 +1,3 @@ +# ------------------------------------------------------------------- +# Build Properties +# ------------------------------------------------------------------- Property changes on: modules/activemq-gbean/project.properties ___________________________________________________________________ Name: svn:executable + * Index: modules/activemq-gbean/project.xml =================================================================== --- modules/activemq-gbean/project.xml (revision 0) +++ modules/activemq-gbean/project.xml (revision 0) @@ -0,0 +1,104 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + + Copyright 2004 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. +--> +<!-- $Rev: 356052 $ $Date: 2005-12-11 16:41:20 -0600 (Sun, 11 Dec 2005) $ --> +<!DOCTYPE project> +<project> + <pomVersion>3</pomVersion> + <extend>../../etc/project.xml</extend> + + <name>Geronimo :: ActiveMQ :: GBeans</name> + <id>geronimo-activemq-gbean</id> + <shortDescription>ActiveMQ Geronimo / GBean support</shortDescription> + <description>ActiveMQ GBeans used for integration into Apache Geronimo</description> + + <!-- ============ --> + <!-- Dependencies --> + <!-- ============ --> + <dependencies> + + <dependency> + <groupId>incubator-activemq</groupId> + <artifactId>activemq-core</artifactId> + <version>4.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>incubator-activemq</groupId> + <artifactId>activeio-core</artifactId> + <version>3.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>geronimo</groupId> + <artifactId>geronimo-activemq-gbean-management</artifactId> + <version>${pom.currentVersion}</version> + </dependency> + + <dependency> + <groupId>geronimo</groupId> + <artifactId>geronimo-kernel</artifactId> + <version>${pom.currentVersion}</version> + </dependency> + + <dependency> + <groupId>geronimo</groupId> + <artifactId>geronimo-system</artifactId> + <version>${pom.currentVersion}</version> + </dependency> + + <dependency> + <groupId>geronimo</groupId> + <artifactId>geronimo-management</artifactId> + <version>${pom.currentVersion}</version> + </dependency> + + <dependency> + <groupId>geronimo</groupId> + <artifactId>geronimo-j2ee</artifactId> + <version>${pom.currentVersion}</version> + </dependency> + + <dependency> + <groupId>mx4j</groupId> + <artifactId>mx4j</artifactId> + <version>${mx4j_version}</version> + </dependency> + + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>${commons_logging_version}</version> + <url>http://jakarta.apache.org/commons/logging/</url> + </dependency> + + + </dependencies> + + <!-- this module is using m2 directory layout --> + <build> + <sourceDirectory>${basedir}/src/main/java</sourceDirectory> + <unitTestSourceDirectory>${basedir}/src/main/test</unitTestSourceDirectory> + + <unitTest> + <includes> + <include>**/*Test.java</include> + </includes> + </unitTest> + </build> + +</project> Property changes on: modules/activemq-gbean/project.xml ___________________________________________________________________ Name: svn:executable + * Index: modules/activemq-gbean/src/test/java/org/apache/activemq/gbean/ConnectorTest.java =================================================================== --- modules/activemq-gbean/src/test/java/org/apache/activemq/gbean/ConnectorTest.java (revision 0) +++ modules/activemq-gbean/src/test/java/org/apache/activemq/gbean/ConnectorTest.java (revision 0) @@ -0,0 +1,61 @@ +/** + * + * 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.gbean; + +import org.apache.activemq.gbean.TransportConnectorGBeanImpl; + +import junit.framework.TestCase; + +/** + * Tests to ensure that URL parsing and updating doesn't blow up + * + * @version $Revision: 1.0$ + */ +public class ConnectorTest extends TestCase { + public TransportConnectorGBeanImpl test; + + protected void setUp() throws Exception { + } + + public void testURLManipulation() { + test = new TransportConnectorGBeanImpl(null, "foo", "localhost", 1234); + assertEquals("foo://localhost:1234", test.getUrl()); + assertEquals("foo", test.getProtocol()); + assertEquals("localhost", test.getHost()); + assertEquals(1234, test.getPort()); + test.setHost("0.0.0.0"); + assertEquals("foo://0.0.0.0:1234", test.getUrl()); + assertEquals("foo", test.getProtocol()); + assertEquals("0.0.0.0", test.getHost()); + assertEquals(1234, test.getPort()); + test.setPort(8765); + assertEquals("foo://0.0.0.0:8765", test.getUrl()); + assertEquals("foo", test.getProtocol()); + assertEquals("0.0.0.0", test.getHost()); + assertEquals(8765, test.getPort()); + test.setProtocol("bar"); + assertEquals("bar://0.0.0.0:8765", test.getUrl()); + assertEquals("bar", test.getProtocol()); + assertEquals("0.0.0.0", test.getHost()); + assertEquals(8765, test.getPort()); + test = new TransportConnectorGBeanImpl(null, "vm", "localhost", -1); + assertEquals("vm://localhost", test.getUrl()); + assertEquals("vm", test.getProtocol()); + assertEquals("localhost", test.getHost()); + assertEquals(-1, test.getPort()); + } +} Index: modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/BrokerServiceGBean.java =================================================================== --- modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/BrokerServiceGBean.java (revision 0) +++ modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/BrokerServiceGBean.java (revision 0) @@ -0,0 +1,34 @@ +/** + * + * 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.gbean; + +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.gbean.ActiveMQBroker; + +/** + * An interface to the ActiveMQContainerGBean for use by the + * ActiveMQConnectorGBean. + * + * @version $Revision: 1.1.1.1 $ + */ +public interface BrokerServiceGBean extends ActiveMQBroker { + + public abstract BrokerService getBrokerContainer(); + public String getBrokerName(); + + +} \ No newline at end of file Property changes on: modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/BrokerServiceGBean.java ___________________________________________________________________ Name: svn:executable + * Index: modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/BrokerServiceGBeanImpl.java =================================================================== --- modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/BrokerServiceGBeanImpl.java (revision 0) +++ modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/BrokerServiceGBeanImpl.java (revision 0) @@ -0,0 +1,209 @@ +/** + * + * 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.gbean; + +import java.net.URI; + +import javax.sql.DataSource; + +import org.apache.activemq.broker.BrokerFactory; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.store.DefaultPersistenceAdapterFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.geronimo.gbean.GBeanInfo; +import org.apache.geronimo.gbean.GBeanInfoBuilder; +import org.apache.geronimo.gbean.GBeanLifecycle; +import org.apache.geronimo.management.geronimo.JMSManager; +import org.apache.geronimo.management.geronimo.NetworkConnector; +import org.apache.geronimo.system.serverinfo.ServerInfo; + + +/** + * Default implementation of the ActiveMQ Message Server + * + * @version $Revision: 1.1.1.1 $ + */ +public class BrokerServiceGBeanImpl implements GBeanLifecycle, BrokerServiceGBean { + + private Log log = LogFactory.getLog(getClass().getName()); + + private String brokerName; + private String brokerUri; + private BrokerService brokerService; + private ServerInfo serverInfo; + private String dataDirectory; + private DataSourceReference dataSource; + + private String objectName; + private JMSManager manager; + + public BrokerServiceGBeanImpl() { + } + + public synchronized BrokerService getBrokerContainer() { + return brokerService; + } + + public synchronized void doStart() throws Exception { + ClassLoader old = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(BrokerServiceGBeanImpl.class.getClassLoader()); + try { + if (brokerService == null) { + brokerService = createContainer(); + } + DefaultPersistenceAdapterFactory persistenceFactory = (DefaultPersistenceAdapterFactory) brokerService.getPersistenceFactory(); + persistenceFactory.setDataDirectory(serverInfo.resolve(dataDirectory)); + persistenceFactory.setDataSource((DataSource) dataSource.$getResource()); + brokerService.start(); + } finally { + Thread.currentThread().setContextClassLoader(old); + } + } + + protected BrokerService createContainer() throws Exception { + if( brokerUri!=null ) { + BrokerService answer = BrokerFactory.createBroker(new URI(brokerUri)); + brokerName = answer.getBrokerName(); + return answer; + } else { + BrokerService answer = new BrokerService(); + answer.setBrokerName(brokerName); + return answer; + } + } + + public synchronized void doStop() throws Exception { + if (brokerService != null) { + BrokerService temp = brokerService; + brokerService = null; + temp.stop(); + } + } + + public synchronized void doFail() { + if (brokerService != null) { + BrokerService temp = brokerService; + brokerService = null; + try { + temp.stop(); + } catch (Exception e) { + log.info("Caught while closing due to failure: " + e, e); + } + } + } + + public static final GBeanInfo GBEAN_INFO; + + static { + GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("ActiveMQ Message Broker", BrokerServiceGBeanImpl.class, "JMSServer"); + infoFactory.addReference("serverInfo", ServerInfo.class); + infoFactory.addAttribute("brokerName", String.class, true); + infoFactory.addAttribute("brokerUri", String.class, true); + infoFactory.addAttribute("dataDirectory", String.class, true); + infoFactory.addReference("dataSource", DataSourceReference.class); + infoFactory.addAttribute("objectName", String.class, false); + infoFactory.addReference("manager", JMSManager.class); + infoFactory.addInterface(BrokerServiceGBean.class); + // infoFactory.setConstructor(new String[]{"brokerName, brokerUri"}); + GBEAN_INFO = infoFactory.getBeanInfo(); + } + + public static GBeanInfo getGBeanInfo() { + return GBEAN_INFO; + } + + /** + * @return Returns the brokerName. + */ + public String getBrokerName() { + return brokerName; + } + + public String getBrokerUri() { + return brokerUri; + } + + public void setBrokerName(String brokerName) { + this.brokerName = brokerName; + } + + public void setBrokerUri(String brokerUri) { + this.brokerUri = brokerUri; + } + + public ServerInfo getServerInfo() { + return serverInfo; + } + + public void setServerInfo(ServerInfo serverInfo) { + this.serverInfo = serverInfo; + } + + public String getDataDirectory() { + return dataDirectory; + } + + public void setDataDirectory(String dataDir) { + this.dataDirectory = dataDir; + } + + public DataSourceReference getDataSource() { + return dataSource; + } + + public void setDataSource(DataSourceReference dataSource) { + this.dataSource = dataSource; + } + + public String getObjectName() { + return objectName; + } + + public boolean isStateManageable() { + return true; + } + + public boolean isStatisticsProvider() { + return false; // todo: return true once stats are integrated + } + + public boolean isEventProvider() { + return true; + } + + public NetworkConnector[] getConnectors() { + return manager.getConnectorsForContainer(this); + } + + public NetworkConnector[] getConnectors(String protocol) { + return manager.getConnectorsForContainer(this, protocol); + } + + public JMSManager getManager() { + return manager; + } + + public void setManager(JMSManager manager) { + this.manager = manager; + } + + public void setObjectName(String objectName) { + this.objectName = objectName; + } + +} \ No newline at end of file Property changes on: modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/BrokerServiceGBeanImpl.java ___________________________________________________________________ Name: svn:executable + * Index: modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/TransportConnectorGBeanImpl.java =================================================================== --- modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/TransportConnectorGBeanImpl.java (revision 0) +++ modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/TransportConnectorGBeanImpl.java (revision 0) @@ -0,0 +1,168 @@ +/** + * + * 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.gbean; + +import java.net.InetSocketAddress; +import java.net.URI; +import java.net.URISyntaxException; + +import org.apache.activemq.broker.TransportConnector; +import org.apache.activemq.gbean.ActiveMQConnector; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.geronimo.gbean.GBeanInfo; +import org.apache.geronimo.gbean.GBeanInfoBuilder; +import org.apache.geronimo.gbean.GBeanLifecycle; +import org.apache.geronimo.gbean.GConstructorInfo; + +/** + * Default implementation of the ActiveMQ connector + * + * @version $Revision: 1.1.1.1 $ + */ +public class TransportConnectorGBeanImpl implements GBeanLifecycle, ActiveMQConnector { + private Log log = LogFactory.getLog(getClass().getName()); + + private TransportConnector transportConnector; + private BrokerServiceGBean brokerService; + + private String protocol; + private String host; + private int port; + private String path; + private String query; + private String urlAsStarted; + + public TransportConnectorGBeanImpl(BrokerServiceGBean brokerService, String protocol, String host, int port) { + this.brokerService = brokerService; + this.protocol = protocol; + this.host = host; + this.port = port; + } + + public String getProtocol() { + return protocol; + } + + public void setProtocol(String protocol) { + this.protocol = protocol; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public String getQuery() { + return query; + } + + public void setQuery(String query) { + this.query = query; + } + + public String getUrl() { + try { + return new URI(protocol, null, host, port, path, query, null).toString(); + } catch (URISyntaxException e) { + throw new IllegalStateException("Attributes don't form a valid URI: "+protocol+"://"+host+":"+port+"/"+path+"?"+query); + } + } + + public InetSocketAddress getListenAddress() { + try { + return transportConnector.getServer().getSocketAddress(); + } catch (Throwable e) { + log.debug("Failure to determine ListenAddress: "+e,e); + return null; + } + } + + public synchronized void doStart() throws Exception { + ClassLoader old = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(BrokerServiceGBeanImpl.class.getClassLoader()); + try { + if (transportConnector == null) { + urlAsStarted = getUrl(); + transportConnector = createBrokerConnector(urlAsStarted); + transportConnector.start(); + } + } finally { + Thread.currentThread().setContextClassLoader(old); + } + } + + public synchronized void doStop() throws Exception { + if (transportConnector != null) { + TransportConnector temp = transportConnector; + transportConnector = null; + temp.stop(); + } + } + + public synchronized void doFail() { + if (transportConnector != null) { + TransportConnector temp = transportConnector; + transportConnector = null; + try { + temp.stop(); + } + catch (Exception e) { + log.info("Caught while closing due to failure: " + e, e); + } + } + } + + protected TransportConnector createBrokerConnector(String url) throws Exception { + return brokerService.getBrokerContainer().addConnector(url); + } + + public static final GBeanInfo GBEAN_INFO; + + static { + GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("ActiveMQ Transport Connector", TransportConnectorGBeanImpl.class, CONNECTOR_J2EE_TYPE); + infoFactory.addAttribute("url", String.class.getName(), false); + infoFactory.addReference("brokerService", BrokerServiceGBean.class); + infoFactory.addInterface(ActiveMQConnector.class, new String[]{"host","port","protocol","path","query"}, + new String[]{"host","port"}); + infoFactory.setConstructor(new GConstructorInfo(new String[]{"brokerService", "protocol", "host", "port"})); + GBEAN_INFO = infoFactory.getBeanInfo(); + } + + public static GBeanInfo getGBeanInfo() { + return GBEAN_INFO; + } +} Property changes on: modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/TransportConnectorGBeanImpl.java ___________________________________________________________________ Name: svn:executable + * Index: modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/DataSourceReference.java =================================================================== --- modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/DataSourceReference.java (revision 0) +++ modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/DataSourceReference.java (revision 0) @@ -0,0 +1,21 @@ +/** + * + * 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.gbean; + +public interface DataSourceReference { + public Object $getResource(); +} Index: modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/management/ActiveMQManagerGBean.java =================================================================== --- modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/management/ActiveMQManagerGBean.java (revision 0) +++ modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/management/ActiveMQManagerGBean.java (revision 0) @@ -0,0 +1,266 @@ +/** + * + * 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.gbean.management; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.apache.activemq.gbean.ActiveMQBroker; +import org.apache.activemq.gbean.ActiveMQConnector; +import org.apache.activemq.gbean.ActiveMQManager; +import org.apache.activemq.gbean.TransportConnectorGBeanImpl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.geronimo.gbean.AbstractName; +import org.apache.geronimo.gbean.AbstractNameQuery; +import org.apache.geronimo.gbean.GBeanData; +import org.apache.geronimo.gbean.GBeanInfo; +import org.apache.geronimo.gbean.GBeanInfoBuilder; +import org.apache.geronimo.gbean.ReferencePatterns; +import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; +import org.apache.geronimo.kernel.GBeanNotFoundException; +import org.apache.geronimo.kernel.Kernel; +import org.apache.geronimo.kernel.config.ConfigurationUtil; +import org.apache.geronimo.kernel.config.EditableConfigurationManager; +import org.apache.geronimo.kernel.config.InvalidConfigException; +import org.apache.geronimo.kernel.proxy.ProxyManager; +import org.apache.geronimo.management.geronimo.JMSBroker; +import org.apache.geronimo.management.geronimo.JMSConnector; +import org.apache.geronimo.management.geronimo.NetworkConnector; + +/** + * Implementation of the ActiveMQ management interface. These are the ActiveMQ + * management features available at runtime. + * + * @version $Revision: 1.0$ + */ +public class ActiveMQManagerGBean implements ActiveMQManager { + private static final Log log = LogFactory.getLog(ActiveMQManagerGBean.class.getName()); + private Kernel kernel; + private String objectName; + + public ActiveMQManagerGBean(Kernel kernel, String objectName) { + this.kernel = kernel; + this.objectName = objectName; + } + + public String getProductName() { + return "ActiveMQ"; + } + + public String getObjectName() { + return objectName; + } + + public boolean isEventProvider() { + return false; + } + + public boolean isStateManageable() { + return true; + } + + public boolean isStatisticsProvider() { + return false; + } + + public Object[] getContainers() { + ProxyManager proxyManager = kernel.getProxyManager(); + AbstractNameQuery query = new AbstractNameQuery(ActiveMQBroker.class.getName()); + Set names = kernel.listGBeans(query); + ActiveMQBroker[] results = new ActiveMQBroker[names.size()]; + int i=0; + for (Iterator it = names.iterator(); it.hasNext(); i++) { + AbstractName name = (AbstractName) it.next(); + results[i] = (ActiveMQBroker) proxyManager.createProxy(name, ActiveMQBroker.class.getClassLoader()); + } + return results; + } + + public String[] getSupportedProtocols() { + // see files in modules/core/src/conf/META-INF/services/org/activemq/transport/server/ + return new String[]{ "tcp", "stomp", "vm", "peer", "udp", "multicast", "failover"}; + } + + public NetworkConnector[] getConnectors() { + ProxyManager proxyManager = kernel.getProxyManager(); + AbstractNameQuery query = new AbstractNameQuery(ActiveMQConnector.class.getName()); + Set names = kernel.listGBeans(query); + ActiveMQConnector[] results = new ActiveMQConnector[names.size()]; + int i=0; + for (Iterator it = names.iterator(); it.hasNext(); i++) { + AbstractName name = (AbstractName) it.next(); + results[i] = (ActiveMQConnector) proxyManager.createProxy(name, ActiveMQConnector.class.getClassLoader()); + } + return results; + } + + public NetworkConnector[] getConnectors(String protocol) { + if(protocol == null) { + return getConnectors(); + } + List result = new ArrayList(); + ProxyManager proxyManager = kernel.getProxyManager(); + AbstractNameQuery query = new AbstractNameQuery(ActiveMQConnector.class.getName()); + Set names = kernel.listGBeans(query); + for (Iterator it = names.iterator(); it.hasNext();) { + AbstractName name = (AbstractName) it.next(); + try { + if (kernel.getAttribute(name, "protocol").equals(protocol)) { + result.add(proxyManager.createProxy(name, ActiveMQConnector.class.getClassLoader())); + } + } catch (Exception e) { + log.error("Unable to check the protocol for a connector", e); + } + } + return (ActiveMQConnector[]) result.toArray(new ActiveMQConnector[names.size()]); + } + + public NetworkConnector[] getConnectorsForContainer(Object broker) { + AbstractName containerName = kernel.getAbstractNameFor(broker); + ProxyManager mgr = kernel.getProxyManager(); + try { + List results = new ArrayList(); + AbstractNameQuery query = new AbstractNameQuery(ActiveMQConnector.class.getName()); + Set set = kernel.listGBeans(query); // all Jetty connectors + for (Iterator it = set.iterator(); it.hasNext();) { + AbstractName name = (AbstractName) it.next(); // a single Jetty connector + GBeanData data = kernel.getGBeanData(name); + ReferencePatterns refs = data.getReferencePatterns("activeMQContainer"); + if (containerName.equals(refs.getAbstractName())) { + results.add(mgr.createProxy(name, ActiveMQConnector.class.getClassLoader())); + } + } + return (ActiveMQConnector[]) results.toArray(new ActiveMQConnector[results.size()]); + } catch (Exception e) { + throw (IllegalArgumentException) new IllegalArgumentException("Unable to look up connectors for ActiveMQ broker '"+containerName).initCause(e); + } + } + + public NetworkConnector[] getConnectorsForContainer(Object broker, String protocol) { + if(protocol == null) { + return getConnectorsForContainer(broker); + } + AbstractName containerName = kernel.getAbstractNameFor(broker); + ProxyManager mgr = kernel.getProxyManager(); + try { + List results = new ArrayList(); + AbstractNameQuery query = new AbstractNameQuery(ActiveMQConnector.class.getName()); + Set set = kernel.listGBeans(query); // all Jetty connectors + for (Iterator it = set.iterator(); it.hasNext();) { + AbstractName name = (AbstractName) it.next(); // a single Jetty connector + GBeanData data = kernel.getGBeanData(name); + ReferencePatterns refs = data.getReferencePatterns("activeMQContainer"); + if(containerName.equals(refs.getAbstractName())) { + try { + String testProtocol = (String) kernel.getAttribute(name, "protocol"); + if(testProtocol != null && testProtocol.equals(protocol)) { + results.add(mgr.createProxy(name, ActiveMQConnector.class.getClassLoader())); + } + } catch (Exception e) { + log.error("Unable to look up protocol for connector '"+name+"'",e); + } + break; + } + } + return (ActiveMQConnector[]) results.toArray(new ActiveMQConnector[results.size()]); + } catch (Exception e) { + throw (IllegalArgumentException)new IllegalArgumentException("Unable to look up connectors for ActiveMQ broker '"+containerName +"': ").initCause(e); + } + } + + /** + * Creates a new connector, and returns the ObjectName for it. Note that + * the connector may well require further customization before being fully + * functional (e.g. SSL settings for a secure connector). + */ + public JMSConnector addConnector(JMSBroker broker, String uniqueName, String protocol, String host, int port) { + AbstractName brokerAbstractName = kernel.getAbstractNameFor(broker); + AbstractName name = kernel.getNaming().createChildName(brokerAbstractName, uniqueName, NameFactory.GERONIMO_SERVICE); + GBeanData connector = new GBeanData(name, TransportConnectorGBeanImpl.GBEAN_INFO); + //todo: if SSL is supported, need to add more properties or use a different GBean? + connector.setAttribute("protocol", protocol); + connector.setAttribute("host", host); + connector.setAttribute("port", new Integer(port)); + connector.setReferencePattern("activeMQContainer", brokerAbstractName); + EditableConfigurationManager mgr = ConfigurationUtil.getEditableConfigurationManager(kernel); + if(mgr != null) { + try { + mgr.addGBeanToConfiguration(brokerAbstractName.getArtifact(), connector, false); + return (JMSConnector) kernel.getProxyManager().createProxy(name, ActiveMQConnector.class.getClassLoader()); + } catch (InvalidConfigException e) { + log.error("Unable to add GBean", e); + return null; + } finally { + ConfigurationUtil.releaseConfigurationManager(kernel, mgr); + } + } else { + log.warn("The ConfigurationManager in the kernel does not allow editing"); + return null; + } + } + + public void removeConnector(AbstractName connectorName) { + try { + GBeanInfo info = kernel.getGBeanInfo(connectorName); + boolean found = false; + Set intfs = info.getInterfaces(); + for (Iterator it = intfs.iterator(); it.hasNext();) { + String intf = (String) it.next(); + if (intf.equals(ActiveMQConnector.class.getName())) { + found = true; + } + } + if (!found) { + throw new GBeanNotFoundException(connectorName); + } + EditableConfigurationManager mgr = ConfigurationUtil.getEditableConfigurationManager(kernel); + if (mgr != null) { + try { + mgr.removeGBeanFromConfiguration(connectorName.getArtifact(), connectorName); + } catch (InvalidConfigException e) { + log.error("Unable to add GBean", e); + } finally { + ConfigurationUtil.releaseConfigurationManager(kernel, mgr); + } + } else { + log.warn("The ConfigurationManager in the kernel does not allow editing"); + } + } catch (GBeanNotFoundException e) { + log.warn("No such GBean '" + connectorName + "'"); //todo: what if we want to remove a failed GBean? + } catch (Exception e) { + log.error(e); + } + } + + public static final GBeanInfo GBEAN_INFO; + + static { + GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("ActiveMQ Manager", ActiveMQManagerGBean.class); + infoFactory.addAttribute("kernel", Kernel.class, false); + infoFactory.addAttribute("objectName", String.class, false); + infoFactory.addInterface(ActiveMQManager.class); + infoFactory.setConstructor(new String[]{"kernel", "objectName"}); + GBEAN_INFO = infoFactory.getBeanInfo(); + } + + public static GBeanInfo getGBeanInfo() { + return GBEAN_INFO; + } +} Index: modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/package.html =================================================================== --- modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/package.html (revision 0) +++ modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/package.html (revision 0) @@ -0,0 +1,11 @@ +<html> +<head> +</head> +<body> + +<p> + The JMS container using GBeaps for deployment in Geronimo or other JSR 77/88 based containers +</p> + +</body> +</html> Property changes on: modules/activemq-gbean/src/main/java/org/apache/activemq/gbean/package.html ___________________________________________________________________ Name: svn:executable + * Index: modules/activemq-gbean/pom.xml =================================================================== --- modules/activemq-gbean/pom.xml (revision 0) +++ modules/activemq-gbean/pom.xml (revision 0) @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<!-- $Rev: 411333 $ $Date: 2006-06-02 18:35:57 -0500 (Fri, 02 Jun 2006) $ --> +<project + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/POM/4.0.0"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.geronimo.modules</groupId> + <artifactId>modules-parent</artifactId> + <version>1.2-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>geronimo-activemq-gbean</artifactId> + <version>${geronimoVersion}</version> + <name>ActiveMQ :: GBeans</name> + <description>Geronimo ActiveMQ Integration</description> + + <dependencies> + + <dependency> + <groupId>incubator-activemq</groupId> + <artifactId>activemq-core</artifactId> + <version>4.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>incubator-activemq</groupId> + <artifactId>activeio-core</artifactId> + <version>3.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.geronimo.modules</groupId> + <artifactId>geronimo-activemq-gbean-management</artifactId> + </dependency> + <dependency> + <groupId>org.apache.geronimo.modules</groupId> + <artifactId>geronimo-kernel</artifactId> + </dependency> + <dependency> + <groupId>org.apache.geronimo.modules</groupId> + <artifactId>geronimo-system</artifactId> + </dependency> + <dependency> + <groupId>org.apache.geronimo.modules</groupId> + <artifactId>geronimo-management</artifactId> + </dependency> + <dependency> + <groupId>org.apache.geronimo.modules</groupId> + <artifactId>geronimo-j2ee</artifactId> + </dependency> + + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + + <dependency> + <groupId>mx4j</groupId> + <artifactId>mx4j</artifactId> + </dependency> + + </dependencies> + +</project> Index: modules/activemq-gbean-management/project.properties =================================================================== --- modules/activemq-gbean-management/project.properties (revision 0) +++ modules/activemq-gbean-management/project.properties (revision 0) @@ -0,0 +1,3 @@ +# ------------------------------------------------------------------- +# Build Properties +# ------------------------------------------------------------------- Property changes on: modules/activemq-gbean-management/project.properties ___________________________________________________________________ Name: svn:executable + * Index: modules/activemq-gbean-management/project.xml =================================================================== --- modules/activemq-gbean-management/project.xml (revision 0) +++ modules/activemq-gbean-management/project.xml (revision 0) @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!DOCTYPE project> +<project> + <pomVersion>3</pomVersion> + <extend>../../etc/project.xml</extend> + + <name>Geronimo :: ActiveMQ :: GBean Interfaces</name> + <id>geronimo-activemq-gbean-management</id> + <shortDescription>Geronimo / GBean management support</shortDescription> + <description>ActiveMQ management interfaces used for integration into Apache Geronimo</description> + + <!-- ============ --> + <!-- Dependencies --> + <!-- ============ --> + <dependencies> + + <dependency> + <groupId>geronimo</groupId> + <artifactId>geronimo-management</artifactId> + <version>${pom.currentVersion}</version> + </dependency> + + </dependencies> + + <!-- this module is using m2 directory layout --> + <build> + <sourceDirectory>${basedir}/src/main/java</sourceDirectory> + <unitTestSourceDirectory>${basedir}/src/main/test</unitTestSourceDirectory> + + <unitTest> + <includes> + <include>**/*Test.java</include> + </includes> + </unitTest> + </build> + +</project> Property changes on: modules/activemq-gbean-management/project.xml ___________________________________________________________________ Name: svn:executable + * Index: modules/activemq-gbean-management/src/main/java/org/apache/activemq/gbean/ActiveMQConnector.java =================================================================== --- modules/activemq-gbean-management/src/main/java/org/apache/activemq/gbean/ActiveMQConnector.java (revision 0) +++ modules/activemq-gbean-management/src/main/java/org/apache/activemq/gbean/ActiveMQConnector.java (revision 0) @@ -0,0 +1,34 @@ +/** + * + * 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.gbean; + +import org.apache.geronimo.management.geronimo.JMSConnector; + +/** + * The GBean interface for the ActiveMQ network connector GBean + * + * @version $Revision: 1.0$ + */ +public interface ActiveMQConnector extends JMSConnector { + public final static String CONNECTOR_J2EE_TYPE = "JMSConnector"; + + // Additional stuff you can add to an ActiveMQ connector URI + public String getPath(); + public void setPath(String path); + public String getQuery(); + public void setQuery(String query); +} Index: modules/activemq-gbean-management/src/main/java/org/apache/activemq/gbean/ActiveMQManager.java =================================================================== --- modules/activemq-gbean-management/src/main/java/org/apache/activemq/gbean/ActiveMQManager.java (revision 0) +++ modules/activemq-gbean-management/src/main/java/org/apache/activemq/gbean/ActiveMQManager.java (revision 0) @@ -0,0 +1,29 @@ +/** + * + * 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.gbean; + +import org.apache.geronimo.management.J2EEManagedObject; +import org.apache.geronimo.management.geronimo.JMSManager; + +/** + * The GBean interface for the ActiveMQ management GBean. This defines the + * features that should be available to the management interface at runtime. + * + * @version $Revision: 1.0$ + */ +public interface ActiveMQManager extends JMSManager, J2EEManagedObject { +} Index: modules/activemq-gbean-management/src/main/java/org/apache/activemq/gbean/ActiveMQBroker.java =================================================================== --- modules/activemq-gbean-management/src/main/java/org/apache/activemq/gbean/ActiveMQBroker.java (revision 0) +++ modules/activemq-gbean-management/src/main/java/org/apache/activemq/gbean/ActiveMQBroker.java (revision 0) @@ -0,0 +1,30 @@ +/** + * + * 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.gbean; + +import org.apache.geronimo.management.geronimo.JMSBroker; + +/** + * The management interface for the ActiveMQ broker GBean. + * This is separate from ActiveMQContainer because that interface has hard + * links to code in activemq-core, yet we still want to be able to + * distinguish ActiveMQ brokers from non-ActiveMQ JMS brokers. + * + * @version $Revision: 1.0$ + */ +public interface ActiveMQBroker extends JMSBroker { +} Index: modules/activemq-gbean-management/src/main/java/org/apache/activemq/gbean/package.html =================================================================== --- modules/activemq-gbean-management/src/main/java/org/apache/activemq/gbean/package.html (revision 0) +++ modules/activemq-gbean-management/src/main/java/org/apache/activemq/gbean/package.html (revision 0) @@ -0,0 +1,12 @@ +<html> +<head> +</head> +<body> + +<p> + The management API for ActiveMQ, when run in a + container like Geronimo +</p> + +</body> +</html> Property changes on: modules/activemq-gbean-management/src/main/java/org/apache/activemq/gbean/package.html ___________________________________________________________________ Name: svn:executable + * Index: modules/activemq-gbean-management/pom.xml =================================================================== --- modules/activemq-gbean-management/pom.xml (revision 0) +++ modules/activemq-gbean-management/pom.xml (revision 0) @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<!-- $Rev: 411333 $ $Date: 2006-06-02 18:35:57 -0500 (Fri, 02 Jun 2006) $ --> +<project + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://maven.apache.org/POM/4.0.0"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.geronimo.modules</groupId> + <artifactId>modules-parent</artifactId> + <version>1.2-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>geronimo-activemq-gbean-management</artifactId> + <version>${geronimoVersion}</version> + <name>Geronimo :: ActiveMQ :: GBean Interfaces</name> + <description>ActiveMQ Management Interfaces used by Geronimo</description> + + <dependencies> + + <dependency> + <groupId>org.apache.geronimo.modules</groupId> + <artifactId>geronimo-management</artifactId> + </dependency> + <dependency> + <groupId>backport-util-concurrent</groupId> + <artifactId>backport-util-concurrent</artifactId> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </dependency> + + </dependencies> +</project> -- Regards, Hiram
