Author: thomas.diesler(a)jboss.com
Date: 2009-05-05 05:16:02 -0400 (Tue, 05 May 2009)
New Revision: 88199
Removed:
projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jmx/
Modified:
projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/bootstrap/BundleTestCase.java
projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/basic-felix-framework.properties
projects/jboss-osgi/trunk/bundle/jmx/pom.xml
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/ServiceActivator.java
projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/internal/NamingServiceImpl.java
Log:
RMIAdaptor startup in runtime - ok
Modified:
projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/bootstrap/BundleTestCase.java
===================================================================
---
projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/bootstrap/BundleTestCase.java 2009-05-05
08:32:11 UTC (rev 88198)
+++
projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/bootstrap/BundleTestCase.java 2009-05-05
09:16:02 UTC (rev 88199)
@@ -24,6 +24,9 @@
//$Id$
package org.jboss.test.osgi.blueprint.bootstrap;
+import javax.management.MBeanServerConnection;
+import javax.naming.InitialContext;
+
import org.jboss.osgi.spi.framework.OSGiBootstrap;
import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
import org.jboss.osgi.spi.framework.OSGiFramework;
@@ -144,4 +147,30 @@
framework.stop();
}
}
+
+ public void testJMXBundle() throws Exception
+ {
+ OSGiBootstrapProvider configProvider = OSGiBootstrap.getBootstrapProvider();
+ configProvider.configure("basic-felix-framework.properties");
+
+ OSGiFramework framework = configProvider.getFramework();
+ try
+ {
+ BundleContext context = framework.getSystemBundleContext();
+
+ Bundle bundle = installBundle(context,
"bundles/jboss-common-core-bundle.jar", true);
+ bundle = installBundle(context, "bundles/jboss-osgi-jndi.jar", true);
+ bundle = installBundle(context, "bundles/jboss-osgi-jmx.jar", true);
+
+ assertEquals("Test bundle ACTIVE", Bundle.ACTIVE, bundle.getState());
+
+ InitialContext iniCtx = new InitialContext();
+ MBeanServerConnection lookup =
(MBeanServerConnection)iniCtx.lookup("jmx/invoker/RMIAdaptor");
+ assertEquals("DefaultDomain", lookup.getDefaultDomain());
+ }
+ finally
+ {
+ framework.stop();
+ }
+ }
}
\ No newline at end of file
Modified:
projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/basic-felix-framework.properties
===================================================================
---
projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/basic-felix-framework.properties 2009-05-05
08:32:11 UTC (rev 88198)
+++
projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/basic-felix-framework.properties 2009-05-05
09:16:02 UTC (rev 88199)
@@ -21,6 +21,5 @@
framework.autoStart=\
file://${test.archive.directory}/bundles/org.apache.felix.log.jar \
file://${test.archive.directory}/bundles/jboss-osgi-common.jar \
- file://${test.archive.directory}/bundles/jboss-osgi-logging.jar \
- file://${test.archive.directory}/bundles/jboss-osgi-jmx.jar
+ file://${test.archive.directory}/bundles/jboss-osgi-logging.jar
\ 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-05 08:32:11 UTC (rev 88198)
+++ projects/jboss-osgi/trunk/bundle/jmx/pom.xml 2009-05-05 09:16:02 UTC (rev 88199)
@@ -61,14 +61,16 @@
<Bundle-SymbolicName>${artifactId}</Bundle-SymbolicName>
<Bundle-Activator>org.jboss.osgi.jmx.internal.ServiceActivator</Bundle-Activator>
<Import-Package>
- javax.management*,
- javax.naming,
- javax.naming.spi,
- org.jboss.net.sockets,
- org.jboss.osgi.common.log,
- org.jboss.osgi.jndi,
- org.osgi.framework;version=1.4,
- org.osgi.service.log,
+ javax.management*,
+ javax.naming,
+ javax.naming.spi,
+ org.jboss.net.sockets,
+ org.jboss.osgi.common.log,
+ org.jboss.osgi.jndi,
+ org.jnp.interfaces,
+ org.osgi.framework;version=1.4,
+ org.osgi.service.log,
+ org.osgi.util.tracker,
</Import-Package>
</instructions>
</configuration>
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-05
08:32:11 UTC (rev 88198)
+++
projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java 2009-05-05
09:16:02 UTC (rev 88199)
@@ -106,8 +106,11 @@
if (conServer == null)
throw new IllegalStateException("JMXConnector not available");
+ ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
try
{
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+
conServer.start();
log.log(LogService.LOG_INFO, "JMXConnector started: " + serviceURL);
}
@@ -115,6 +118,10 @@
{
log.log(LogService.LOG_ERROR, "Cannot start JMXConnector", ex);
}
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(ctxLoader);
+ }
}
public void stop()
Modified:
projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/ServiceActivator.java
===================================================================
---
projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/ServiceActivator.java 2009-05-05
08:32:11 UTC (rev 88198)
+++
projects/jboss-osgi/trunk/bundle/jmx/src/main/java/org/jboss/osgi/jmx/internal/ServiceActivator.java 2009-05-05
09:16:02 UTC (rev 88199)
@@ -51,7 +51,12 @@
public static final String REMOTE_JMX_RMI_PORT =
"org.jboss.osgi.jmx.rmi.port";
public static final String REMOTE_JMX_RMI_ADAPTOR =
"org.jboss.osgi.jmx.rmi.adaptor";
- private JMXConnectorService conService;
+ private JMXConnectorService jmxConnector;
+ private String jmxHost;
+ private String jmxRmiPort;
+ private String rmiAdaptorPath;
+ private MBeanServer mbanServer;
+
private LogService log;
public void start(BundleContext context)
@@ -59,23 +64,20 @@
log = new LogServiceTracker(context);
MBeanServerService mbeanService = new MBeanServerService(context);
- MBeanServer mbs = mbeanService.getMBeanServer();
+ mbanServer = mbeanService.getMBeanServer();
- String jmxHost = context.getProperty(REMOTE_JMX_HOST);
+ jmxHost = context.getProperty(REMOTE_JMX_HOST);
if (jmxHost == null)
jmxHost = "localhost";
- String jmxRmiPort = context.getProperty(REMOTE_JMX_RMI_PORT);
+ jmxRmiPort = context.getProperty(REMOTE_JMX_RMI_PORT);
if (jmxRmiPort == null)
jmxRmiPort = "1098";
- String rmiAdaptorPath = context.getProperty(REMOTE_JMX_RMI_ADAPTOR);
+ rmiAdaptorPath = context.getProperty(REMOTE_JMX_RMI_ADAPTOR);
if (rmiAdaptorPath == null)
rmiAdaptorPath = "jmx/invoker/RMIAdaptor";
- conService = new JMXConnectorService(context, mbs, jmxHost,
Integer.parseInt(jmxRmiPort));
- conService.start();
-
// Start tracking the NamingService
NamingServiceTracker tracker = new NamingServiceTracker(context, rmiAdaptorPath);
tracker.open();
@@ -83,10 +85,15 @@
public void stop(BundleContext context)
{
- if (conService != null)
+ stopJMXConnectorService();
+ }
+
+ private void stopJMXConnectorService()
+ {
+ if (jmxConnector != null)
{
- conService.stop();
- conService = null;
+ jmxConnector.stop();
+ jmxConnector = null;
}
}
@@ -105,12 +112,19 @@
{
NamingService naming = (NamingService)super.addingService(reference);
+ // Start JMXConnectorService
+ if (jmxConnector == null)
+ {
+ jmxConnector = new JMXConnectorService(context, mbanServer, jmxHost,
Integer.parseInt(jmxRmiPort));
+ jmxConnector.start();
+ }
+
// Bind the RMIAdaptor
try
{
InitialContext iniCtx = naming.getInitialContext();
iniCtx.createSubcontext("jmx").createSubcontext("invoker");
- StringRefAddr addr = new StringRefAddr(JMXServiceURL.class.getName(),
conService.getServiceURL().toString());
+ StringRefAddr addr = new StringRefAddr(JMXServiceURL.class.getName(),
jmxConnector.getServiceURL().toString());
Reference ref = new Reference(MBeanServerConnection.class.getName(), addr,
RMIAdaptorFactory.class.getName(), null);
iniCtx.bind(rmiAdaptorPath, ref);
@@ -129,6 +143,9 @@
{
NamingService naming = (NamingService)service;
+ // Stop JMXConnectorService
+ stopJMXConnectorService();
+
// Unbind the RMIAdaptor
try
{
Modified:
projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/internal/NamingServiceImpl.java
===================================================================
---
projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/internal/NamingServiceImpl.java 2009-05-05
08:32:11 UTC (rev 88198)
+++
projects/jboss-osgi/trunk/bundle/jndi/src/main/java/org/jboss/osgi/jndi/internal/NamingServiceImpl.java 2009-05-05
09:16:02 UTC (rev 88199)
@@ -36,8 +36,23 @@
*/
public class NamingServiceImpl implements NamingService
{
+ private InitialContext initialContext;
+
public InitialContext getInitialContext() throws NamingException
{
- return new InitialContext();
+ if (initialContext == null)
+ {
+ ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ initialContext = new InitialContext();
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(ctxLoader);
+ }
+ }
+ return initialContext;
}
}
\ No newline at end of file