[jboss-cvs] JBossAS SVN: r101408 - in projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src: test/java/org/jboss/test/osgi/jmx and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 24 11:27:47 EST 2010
Author: thomas.diesler at jboss.com
Date: 2010-02-24 11:27:47 -0500 (Wed, 24 Feb 2010)
New Revision: 101408
Modified:
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/BundleState.java
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/test/java/org/jboss/test/osgi/jmx/BundleStateTestCase.java
Log:
Implement getHeaders(locale)
Modified: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/BundleState.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/BundleState.java 2010-02-24 16:25:16 UTC (rev 101407)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/BundleState.java 2010-02-24 16:27:47 UTC (rev 101408)
@@ -26,16 +26,24 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.management.JMRuntimeException;
import javax.management.MBeanServer;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
import javax.management.StandardMBean;
import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.OpenDataException;
import javax.management.openmbean.TabularData;
+import javax.management.openmbean.TabularDataSupport;
-import org.jboss.logging.Logger;
import org.jboss.osgi.jmx.BundleStateMBeanExt;
import org.jboss.osgi.spi.management.ObjectNameFactory;
import org.osgi.framework.Bundle;
@@ -96,12 +104,24 @@
}
@Override
+ @SuppressWarnings("unchecked")
public TabularData getHeaders(long bundleId, String locale) throws IOException
{
Bundle bundle = assertBundle(bundleId);
- Dictionary<String, String> headers = bundle.getHeaders(locale);
- // TODO Auto-generated method stub
- return null;
+ List<Header> headers = new ArrayList<Header>();
+ Dictionary<String, String> bundleHeaders = bundle.getHeaders(locale);
+ Enumeration<String> keys = bundleHeaders.keys();
+ while (keys.hasMoreElements())
+ {
+ String key = keys.nextElement();
+ headers.add(new Header(key, bundleHeaders.get(key)));
+ }
+ TabularData headerTable = new TabularDataSupport(HEADERS_TYPE);
+ for (Header header : headers)
+ {
+ headerTable.put(header.toCompositeData());
+ }
+ return headerTable;
}
@Override
@@ -122,7 +142,7 @@
Bundle exporter = service.getBundle(clazz);
if (exporter == null)
return 0;
-
+
return exporter.getBundleId();
}
@@ -233,4 +253,57 @@
throw new IllegalArgumentException("No such bundle: " + bundleId);
return bundle;
}
+
+ /*
+ * Represents key/value pair in BundleData headers
+ */
+ static class Header {
+
+ private String key;
+ private String value;
+
+ String getKey() {
+ return key;
+ }
+
+ String getValue() {
+ return value;
+ }
+
+ private Header() {
+ super();
+ }
+
+ Header(String key, String value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ CompositeData toCompositeData() throws JMRuntimeException {
+ CompositeData result = null;
+ Map<String, Object> items = new HashMap<String, Object>();
+ items.put(KEY, key);
+ items.put(VALUE, value);
+ try {
+ result = new CompositeDataSupport(HEADER_TYPE, items);
+ } catch (OpenDataException e) {
+ throw new JMRuntimeException("Failed to create CompositeData for header [" + key + ":" + value + "] - "
+ + e.getMessage());
+ }
+ return result;
+ }
+
+ static Header from(CompositeData compositeData) {
+ if (compositeData == null) {
+ throw new IllegalArgumentException("Argument compositeData cannot be null");
+ }
+ if (!compositeData.getCompositeType().equals(HEADER_TYPE)) {
+ throw new IllegalArgumentException("Invalid CompositeType [" + compositeData.getCompositeType() + "]");
+ }
+ Header header = new Header();
+ header.key = (String) compositeData.get(KEY);
+ header.value = (String) compositeData.get(VALUE);
+ return header;
+ }
+ }
}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java 2010-02-24 16:25:16 UTC (rev 101407)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/JMXConnectorService.java 2010-02-24 16:27:47 UTC (rev 101408)
@@ -37,7 +37,6 @@
import javax.management.remote.JMXServiceURL;
import org.jboss.logging.Logger;
-import org.osgi.framework.BundleContext;
/**
* A Service Activator that registers an MBeanServer
@@ -55,7 +54,7 @@
private boolean shutdownRegistry;
private Registry rmiRegistry;
- public JMXConnectorService(BundleContext context, MBeanServer mbeanServer, String host, int rmiPort) throws IOException
+ public JMXConnectorService(MBeanServer mbeanServer, String host, int rmiPort) throws IOException
{
// check to see if registry already created
rmiRegistry = LocateRegistry.getRegistry(host, rmiPort);
Modified: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java 2010-02-24 16:25:16 UTC (rev 101407)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java 2010-02-24 16:27:47 UTC (rev 101408)
@@ -56,8 +56,9 @@
private String jmxRmiPort;
private String rmiAdaptorPath;
private MBeanServer mbeanServer;
- private FrameworkState framework;
+ private FrameworkState frameworkState;
private ServiceState serviceState;
+ private BundleState bundleState;
private ManagedBundleTracker bundleTracker;
public void start(BundleContext context)
@@ -70,13 +71,17 @@
BundleContext sysContext = context.getBundle(0).getBundleContext();
// Register the FrameworkMBean
- framework = new FrameworkState(sysContext, mbeanServer);
- framework.start();
+ frameworkState = new FrameworkState(sysContext, mbeanServer);
+ frameworkState.start();
// Register the ServiceStateMBean
serviceState = new ServiceState(sysContext, mbeanServer);
serviceState.start();
+ // Register the BundleStateMBean
+ bundleState = new BundleState(sysContext, mbeanServer);
+ bundleState.start();
+
// Start tracking the bundles
bundleTracker = new ManagedBundleTracker(sysContext, mbeanServer);
bundleTracker.open();
@@ -101,11 +106,14 @@
public void stop(BundleContext context)
{
// Unregister the FrameworkMBean
- framework.stop();
+ frameworkState.stop();
// Unregister the ServiceStateMBean
serviceState.stop();
+ // Unregister the BundleStateMBean
+ bundleState.stop();
+
// Stop tracking the bundles
bundleTracker.close();
@@ -137,7 +145,7 @@
{
// Try to start the JMXConnector, this should fail if it is already running
// [TODO] is there a better way to check whether the connector is already running?
- jmxConnector = new JMXConnectorService(context, mbeanServer, jmxHost, Integer.parseInt(jmxRmiPort));
+ jmxConnector = new JMXConnectorService(mbeanServer, jmxHost, Integer.parseInt(jmxRmiPort));
jmxConnector.start();
}
catch (IOException ex)
Modified: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/test/java/org/jboss/test/osgi/jmx/BundleStateTestCase.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/test/java/org/jboss/test/osgi/jmx/BundleStateTestCase.java 2010-02-24 16:25:16 UTC (rev 101407)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/test/java/org/jboss/test/osgi/jmx/BundleStateTestCase.java 2010-02-24 16:27:47 UTC (rev 101408)
@@ -29,6 +29,7 @@
import javax.management.ObjectName;
import javax.management.openmbean.TabularData;
+import org.jboss.osgi.jmx.BundleStateMBeanExt;
import org.jboss.osgi.spi.management.ObjectNameFactory;
import org.junit.Test;
import org.osgi.framework.Bundle;
@@ -45,7 +46,7 @@
@Test
public void testMBeanAccess() throws Exception
{
- ObjectName oname = ObjectNameFactory.create(BundleStateMBean.OBJECTNAME);
+ ObjectName oname = ObjectNameFactory.create(BundleStateMBeanExt.OBJECTNAME);
assertTrue("Registerd " + oname, getMBeanServer().isRegistered(oname));
}
@@ -53,7 +54,6 @@
public void listBundles() throws Exception
{
Bundle[] bundles = getSystemContext().getBundles();
-
BundleStateMBean bundleState = getBundleStateMBean();
TabularData data = bundleState.listBundles();
assertEquals("Number of bundles", bundles.length, data.size());
More information about the jboss-cvs-commits
mailing list