[jboss-osgi-commits] JBoss-OSGI SVN: r93450 - in projects/jboss-osgi/projects/bundles/jmx/trunk: src/main/java/org/jboss/osgi/jmx/internal and 1 other directory.
jboss-osgi-commits at lists.jboss.org
jboss-osgi-commits at lists.jboss.org
Mon Sep 14 03:51:11 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-09-14 03:51:11 -0400 (Mon, 14 Sep 2009)
New Revision: 93450
Modified:
projects/jboss-osgi/projects/bundles/jmx/trunk/pom.xml
projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java
Log:
Start connector optionally
Modified: projects/jboss-osgi/projects/bundles/jmx/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/pom.xml 2009-09-14 07:49:04 UTC (rev 93449)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/pom.xml 2009-09-14 07:51:11 UTC (rev 93450)
@@ -32,7 +32,7 @@
<!-- Properties -->
<properties>
- <version.jboss.osgi.common.core>2.2.11.SP1</version.jboss.osgi.common.core>
+ <version.jboss.osgi.common.core>2.2.13-SNAPSHOT</version.jboss.osgi.common.core>
<version.jboss.osgi.jndi>1.0.1-SNAPSHOT</version.jboss.osgi.jndi>
<version.osgi>r4v42-20090728</version.osgi>
</properties>
@@ -95,10 +95,16 @@
org.osgi.service.log,
org.osgi.util.tracker,
- <!-- optional -->
+ <!-- FIXME optional -->
+ org.jboss.osgi.jndi,
+ org.jboss.net.sockets,
+ org.jnp.interfaces,
+
+ <!--
org.jboss.osgi.jndi;resolution:=optional,
org.jboss.net.sockets;resolution:=optional,
org.jnp.interfaces;resolution:=optional,
+ -->
</Import-Package>
</instructions>
</configuration>
Modified: projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java 2009-09-14 07:49:04 UTC (rev 93449)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java 2009-09-14 07:51:11 UTC (rev 93450)
@@ -27,6 +27,9 @@
import static org.jboss.osgi.jmx.Constants.REMOTE_JMX_RMI_ADAPTOR;
import static org.jboss.osgi.jmx.Constants.REMOTE_JMX_RMI_PORT;
+import java.io.IOException;
+import java.net.Socket;
+
import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;
import javax.management.remote.JMXServiceURL;
@@ -66,23 +69,26 @@
public void start(BundleContext context)
{
log = new LogServiceTracker(context);
-
+
MBeanServerLocator locator = new MBeanServerLocator(context);
mbeanServer = locator.getMBeanServer();
-
+
// Register the MBeanServer
context.registerService(MBeanServer.class.getName(), mbeanServer, null);
log.log(LogService.LOG_DEBUG, "MBeanServer registered");
-
+
+ // Get the system BundleContext
+ BundleContext sysContext = context.getBundle(0).getBundleContext();
+
// Register the ManagedBundleService
- managedBundleService = new ManagedBundleServiceImpl(context, mbeanServer);
+ managedBundleService = new ManagedBundleServiceImpl(sysContext, mbeanServer);
context.registerService(ManagedBundleService.class.getName(), managedBundleService, null);
log.log(LogService.LOG_DEBUG, "ManagedBundleService registered");
-
+
// Register the ManagedFramework
- managedFramework = new ManagedFramework(context, mbeanServer);
+ managedFramework = new ManagedFramework(sysContext, mbeanServer);
managedFramework.start();
-
+
// Register all ManagedBundles
for (Bundle bundle : context.getBundles())
managedBundleService.register(bundle);
@@ -98,7 +104,7 @@
rmiAdaptorPath = context.getProperty(REMOTE_JMX_RMI_ADAPTOR);
if (rmiAdaptorPath == null)
rmiAdaptorPath = "jmx/invoker/RMIAdaptor";
-
+
// Start tracking the NamingService
InitialContextTracker tracker = new InitialContextTracker(context, rmiAdaptorPath);
tracker.open();
@@ -109,59 +115,69 @@
// Unregister all ManagedBundles
for (Bundle bundle : context.getBundles())
managedBundleService.unregister(bundle);
-
+
// Unregister the managed framework
managedFramework.stop();
-
- stopJMXConnectorService();
- }
- private void stopJMXConnectorService()
- {
if (jmxConnector != null)
{
jmxConnector.stop();
jmxConnector = null;
}
}
-
+
class InitialContextTracker extends ServiceTracker
{
private String rmiAdaptorPath;
-
+ private boolean rmiAdaptorBound;
+
public InitialContextTracker(BundleContext context, String rmiAdaptorPath)
{
super(context, InitialContext.class.getName(), null);
this.rmiAdaptorPath = rmiAdaptorPath;
}
-
+
@Override
public Object addingService(ServiceReference reference)
{
InitialContext iniCtx = (InitialContext)super.addingService(reference);
- // Start JMXConnectorService
- if (jmxConnector == null)
+ try
{
+ // Assume that the JMXConnector is already running if we can connect to it
+ Socket socket = new Socket(jmxHost, new Integer(jmxRmiPort));
+ socket.close();
+ }
+ catch (IOException ex)
+ {
+ // Start JMXConnectorService
jmxConnector = new JMXConnectorService(context, mbeanServer, jmxHost, Integer.parseInt(jmxRmiPort));
jmxConnector.start();
}
- // Bind the RMIAdaptor
try
{
- iniCtx.createSubcontext("jmx").createSubcontext("invoker");
- 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);
-
- log.log(LogService.LOG_INFO, "MBeanServerConnection bound to: " + rmiAdaptorPath);
+ // Check if the RMIAdaptor is alrady bound
+ iniCtx.lookup(rmiAdaptorPath);
}
- catch (NamingException ex)
+ catch (NamingException lookupEx)
{
- log.log(LogService.LOG_ERROR, "Cannot bind RMIAdaptor", ex);
+ // Bind the RMIAdaptor
+ try
+ {
+ iniCtx.createSubcontext("jmx").createSubcontext("invoker");
+ 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);
+ rmiAdaptorBound = true;
+
+ log.log(LogService.LOG_INFO, "MBeanServerConnection bound to: " + rmiAdaptorPath);
+ }
+ catch (NamingException ex)
+ {
+ log.log(LogService.LOG_ERROR, "Cannot bind RMIAdaptor", ex);
+ }
}
-
return iniCtx;
}
@@ -169,22 +185,28 @@
public void removedService(ServiceReference reference, Object service)
{
InitialContext iniCtx = (InitialContext)service;
-
+
// Stop JMXConnectorService
- stopJMXConnectorService();
-
- // Unbind the RMIAdaptor
- try
+ if (jmxConnector != null)
{
- iniCtx.unbind(rmiAdaptorPath);
-
- log.log(LogService.LOG_INFO, "MBeanServerConnection unbound from: " + rmiAdaptorPath);
+ jmxConnector.stop();
+ jmxConnector = null;
}
- catch (NamingException ex)
+
+ // Unbind the RMIAdaptor
+ if (rmiAdaptorBound == true)
{
- log.log(LogService.LOG_ERROR, "Cannot unbind RMIAdaptor", ex);
+ try
+ {
+ iniCtx.unbind(rmiAdaptorPath);
+ log.log(LogService.LOG_INFO, "MBeanServerConnection unbound from: " + rmiAdaptorPath);
+ }
+ catch (NamingException ex)
+ {
+ log.log(LogService.LOG_ERROR, "Cannot unbind RMIAdaptor", ex);
+ }
}
-
+
super.removedService(reference, service);
}
}
More information about the jboss-osgi-commits
mailing list