[jboss-cvs] JBossAS SVN: r88150 - in projects/jboss-osgi/trunk: bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jmx and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon May 4 09:56:02 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-05-04 09:56:01 -0400 (Mon, 04 May 2009)
New Revision: 88150
Added:
projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/RMIAdaptor.java
projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/RMIAdaptorFactory.java
Removed:
projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jndi/
Modified:
projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jmx/JMXTestCase.java
projects/jboss-osgi/trunk/bundle/jmx/pom.xml
projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/ServiceActivator.java
projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java
projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/junit/OSGiTestSetup.java
Log:
JMXConnector started from BundleActivator
Modified: projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jmx/JMXTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jmx/JMXTestCase.java 2009-05-04 13:42:18 UTC (rev 88149)
+++ projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/jmx/JMXTestCase.java 2009-05-04 13:56:01 UTC (rev 88150)
@@ -23,60 +23,18 @@
//$Id$
-import java.io.IOException;
-import java.io.Serializable;
-import java.net.InetAddress;
-import java.rmi.RemoteException;
-import java.rmi.registry.LocateRegistry;
-import java.rmi.registry.Registry;
-import java.util.Hashtable;
-import java.util.Set;
-
-import javax.management.Attribute;
-import javax.management.AttributeList;
-import javax.management.AttributeNotFoundException;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
-import javax.management.IntrospectionException;
-import javax.management.InvalidAttributeValueException;
-import javax.management.ListenerNotFoundException;
-import javax.management.MBeanException;
-import javax.management.MBeanInfo;
-import javax.management.MBeanRegistrationException;
-import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;
-import javax.management.NotCompliantMBeanException;
-import javax.management.NotificationFilter;
-import javax.management.NotificationListener;
-import javax.management.ObjectInstance;
import javax.management.ObjectName;
-import javax.management.QueryExp;
-import javax.management.ReflectionException;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXConnectorServer;
-import javax.management.remote.JMXConnectorServerFactory;
-import javax.management.remote.JMXServiceURL;
-import javax.naming.Context;
import javax.naming.InitialContext;
-import javax.naming.Name;
-import javax.naming.NamingException;
-import javax.naming.RefAddr;
-import javax.naming.Reference;
-import javax.naming.StringRefAddr;
-import javax.naming.spi.ObjectFactory;
-import org.jboss.logging.Logger;
-import org.jboss.net.sockets.DefaultSocketFactory;
+import junit.framework.Test;
+
import org.jboss.osgi.spi.framework.OSGiFramework;
+import org.jboss.osgi.spi.junit.OSGiTestSetup;
import org.jboss.osgi.spi.management.MBeanProxy;
import org.jboss.test.osgi.blueprint.BlueprintTest;
-import org.jboss.test.osgi.blueprint.jmx.bundle.Foo;
import org.jboss.test.osgi.blueprint.jmx.bundle.FooMBean;
-import org.jnp.interfaces.Naming;
-import org.jnp.server.Main;
-import org.jnp.server.NamingBean;
-import org.jnp.server.NamingServer;
+import org.jboss.test.osgi.blueprint.mcservice.MicrocontainerServiceTestCase;
import org.osgi.framework.BundleContext;
/**
@@ -87,285 +45,49 @@
*/
public class JMXTestCase extends BlueprintTest
{
- private static final Logger log = Logger.getLogger(JMXTestCase.class);
+ private static OSGiFramework framework;
- private Main namingMain;
- private Naming namingServer;
-
- public void testJMXConnector() throws Exception
+ public static Test suite()
{
- // Get the MBeanServer and register an MBean
- MBeanServer mbeanServer = getMBeanServer();
- ObjectName oname = new ObjectName("jboss.osgi:service=mbean-test-service");
- mbeanServer.registerMBean(new Foo(), oname);
-
- // Access the MBean
- FooMBean foo = (FooMBean)MBeanProxy.get(FooMBean.class, oname, mbeanServer);
- assertEquals("hello", foo.echo("hello"));
-
- NamingBean namingBean = new NamingBean()
+ OSGiTestSetup setup = new OSGiTestSetup(MicrocontainerServiceTestCase.class)
{
- public Naming getNamingInstance()
+ @Override
+ protected void setUp() throws Exception
{
- if (namingServer == null)
- {
- try
- {
- namingServer = new NamingServer();
- }
- catch (NamingException ex)
- {
- throw new IllegalStateException("Cannot create NamingServer", ex);
- }
- }
- return namingServer;
+ super.setUp();
+ framework = getBootstrapProvider().getFramework();
+ framework.start();
+
+ BundleContext sysContext = framework.getSystemBundleContext();
+ installBundle(sysContext, "jmx-test.jar", true);
}
- };
- // the address to expose in the urls
- String host = System.getProperty("java.rmi.server.hostname");
- if (host == null)
- host = "localhost";
-
- String jndiPath = "/jmxconnector";
- InetAddress bindAddress = InetAddress.getByName(host);
- int rmiPort = 1098;
-
- namingMain = new Main();
- namingMain.setNamingInfo(namingBean);
- namingMain.setBindAddress(host);
- namingMain.setRmiPort(rmiPort);
- namingMain.setPort(1099);
-
- namingMain.start();
-
- // check to see if registry already created
- Registry rmiRegistry = LocateRegistry.getRegistry(host, rmiPort);
- if (rmiRegistry != null)
- {
- try
+ @Override
+ protected void tearDown() throws Exception
{
- rmiRegistry.list();
+ framework.stop();
+ super.tearDown();
}
- catch (RemoteException e)
- {
- log.debug("No registry running at host '" + host + "', port '" + rmiPort + "'. Will create one.");
- rmiRegistry = LocateRegistry.createRegistry(rmiPort, null, new DefaultSocketFactory(bindAddress));
- }
- }
- else
- {
- rmiRegistry = LocateRegistry.createRegistry(rmiPort, null, new DefaultSocketFactory(bindAddress));
- }
-
- String serviceURL = "service:jmx:rmi://" + host + "/jndi/rmi://" + host + ":" + rmiPort + jndiPath;
-
- final JMXServiceURL url = new JMXServiceURL(serviceURL);
-
- // create new connector server and start it
- JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbeanServer);
- connectorServer.start();
-
- log.info("JMX Connector server: " + serviceURL);
-
- // Bind the ObjectFactory that creates the MBeanServerConnection
- InitialContext iniCtx = new InitialContext();
- iniCtx.createSubcontext("jmx").createSubcontext("invoker");
- StringRefAddr addr = new StringRefAddr(JMXServiceURL.class.getName(), serviceURL);
- Reference ref = new Reference(MBeanServerConnection.class.getName(), addr, RMIAdaptorFactory.class.getName(), null);
- iniCtx.bind("jmx/invoker/RMIAdaptor", ref);
-
- // Lookup the MBeanServerConnection
- MBeanServerConnection rmiAdaptor = (MBeanServerConnection)iniCtx.lookup("jmx/invoker/RMIAdaptor");
-
- // Access the MBean through the MBeanServerConnection
- FooMBean remfoo = (FooMBean)MBeanProxy.get(FooMBean.class, oname, rmiAdaptor);
- assertEquals("hello", remfoo.echo("hello"));
-
- rmiAdaptor.unregisterMBean(oname);
+ };
+ return setup;
}
public void testMBeanAccess() throws Exception
{
- OSGiFramework framework = getBootstrapProvider().getFramework();
-
- try
- {
- BundleContext sysContext = framework.getSystemBundleContext();
-
- installBundle(sysContext, "jmx-test.jar", true);
-
- ObjectName oname = new ObjectName("jboss.osgi:service=mbean-test-service");
- FooMBean foo = (FooMBean)MBeanProxy.get(FooMBean.class, oname, getMBeanServer());
- assertEquals("hello", foo.echo("hello"));
- }
- finally
- {
- framework.stop();
- }
+ ObjectName oname = new ObjectName("jboss.osgi:service=mbean-test-service");
+ FooMBean foo = (FooMBean)MBeanProxy.get(FooMBean.class, oname, getMBeanServer());
+ assertEquals("hello", foo.echo("hello"));
}
- public static class RMIAdaptorFactory implements ObjectFactory, Serializable
+ public void testRMIAdaptor() throws Exception
{
- private static final long serialVersionUID = 2560477127430087074L;
+ // Lookup the MBeanServerConnection
+ InitialContext iniCtx = new InitialContext();
+ MBeanServerConnection rmiAdaptor = (MBeanServerConnection)iniCtx.lookup("jmx/invoker/RMIAdaptor");
- public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception
- {
- Reference ref = (Reference)obj;
- RefAddr refAddr = ref.get(JMXServiceURL.class.getName());
- String serviceURL = (String)refAddr.getContent();
- JMXServiceURL url = new JMXServiceURL(serviceURL);
- return new RMIAdaptor(url);
- }
+ // Access the MBean through the MBeanServerConnection
+ ObjectName oname = new ObjectName("jboss.osgi:service=mbean-test-service");
+ FooMBean foo = (FooMBean)MBeanProxy.get(FooMBean.class, oname, rmiAdaptor);
+ assertEquals("hello", foo.echo("hello"));
}
-
- public static class RMIAdaptor implements MBeanServerConnection, Serializable
- {
- private static final long serialVersionUID = 6066226353118090215L;
-
- private MBeanServerConnection delegate;
-
- public RMIAdaptor(JMXServiceURL url) throws IOException
- {
- JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
- delegate = jmxc.getMBeanServerConnection();
- }
-
- public void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback)
- throws InstanceNotFoundException, IOException
- {
- delegate.addNotificationListener(name, listener, filter, handback);
- }
-
- public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException,
- IOException
- {
- delegate.addNotificationListener(name, listener, filter, handback);
- }
-
- public ObjectInstance createMBean(String className, ObjectName name, Object[] params, String[] signature) throws ReflectionException,
- InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, IOException
- {
- return delegate.createMBean(className, name, params, signature);
- }
-
- public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName, Object[] params, String[] signature) throws ReflectionException,
- InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException, IOException
- {
- return delegate.createMBean(className, name, loaderName, params, signature);
- }
-
- public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName) throws ReflectionException, InstanceAlreadyExistsException,
- MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException, IOException
- {
- return delegate.createMBean(className, name, loaderName);
- }
-
- public ObjectInstance createMBean(String className, ObjectName name) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException,
- MBeanException, NotCompliantMBeanException, IOException
- {
- return delegate.createMBean(className, name);
- }
-
- public Object getAttribute(ObjectName name, String attribute) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException,
- ReflectionException, IOException
- {
- return delegate.getAttribute(name, attribute);
- }
-
- public AttributeList getAttributes(ObjectName name, String[] attributes) throws InstanceNotFoundException, ReflectionException, IOException
- {
- return delegate.getAttributes(name, attributes);
- }
-
- public String getDefaultDomain() throws IOException
- {
- return delegate.getDefaultDomain();
- }
-
- public String[] getDomains() throws IOException
- {
- return delegate.getDomains();
- }
-
- public Integer getMBeanCount() throws IOException
- {
- return delegate.getMBeanCount();
- }
-
- public MBeanInfo getMBeanInfo(ObjectName name) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException
- {
- return delegate.getMBeanInfo(name);
- }
-
- public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException, IOException
- {
- return delegate.getObjectInstance(name);
- }
-
- public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature) throws InstanceNotFoundException, MBeanException,
- ReflectionException, IOException
- {
- return delegate.invoke(name, operationName, params, signature);
- }
-
- public boolean isInstanceOf(ObjectName name, String className) throws InstanceNotFoundException, IOException
- {
- return delegate.isInstanceOf(name, className);
- }
-
- public boolean isRegistered(ObjectName name) throws IOException
- {
- return delegate.isRegistered(name);
- }
-
- public Set queryMBeans(ObjectName name, QueryExp query) throws IOException
- {
- return delegate.queryMBeans(name, query);
- }
-
- public Set queryNames(ObjectName name, QueryExp query) throws IOException
- {
- return delegate.queryNames(name, query);
- }
-
- public void removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback)
- throws InstanceNotFoundException, ListenerNotFoundException, IOException
- {
- delegate.removeNotificationListener(name, listener, filter, handback);
- }
-
- public void removeNotificationListener(ObjectName name, NotificationListener listener) throws InstanceNotFoundException, ListenerNotFoundException,
- IOException
- {
- delegate.removeNotificationListener(name, listener);
- }
-
- public void removeNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException,
- ListenerNotFoundException, IOException
- {
- delegate.removeNotificationListener(name, listener, filter, handback);
- }
-
- public void removeNotificationListener(ObjectName name, ObjectName listener) throws InstanceNotFoundException, ListenerNotFoundException, IOException
- {
- delegate.removeNotificationListener(name, listener);
- }
-
- public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException,
- MBeanException, ReflectionException, IOException
- {
- delegate.setAttribute(name, attribute);
- }
-
- public AttributeList setAttributes(ObjectName name, AttributeList attributes) throws InstanceNotFoundException, ReflectionException, IOException
- {
- return delegate.setAttributes(name, attributes);
- }
-
- public void unregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException, IOException
- {
- delegate.unregisterMBean(name);
- }
- }
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/bundle/jmx/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/bundle/jmx/pom.xml 2009-05-04 13:42:18 UTC (rev 88149)
+++ projects/jboss-osgi/trunk/bundle/jmx/pom.xml 2009-05-04 13:56:01 UTC (rev 88150)
@@ -63,6 +63,9 @@
<Bundle-Activator>org.jboss.osgi.jmx.ServiceActivator</Bundle-Activator>
<Import-Package>
javax.management*,
+ javax.naming,
+ javax.naming.spi,
+ org.jboss.net.sockets,
org.jboss.osgi.common.log,
org.osgi.framework;version=1.4,
org.osgi.service.log,
Modified: projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/ServiceActivator.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/ServiceActivator.java 2009-05-04 13:42:18 UTC (rev 88149)
+++ projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/ServiceActivator.java 2009-05-04 13:56:01 UTC (rev 88150)
@@ -38,24 +38,26 @@
*/
public class ServiceActivator implements BundleActivator
{
- public static final String REMOTE_JMX_HOST = "org.jboss.osgi.jmx.host";
- public static final String REMOTE_JMX_PORT = "org.jboss.osgi.jmx.port";
-
+ public static final String REMOTE_JNDI_HOST = "org.jboss.osgi.jndi.host";
+ public static final String REMOTE_JNDI_RMI_PORT = "org.jboss.osgi.jndi.rmi.port";
+
private JMXConnectorService conService;
-
+
public void start(BundleContext context)
{
MBeanServerService mbeanService = new MBeanServerService(context);
MBeanServer mbs = mbeanService.getMBeanServer();
-
- String jmxHost = context.getProperty(REMOTE_JMX_HOST);
- String jmxPort = context.getProperty(REMOTE_JMX_PORT);
-
- if (jmxHost != null && jmxPort != null)
- {
- conService = new JMXConnectorService(context, mbs, jmxHost, jmxPort);
- conService.start();
- }
+
+ String jndiHost = context.getProperty(REMOTE_JNDI_HOST);
+ if (jndiHost == null)
+ jndiHost = "localhost";
+
+ String jndiRmiPort = context.getProperty(REMOTE_JNDI_RMI_PORT);
+ if (jndiRmiPort == null)
+ jndiRmiPort = "1098";
+
+ conService = new JMXConnectorService(context, mbs, jndiHost, Integer.parseInt(jndiRmiPort));
+ conService.start();
}
public void stop(BundleContext context)
Modified: projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java 2009-05-04 13:42:18 UTC (rev 88149)
+++ projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java 2009-05-04 13:56:01 UTC (rev 88150)
@@ -24,12 +24,21 @@
//$Id$
import java.io.IOException;
+import java.net.InetAddress;
+import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
import javax.management.MBeanServer;
+import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
+import javax.naming.InitialContext;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+import org.jboss.net.sockets.DefaultSocketFactory;
import org.jboss.osgi.common.log.LogServiceTracker;
import org.osgi.framework.BundleContext;
import org.osgi.service.log.LogService;
@@ -46,34 +55,76 @@
private JMXServiceURL conURL;
private JMXConnectorServer conServer;
- public JMXConnectorService(BundleContext context, MBeanServer mbs, String jmxHost, String jmxPort)
+ public JMXConnectorService(BundleContext context, MBeanServer mbeanServer, String host, int rmiPort)
{
log = new LogServiceTracker(context);
+ String jmxConnectorServerPath = "/jmxconnector";
+ String rmiAdaptorPath = "jmx/invoker/RMIAdaptor";
+
try
{
- conURL = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + jmxHost + ":" + jmxPort + "/server");
- conServer = JMXConnectorServerFactory.newJMXConnectorServer(conURL, null, mbs);
+ InetAddress bindAddress = InetAddress.getByName(host);
+
+ // check to see if registry already created
+ Registry rmiRegistry = LocateRegistry.getRegistry(host, rmiPort);
+ if (rmiRegistry != null)
+ {
+ try
+ {
+ rmiRegistry.list();
+ }
+ catch (RemoteException e)
+ {
+ log.log(LogService.LOG_DEBUG, "No registry running at host '" + host + "', port '" + rmiPort + "'. Will create one.");
+ rmiRegistry = LocateRegistry.createRegistry(rmiPort, null, new DefaultSocketFactory(bindAddress));
+ }
+ }
+ else
+ {
+ rmiRegistry = LocateRegistry.createRegistry(rmiPort, null, new DefaultSocketFactory(bindAddress));
+ }
+
+ String serviceURL = "service:jmx:rmi://" + host + "/jndi/rmi://" + host + ":" + rmiPort + jmxConnectorServerPath;
+ JMXServiceURL url = new JMXServiceURL(serviceURL);
+
+ // create new connector server and start it
+ conServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbeanServer);
+
+ log.log(LogService.LOG_DEBUG, "JMX Connector created: " + serviceURL);
+
+ // Bind an ObjectFactory that creates the MBeanServerConnection
+ InitialContext iniCtx = new InitialContext();
+ iniCtx.createSubcontext("jmx").createSubcontext("invoker");
+ StringRefAddr addr = new StringRefAddr(JMXServiceURL.class.getName(), serviceURL);
+ Reference ref = new Reference(MBeanServerConnection.class.getName(), addr, RMIAdaptorFactory.class.getName(), null);
+ iniCtx.bind(rmiAdaptorPath, ref);
+
+ log.log(LogService.LOG_INFO, "MBeanServerConnection bound: " + rmiAdaptorPath);
}
- catch (IOException ex)
+ catch (RuntimeException rte)
{
- log.log(LogService.LOG_ERROR, "Cannot create JMXConnectorServer", ex);
+ throw rte;
}
+ catch (Exception ex)
+ {
+ log.log(LogService.LOG_ERROR, "Cannot create JMXConnector", ex);
+ }
}
public void start()
{
if (conServer == null)
- throw new IllegalStateException("JMXConnectorServer not available");
+ throw new IllegalStateException("JMXConnector not available");
try
{
conServer.start();
- log.log(LogService.LOG_DEBUG, "JMXConnector started: " + conURL);
+ log.log(LogService.LOG_INFO, "JMXConnector started: " + conURL);
}
catch (IOException ex)
{
- log.log(LogService.LOG_ERROR, "Cannot start JMXConnectorServer", ex);
+ log.log(LogService.LOG_ERROR, "Cannot start JMXConnector", ex);
}
}
@@ -86,7 +137,7 @@
}
catch (IOException ex)
{
- log.log(LogService.LOG_WARNING, "Cannot stop JMXConnectorServer", ex);
+ log.log(LogService.LOG_WARNING, "Cannot stop JMXConnector", ex);
}
}
}
\ No newline at end of file
Added: projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/RMIAdaptor.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/RMIAdaptor.java (rev 0)
+++ projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/RMIAdaptor.java 2009-05-04 13:56:01 UTC (rev 88150)
@@ -0,0 +1,183 @@
+/**
+ *
+ */
+package org.jboss.osgi.jmx.internal;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Set;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.IntrospectionException;
+import javax.management.InvalidAttributeValueException;
+import javax.management.ListenerNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServerConnection;
+import javax.management.NotCompliantMBeanException;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+import javax.management.QueryExp;
+import javax.management.ReflectionException;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+public class RMIAdaptor implements MBeanServerConnection, Serializable
+{
+ private static final long serialVersionUID = 6066226353118090215L;
+
+ private MBeanServerConnection delegate;
+
+ public RMIAdaptor(JMXServiceURL url) throws IOException
+ {
+ JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
+ delegate = jmxc.getMBeanServerConnection();
+ }
+
+ public void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback)
+ throws InstanceNotFoundException, IOException
+ {
+ delegate.addNotificationListener(name, listener, filter, handback);
+ }
+
+ public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException,
+ IOException
+ {
+ delegate.addNotificationListener(name, listener, filter, handback);
+ }
+
+ public ObjectInstance createMBean(String className, ObjectName name, Object[] params, String[] signature) throws ReflectionException,
+ InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, IOException
+ {
+ return delegate.createMBean(className, name, params, signature);
+ }
+
+ public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName, Object[] params, String[] signature) throws ReflectionException,
+ InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException, IOException
+ {
+ return delegate.createMBean(className, name, loaderName, params, signature);
+ }
+
+ public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName) throws ReflectionException, InstanceAlreadyExistsException,
+ MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException, IOException
+ {
+ return delegate.createMBean(className, name, loaderName);
+ }
+
+ public ObjectInstance createMBean(String className, ObjectName name) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException,
+ MBeanException, NotCompliantMBeanException, IOException
+ {
+ return delegate.createMBean(className, name);
+ }
+
+ public Object getAttribute(ObjectName name, String attribute) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException,
+ ReflectionException, IOException
+ {
+ return delegate.getAttribute(name, attribute);
+ }
+
+ public AttributeList getAttributes(ObjectName name, String[] attributes) throws InstanceNotFoundException, ReflectionException, IOException
+ {
+ return delegate.getAttributes(name, attributes);
+ }
+
+ public String getDefaultDomain() throws IOException
+ {
+ return delegate.getDefaultDomain();
+ }
+
+ public String[] getDomains() throws IOException
+ {
+ return delegate.getDomains();
+ }
+
+ public Integer getMBeanCount() throws IOException
+ {
+ return delegate.getMBeanCount();
+ }
+
+ public MBeanInfo getMBeanInfo(ObjectName name) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException
+ {
+ return delegate.getMBeanInfo(name);
+ }
+
+ public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException, IOException
+ {
+ return delegate.getObjectInstance(name);
+ }
+
+ public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature) throws InstanceNotFoundException, MBeanException,
+ ReflectionException, IOException
+ {
+ return delegate.invoke(name, operationName, params, signature);
+ }
+
+ public boolean isInstanceOf(ObjectName name, String className) throws InstanceNotFoundException, IOException
+ {
+ return delegate.isInstanceOf(name, className);
+ }
+
+ public boolean isRegistered(ObjectName name) throws IOException
+ {
+ return delegate.isRegistered(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Set queryMBeans(ObjectName name, QueryExp query) throws IOException
+ {
+ return delegate.queryMBeans(name, query);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Set queryNames(ObjectName name, QueryExp query) throws IOException
+ {
+ return delegate.queryNames(name, query);
+ }
+
+ public void removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback)
+ throws InstanceNotFoundException, ListenerNotFoundException, IOException
+ {
+ delegate.removeNotificationListener(name, listener, filter, handback);
+ }
+
+ public void removeNotificationListener(ObjectName name, NotificationListener listener) throws InstanceNotFoundException, ListenerNotFoundException,
+ IOException
+ {
+ delegate.removeNotificationListener(name, listener);
+ }
+
+ public void removeNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException,
+ ListenerNotFoundException, IOException
+ {
+ delegate.removeNotificationListener(name, listener, filter, handback);
+ }
+
+ public void removeNotificationListener(ObjectName name, ObjectName listener) throws InstanceNotFoundException, ListenerNotFoundException, IOException
+ {
+ delegate.removeNotificationListener(name, listener);
+ }
+
+ public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException,
+ MBeanException, ReflectionException, IOException
+ {
+ delegate.setAttribute(name, attribute);
+ }
+
+ public AttributeList setAttributes(ObjectName name, AttributeList attributes) throws InstanceNotFoundException, ReflectionException, IOException
+ {
+ return delegate.setAttributes(name, attributes);
+ }
+
+ public void unregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException, IOException
+ {
+ delegate.unregisterMBean(name);
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/RMIAdaptor.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/RMIAdaptorFactory.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/RMIAdaptorFactory.java (rev 0)
+++ projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/RMIAdaptorFactory.java 2009-05-04 13:56:01 UTC (rev 88150)
@@ -0,0 +1,30 @@
+/**
+ *
+ */
+package org.jboss.osgi.jmx.internal;
+
+// $Id$
+
+import java.io.Serializable;
+import java.util.Hashtable;
+
+import javax.management.remote.JMXServiceURL;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
+
+public class RMIAdaptorFactory implements ObjectFactory, Serializable
+{
+ private static final long serialVersionUID = 2560477127430087074L;
+
+ public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception
+ {
+ Reference ref = (Reference)obj;
+ RefAddr refAddr = ref.get(JMXServiceURL.class.getName());
+ String serviceURL = (String)refAddr.getContent();
+ JMXServiceURL url = new JMXServiceURL(serviceURL);
+ return new RMIAdaptor(url);
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/RMIAdaptorFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/junit/OSGiTestSetup.java
===================================================================
--- projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/junit/OSGiTestSetup.java 2009-05-04 13:42:18 UTC (rev 88149)
+++ projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/junit/OSGiTestSetup.java 2009-05-04 13:56:01 UTC (rev 88150)
@@ -31,6 +31,9 @@
import org.jboss.logging.Logger;
import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
import org.jboss.virtual.VFS;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
/**
* An OSGi Test Setup
@@ -100,4 +103,9 @@
{
return delegate.getTestArchiveFile(archive).toURI().toURL();
}
+
+ public Bundle installBundle(BundleContext sysContext, String bundlePath, boolean start) throws BundleException
+ {
+ return delegate.installBundle(sysContext, bundlePath, start);
+ }
}
More information about the jboss-cvs-commits
mailing list