Hiram R. Chirino 2006-06-17 17:40:40 +00:00
parent 319033f712
commit b3748b4fd8
18 changed files with 12 additions and 1156 deletions

View File

@ -37,7 +37,6 @@ public class FutureResponse {
} }
public Response getResult() throws IOException { public Response getResult() throws IOException {
while (true) {
try { try {
return (Response) responseSlot.take(); return (Response) responseSlot.take();
} }
@ -46,8 +45,7 @@ public class FutureResponse {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Operation interupted: " + e, e); log.debug("Operation interupted: " + e, e);
} }
// throw new InterruptedIOException("Interrupted."); throw new InterruptedIOException("Interrupted.");
}
} }
} }
@ -60,13 +58,10 @@ public class FutureResponse {
} }
public void set(Response result) throws InterruptedIOException { public void set(Response result) throws InterruptedIOException {
try { if( responseSlot.offer(result) ) {
responseSlot.put(result);
} catch (InterruptedException e) {
throw new InterruptedIOException("Interrupted.");
}
if( responseCallback !=null ) { if( responseCallback !=null ) {
responseCallback.onCompletion(this); responseCallback.onCompletion(this);
} }
} }
} }
}

View File

@ -1,57 +0,0 @@
<?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.
-->
<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>incubator-activemq</groupId>
<artifactId>activemq-parent</artifactId>
<version>4.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>activemq-gbean-management</artifactId>
<name>ActiveMQ :: GBean Interfaces</name>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
</build>
<dependencies>
<!-- geronimo legacy dependency -->
<dependency>
<groupId>geronimo</groupId>
<artifactId>geronimo-management</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>backport-util-concurrent</groupId>
<artifactId>backport-util-concurrent</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,9 +0,0 @@
# -------------------------------------------------------------------
# Build Properties
# -------------------------------------------------------------------
maven.multiproject.type=jar
maven.repo.remote=\
http://www.ibiblio.org/maven,\
http://dist.codehaus.org,\
http://people.apache.org/repository

View File

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE project>
<project>
<pomVersion>3</pomVersion>
<extend>${basedir}/../etc/project.xml</extend>
<name>ActiveMQ :: GBean Interfaces</name>
<id>activemq-gbean-management</id>
<shortDescription>Geronimo / GBean management support</shortDescription>
<description>ActiveMQ management interfaces used for integration into Apache Geronimo</description>
<package>org.activemq.gbean</package>
<packageGroups>
<packageGroup>
<title>Geronimo / GBean management support</title>
<packages>org.activemq.gbean</packages>
</packageGroup>
</packageGroups>
<!-- ============ -->
<!-- Dependencies -->
<!-- ============ -->
<dependencies>
<dependency>
<groupId>geronimo</groupId>
<artifactId>geronimo-management</artifactId>
<version>${geronimo_management_version}</version>
</dependency>
</dependencies>
</project>

View File

@ -1,30 +0,0 @@
/**
*
* 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 {
}

View File

@ -1,34 +0,0 @@
/**
*
* 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);
}

View File

@ -1,28 +0,0 @@
/**
*
* 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.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 {
}

View File

@ -1,12 +0,0 @@
<html>
<head>
</head>
<body>
<p>
The management API for ActiveMQ, when run in a
container like Geronimo
</p>
</body>
</html>

View File

@ -1,105 +0,0 @@
<?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.
-->
<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>incubator-activemq</groupId>
<artifactId>activemq-parent</artifactId>
<version>4.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>activemq-gbean</artifactId>
<name>ActiveMQ :: GBeans</name>
<dependencies>
<!-- activemq -->
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>activemq-core</artifactId>
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>activemq-gbean-management</artifactId>
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>activeio-core</artifactId>
</dependency>
<!-- geronimo for legacy repository -->
<dependency>
<groupId>geronimo</groupId>
<artifactId>geronimo-kernel</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>geronimo</groupId>
<artifactId>geronimo-system</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>geronimo</groupId>
<artifactId>geronimo-management</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>geronimo</groupId>
<artifactId>geronimo-j2ee</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
<dependency>
<groupId>mx4j</groupId>
<artifactId>mx4j</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Test.*</include>
</includes>
<excludes>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,9 +0,0 @@
# -------------------------------------------------------------------
# Build Properties
# -------------------------------------------------------------------
maven.multiproject.type=jar
maven.repo.remote=\
http://www.ibiblio.org/maven,\
http://dist.codehaus.org,\
http://people.apache.org/repository

View File

@ -1,82 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE project>
<project>
<pomVersion>3</pomVersion>
<extend>${basedir}/../etc/project.xml</extend>
<name>ActiveMQ :: GBeans</name>
<id>activemq-gbean</id>
<shortDescription>Geronimo / GBean support</shortDescription>
<description>ActiveMQ GBeans used for integration into Apache Geronimo</description>
<package>org.activemq.gbean</package>
<packageGroups>
<packageGroup>
<title>Geronimo / GBean support</title>
<packages>org.activemq.gbean</packages>
</packageGroup>
</packageGroups>
<!-- ============ -->
<!-- Dependencies -->
<!-- ============ -->
<dependencies>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>activemq-core</artifactId>
<version>${pom.currentVersion}</version>
<properties>
<eclipse.dependency>true</eclipse.dependency>
</properties>
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>activeio-core</artifactId>
<version>${activeio_version}</version>
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>activemq-gbean-management</artifactId>
<version>${pom.currentVersion}</version>
<properties>
<eclipse.dependency>true</eclipse.dependency>
</properties>
</dependency>
<dependency> <!-- Used for unit tests -->
<groupId>${pom.groupId}</groupId>
<artifactId>activemq-core-test</artifactId>
<version>${pom.currentVersion}</version>
</dependency>
<dependency>
<groupId>geronimo</groupId>
<artifactId>geronimo-kernel</artifactId>
<version>${geronimo_kernel_version}</version>
</dependency>
<dependency>
<groupId>geronimo</groupId>
<artifactId>geronimo-system</artifactId>
<version>${geronimo_system_version}</version>
</dependency>
<dependency>
<groupId>geronimo</groupId>
<artifactId>geronimo-management</artifactId>
<version>${geronimo_management_version}</version>
</dependency>
<dependency>
<groupId>geronimo</groupId>
<artifactId>geronimo-j2ee</artifactId>
<version>${geronimo_j2ee_version}</version>
</dependency>
<dependency>
<groupId>mx4j</groupId>
<artifactId>mx4j</artifactId>
<version>${mx4j_version}</version>
</dependency>
</dependencies>
</project>

View File

@ -1,34 +0,0 @@
/**
*
* 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();
}

View File

@ -1,167 +0,0 @@
/**
*
* 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.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;
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.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;
}
}

View File

@ -1,21 +0,0 @@
/**
*
* 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();
}

View File

@ -1,167 +0,0 @@
/**
*
* 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"});
infoFactory.setConstructor(new GConstructorInfo(new String[]{"brokerService", "protocol", "host", "port"}));
GBEAN_INFO = infoFactory.getBeanInfo();
}
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
}

View File

@ -1,281 +0,0 @@
/**
*
* 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.Set;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.List;
import java.util.Hashtable;
import javax.management.ObjectName;
import javax.management.MalformedObjectNameException;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.gbean.GBeanQuery;
import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.GBeanNotFoundException;
import org.apache.geronimo.j2ee.management.impl.Util;
import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
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;
/**
* 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;
public ActiveMQManagerGBean(Kernel kernel) {
this.kernel = kernel;
}
public String[] getContainers() {
GBeanQuery query = new GBeanQuery(null, ActiveMQBroker.class.getName());
Set set = kernel.listGBeans(query);
String[] results = new String[set.size()];
int i=0;
for (Iterator it = set.iterator(); it.hasNext();) {
ObjectName name = (ObjectName) it.next();
results[i++] = name.getCanonicalName();
}
return results;
}
public String[] getSupportedProtocols() {
return new String[]{"tcp","vm","ssl", "udp", "nio"};
}
public String[] getConnectors() {
GBeanQuery query = new GBeanQuery(null, ActiveMQConnector.class.getName());
Set set = kernel.listGBeans(query);
String[] results = new String[set.size()];
int i=0;
for (Iterator it = set.iterator(); it.hasNext();) {
ObjectName name = (ObjectName) it.next();
results[i++] = name.getCanonicalName();
}
return results;
}
public String[] getConnectors(String protocol) {
if(protocol == null) {
return getConnectors();
}
GBeanQuery query = new GBeanQuery(null, ActiveMQConnector.class.getName());
Set set = kernel.listGBeans(query);
List results = new ArrayList();
for (Iterator it = set.iterator(); it.hasNext();) {
ObjectName name = (ObjectName) it.next();
try {
String target = (String) kernel.getAttribute(name, "protocol");
if(target != null && target.equals(protocol)) {
results.add(name.getCanonicalName());
}
} catch (Exception e) {
log.error("Unable to look up protocol for connector '"+name+"'",e);
}
}
return (String[]) results.toArray(new String[results.size()]);
}
public String[] getConnectorsForContainer(String broker) {
try {
ObjectName brokerName = ObjectName.getInstance(broker);
List results = new ArrayList();
GBeanQuery query = new GBeanQuery(null, ActiveMQConnector.class.getName());
Set set = kernel.listGBeans(query); // all ActiveMQ connectors
for (Iterator it = set.iterator(); it.hasNext();) {
ObjectName name = (ObjectName) it.next(); // a single ActiveMQ connector
GBeanData data = kernel.getGBeanData(name);
Set refs = data.getReferencePatterns("brokerService");
for (Iterator refit = refs.iterator(); refit.hasNext();) {
ObjectName ref = (ObjectName) refit.next();
if(ref.isPattern()) {
Set matches = kernel.listGBeans(ref);
if(matches.size() != 1) {
log.error("Unable to compare a connector->container reference that's a pattern to a fixed container name: "+ref.getCanonicalName());
} else {
ref = (ObjectName)matches.iterator().next();
if(ref.equals(brokerName)) {
results.add(name.getCanonicalName());
break;
}
}
} else {
if(ref.equals(brokerName)) {
results.add(name.getCanonicalName());
break;
}
}
}
}
return (String[]) results.toArray(new String[results.size()]);
} catch (Exception e) {
throw new IllegalArgumentException("Unable to look up connectors for broker '"+broker+"': "+e);
}
}
public String[] getConnectorsForContainer(String broker, String protocol) {
if(protocol == null) {
return getConnectorsForContainer(broker);
}
try {
ObjectName brokerName = ObjectName.getInstance(broker);
List results = new ArrayList();
GBeanQuery query = new GBeanQuery(null, ActiveMQConnector.class.getName());
Set set = kernel.listGBeans(query); // all ActiveMQ connectors
for (Iterator it = set.iterator(); it.hasNext();) {
ObjectName name = (ObjectName) it.next(); // a single ActiveMQ connector
GBeanData data = kernel.getGBeanData(name);
Set refs = data.getReferencePatterns("brokerService");
for (Iterator refit = refs.iterator(); refit.hasNext();) {
ObjectName ref = (ObjectName) refit.next();
boolean match = false;
if(ref.isPattern()) {
Set matches = kernel.listGBeans(ref);
if(matches.size() != 1) {
log.error("Unable to compare a connector->container reference that's a pattern to a fixed container name: "+ref.getCanonicalName());
} else {
ref = (ObjectName)matches.iterator().next();
if(ref.equals(brokerName)) {
match = true;
}
}
} else {
if(ref.equals(brokerName)) {
match = true;
}
}
if(match) {
try {
String testProtocol = (String) kernel.getAttribute(name, "protocol");
if(testProtocol != null && testProtocol.equals(protocol)) {
results.add(name.getCanonicalName());
}
} catch (Exception e) {
log.error("Unable to look up protocol for connector '"+name+"'",e);
}
break;
}
}
}
return (String[]) results.toArray(new String[results.size()]);
} catch (Exception e) {
throw new IllegalArgumentException("Unable to look up connectors for broker '"+broker+"': "+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 String addConnector(String broker, String uniqueName, String protocol, String host, int port) {
ObjectName brokerName = null;
try {
brokerName = ObjectName.getInstance(broker);
} catch (MalformedObjectNameException e) {
throw new IllegalArgumentException("Unable to parse ObjectName '"+broker+"'");
}
ObjectName name = getConnectorName(brokerName, protocol, host, port, uniqueName);
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("brokerService", brokerName);
ObjectName config = Util.getConfiguration(kernel, brokerName);
try {
kernel.invoke(config, "addGBean", new Object[]{connector, Boolean.FALSE}, new String[]{GBeanData.class.getName(), boolean.class.getName()});
} catch (Exception e) {
log.error("Unable to add GBean ", e);
return null;
}
return name.getCanonicalName();
}
public void removeConnector(String objectName) {
ObjectName name = null;
try {
name = ObjectName.getInstance(objectName);
} catch (MalformedObjectNameException e) {
throw new IllegalArgumentException("Invalid object name '" + objectName + "': " + e.getMessage());
}
try {
GBeanInfo info = kernel.getGBeanInfo(name);
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(name);
}
ObjectName config = Util.getConfiguration(kernel, name);
kernel.invoke(config, "removeGBean", new Object[]{name}, new String[]{ObjectName.class.getName()});
} catch (GBeanNotFoundException e) {
log.warn("No such GBean '" + objectName + "'"); //todo: what if we want to remove a failed GBean?
} catch (Exception e) {
log.error("Unable to remove GBean", e);
}
}
/**
* Generate an ObjectName for a new connector GBean
*/
private ObjectName getConnectorName(ObjectName broker, String protocol, String host, int port, String uniqueName) {
Hashtable table = new Hashtable();
table.put(NameFactory.J2EE_APPLICATION, broker.getKeyProperty(NameFactory.J2EE_APPLICATION));
table.put(NameFactory.J2EE_SERVER, broker.getKeyProperty(NameFactory.J2EE_SERVER));
table.put(NameFactory.J2EE_MODULE, broker.getKeyProperty(NameFactory.J2EE_MODULE));
table.put(NameFactory.J2EE_TYPE, ActiveMQConnector.CONNECTOR_J2EE_TYPE);
String brokerName = broker.getKeyProperty(NameFactory.J2EE_NAME);
table.put("broker", brokerName);
table.put(NameFactory.J2EE_NAME, brokerName+"."+protocol+"."+host+(port > -1 ? "."+port : "")+"-"+uniqueName);
try {
return ObjectName.getInstance(broker.getDomain(), table);
} catch (MalformedObjectNameException e) {
throw new IllegalStateException("Never should have failed: " + e.getMessage());
}
}
public static final GBeanInfo GBEAN_INFO;
static {
GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("ActiveMQ Manager", ActiveMQManagerGBean.class);
infoFactory.addAttribute("kernel", Kernel.class, false);
infoFactory.addInterface(ActiveMQManager.class);
infoFactory.setConstructor(new String[]{"kernel"});
GBEAN_INFO = infoFactory.getBeanInfo();
}
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
}

View File

@ -1,11 +0,0 @@
<html>
<head>
</head>
<body>
<p>
The JMS container using GBeaps for deployment in Geronimo or other JSR 77/88 based containers
</p>
</body>
</html>

View File

@ -1,61 +0,0 @@
/**
*
* 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());
}
}