[jboss-cvs] JBossAS SVN: r101419 - in projects/jboss-osgi/projects: bundles/jmx/trunk/jmx-bundle and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 24 15:18:09 EST 2010
Author: thomas.diesler at jboss.com
Date: 2010-02-24 15:18:06 -0500 (Wed, 24 Feb 2010)
New Revision: 101419
Added:
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/AbstractState.java
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/BundleStateExt.java
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/FrameworkStateExt.java
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ServiceStateExt.java
Removed:
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/AbstractStateMBean.java
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/FrameworkState.java
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ManagedBundleTracker.java
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ServiceState.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundleMBean.java
Modified:
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-api/src/main/java/org/jboss/osgi/jmx/BundleStateMBeanExt.java
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/pom.xml
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteBundle.java
Log:
Migrate ManagedBundle to BundleStateMBean
Modified: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-api/src/main/java/org/jboss/osgi/jmx/BundleStateMBeanExt.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-api/src/main/java/org/jboss/osgi/jmx/BundleStateMBeanExt.java 2010-02-24 20:04:08 UTC (rev 101418)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-api/src/main/java/org/jboss/osgi/jmx/BundleStateMBeanExt.java 2010-02-24 20:18:06 UTC (rev 101419)
@@ -28,6 +28,7 @@
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.TabularData;
+import org.osgi.jmx.JmxConstants;
import org.osgi.jmx.framework.BundleStateMBean;
/**
@@ -64,6 +65,19 @@
TabularData getHeaders(long bundleId, String locale) throws IOException;
/**
+ * Answer the map of properties associated with this bundle
+ *
+ * @see JmxConstants#PROPERTIES_TYPE for the details of the CompositeType
+ *
+ * @param bundleId the unique identifier of the bundle
+ * @param key The name of the requested property.
+ * @return the property data, or null if the property is undefined.
+ * @throws IOException if the operation fails
+ * @throws IllegalArgumentException if the bundle indicated does not exist
+ */
+ CompositeData getProperty(long bundleId, String key) throws IOException;
+
+ /**
* Loads the specified class using the class loader of the bundle with the given identifier.
*
* @param bundleId the unique identifier of the bundle
Modified: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/pom.xml 2010-02-24 20:04:08 UTC (rev 101418)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/pom.xml 2010-02-24 20:18:06 UTC (rev 101419)
@@ -127,7 +127,7 @@
<!-- osgi -->
org.osgi.framework;version="[1.5,2.0)",
- org.osgi.jmx.framework;version="[1.0,2.0)",
+ org.osgi.jmx*;version="[1.0,2.0)",
org.osgi.service.packageadmin;version="[1.2,2.0)",
org.osgi.util.tracker;version="[1.4,2.0)",
Copied: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/AbstractState.java (from rev 101404, projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/AbstractStateMBean.java)
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/AbstractState.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/AbstractState.java 2010-02-24 20:18:06 UTC (rev 101419)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.jmx.internal;
+
+//$Id$
+
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectName;
+import javax.management.StandardMBean;
+
+import org.jboss.logging.Logger;
+import org.jboss.osgi.spi.management.MBeanProxy;
+import org.jboss.osgi.spi.management.ObjectNameFactory;
+import org.osgi.framework.BundleContext;
+import org.osgi.jmx.framework.BundleStateMBean;
+import org.osgi.jmx.framework.FrameworkMBean;
+import org.osgi.jmx.framework.ServiceStateMBean;
+
+/**
+ * An extension to {@link BundleStateMBean}.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 23-Feb-2010
+ */
+abstract class AbstractState
+{
+ // Provide logging
+ private static final Logger log = Logger.getLogger(AbstractState.class);
+
+ protected MBeanServer mbeanServer;
+ protected BundleContext context;
+
+ AbstractState(BundleContext context, MBeanServer mbeanServer)
+ {
+ if (context == null)
+ throw new IllegalArgumentException("Null BundleContext");
+ if (mbeanServer == null)
+ throw new IllegalArgumentException("Null MBeanServer");
+
+ if (context.getBundle().getBundleId() != 0)
+ throw new IllegalArgumentException("Not the system bundle context: " + context);
+
+ this.context = context;
+ this.mbeanServer = mbeanServer;
+ }
+
+ void start()
+ {
+ ObjectName objectName = getObjectName();
+ try
+ {
+ log.debug("Register: " + objectName);
+ mbeanServer.registerMBean(getStandardMBean(), objectName);
+ }
+ catch (JMException ex)
+ {
+ log.warn("Cannot register: " + objectName);
+ }
+ }
+
+ void stop()
+ {
+ ObjectName objectName = getObjectName();
+ try
+ {
+ if (mbeanServer.isRegistered(objectName))
+ {
+ log.debug("Unregister: " + objectName);
+ mbeanServer.unregisterMBean(objectName);
+ }
+ }
+ catch (JMException ex)
+ {
+ log.warn("Cannot unregister: " + objectName);
+ }
+ }
+
+ abstract StandardMBean getStandardMBean() throws NotCompliantMBeanException;
+
+ abstract ObjectName getObjectName();
+
+ FrameworkMBean getFrameworkMBean()
+ {
+ ObjectName objectName = ObjectNameFactory.create(FrameworkMBean.OBJECTNAME);
+ return MBeanProxy.get(mbeanServer, objectName, FrameworkMBean.class);
+ }
+
+ BundleStateMBean getBundleStateMBean()
+ {
+ ObjectName objectName = ObjectNameFactory.create(BundleStateMBean.OBJECTNAME);
+ return MBeanProxy.get(mbeanServer, objectName, BundleStateMBean.class);
+ }
+
+ ServiceStateMBean getServiceStateMBean()
+ {
+ ObjectName objectName = ObjectNameFactory.create(ServiceStateMBean.OBJECTNAME);
+ return MBeanProxy.get(mbeanServer, objectName, ServiceStateMBean.class);
+ }
+}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/AbstractStateMBean.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/AbstractStateMBean.java 2010-02-24 20:04:08 UTC (rev 101418)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/AbstractStateMBean.java 2010-02-24 20:18:06 UTC (rev 101419)
@@ -1,120 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.jmx.internal;
-
-//$Id$
-
-import javax.management.JMException;
-import javax.management.MBeanServer;
-import javax.management.NotCompliantMBeanException;
-import javax.management.ObjectName;
-import javax.management.StandardMBean;
-
-import org.jboss.logging.Logger;
-import org.jboss.osgi.spi.management.MBeanProxy;
-import org.jboss.osgi.spi.management.ObjectNameFactory;
-import org.osgi.framework.BundleContext;
-import org.osgi.jmx.framework.BundleStateMBean;
-import org.osgi.jmx.framework.FrameworkMBean;
-import org.osgi.jmx.framework.ServiceStateMBean;
-
-/**
- * An extension to {@link BundleStateMBean}.
- *
- * @author thomas.diesler at jboss.com
- * @since 23-Feb-2010
- */
-abstract class AbstractStateMBean
-{
- // Provide logging
- private static final Logger log = Logger.getLogger(AbstractStateMBean.class);
-
- protected MBeanServer mbeanServer;
- protected BundleContext context;
-
- AbstractStateMBean(BundleContext context, MBeanServer mbeanServer)
- {
- if (context == null)
- throw new IllegalArgumentException("Null BundleContext");
- if (mbeanServer == null)
- throw new IllegalArgumentException("Null MBeanServer");
-
- if (context.getBundle().getBundleId() != 0)
- throw new IllegalArgumentException("Not the system bundle context: " + context);
-
- this.context = context;
- this.mbeanServer = mbeanServer;
- }
-
- void start()
- {
- ObjectName objectName = getObjectName();
- try
- {
- log.debug("Register: " + objectName);
- mbeanServer.registerMBean(getStandardMBean(), objectName);
- }
- catch (JMException ex)
- {
- log.warn("Cannot register: " + objectName);
- }
- }
-
- void stop()
- {
- ObjectName objectName = getObjectName();
- try
- {
- if (mbeanServer.isRegistered(objectName))
- {
- log.debug("Unregister: " + objectName);
- mbeanServer.unregisterMBean(objectName);
- }
- }
- catch (JMException ex)
- {
- log.warn("Cannot unregister: " + objectName);
- }
- }
-
- abstract StandardMBean getStandardMBean() throws NotCompliantMBeanException;
-
- abstract ObjectName getObjectName();
-
- FrameworkMBean getFrameworkMBean()
- {
- ObjectName objectName = ObjectNameFactory.create(FrameworkMBean.OBJECTNAME);
- return MBeanProxy.get(mbeanServer, objectName, FrameworkMBean.class);
- }
-
- BundleStateMBean getBundleStateMBean()
- {
- ObjectName objectName = ObjectNameFactory.create(BundleStateMBean.OBJECTNAME);
- return MBeanProxy.get(mbeanServer, objectName, BundleStateMBean.class);
- }
-
- ServiceStateMBean getServiceStateMBean()
- {
- ObjectName objectName = ObjectNameFactory.create(ServiceStateMBean.OBJECTNAME);
- return MBeanProxy.get(mbeanServer, objectName, ServiceStateMBean.class);
- }
-}
\ No newline at end of file
Deleted: 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 20:04:08 UTC (rev 101418)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/BundleState.java 2010-02-24 20:18:06 UTC (rev 101419)
@@ -1,309 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.jmx.internal;
-
-//$Id$
-
-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.osgi.jmx.BundleStateMBeanExt;
-import org.jboss.osgi.spi.management.ObjectNameFactory;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.jmx.framework.BundleStateMBean;
-import org.osgi.service.packageadmin.PackageAdmin;
-
-/**
- * An extension to {@link BundleStateMBean}.
- *
- * @author thomas.diesler at jboss.com
- * @since 23-Feb-2010
- */
-public class BundleState extends AbstractStateMBean implements BundleStateMBeanExt
-{
- public BundleState(BundleContext context, MBeanServer mbeanServer)
- {
- super(context, mbeanServer);
- }
-
- @Override
- ObjectName getObjectName()
- {
- return ObjectNameFactory.create(OBJECTNAME);
- }
-
- @Override
- StandardMBean getStandardMBean() throws NotCompliantMBeanException
- {
- return new StandardMBean(this, BundleStateMBeanExt.class);
- }
-
- @Override
- public CompositeData getBundle(long bundleId) throws IOException
- {
- TabularData bundleList = listBundles();
- CompositeData bundleData = bundleList.get(new Object[] { (Long)bundleId });
- if (bundleData == null)
- throw new IllegalArgumentException("No such bundle: " + bundleId);
- return bundleData;
- }
-
- @Override
- public String getDataFile(long bundleId, String filename) throws IOException
- {
- Bundle bundle = assertBundle(bundleId);
- File dataFile = bundle.getBundleContext().getDataFile(filename);
- return dataFile.getCanonicalPath();
- }
-
- @Override
- public String getEntry(long bundleId, String path) throws IOException
- {
- Bundle bundle = assertBundle(bundleId);
- URL entry = bundle.getEntry(path);
- return entry.toExternalForm();
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public TabularData getHeaders(long bundleId, String locale) throws IOException
- {
- Bundle bundle = assertBundle(bundleId);
- 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
- public String getResource(long bundleId, String name) throws IOException
- {
- Bundle bundle = assertBundle(bundleId);
- URL entry = bundle.getResource(name);
- return entry.toExternalForm();
- }
-
- @Override
- public long loadClass(long bundleId, String name) throws ClassNotFoundException, IOException
- {
- Bundle bundle = assertBundle(bundleId);
- Class<?> clazz = bundle.loadClass(name);
- ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
- PackageAdmin service = (PackageAdmin)context.getService(sref);
- Bundle exporter = service.getBundle(clazz);
- if (exporter == null)
- return 0;
-
- return exporter.getBundleId();
- }
-
- public String[] getExportedPackages(long arg0) throws IOException
- {
- return getBundleStateMBean().getExportedPackages(arg0);
- }
-
- public long[] getFragments(long arg0) throws IOException
- {
- return getBundleStateMBean().getFragments(arg0);
- }
-
- public TabularData getHeaders(long arg0) throws IOException
- {
- return getBundleStateMBean().getHeaders(arg0);
- }
-
- public long[] getHosts(long arg0) throws IOException
- {
- return getBundleStateMBean().getHosts(arg0);
- }
-
- public String[] getImportedPackages(long arg0) throws IOException
- {
- return getBundleStateMBean().getImportedPackages(arg0);
- }
-
- public long getLastModified(long arg0) throws IOException
- {
- return getBundleStateMBean().getLastModified(arg0);
- }
-
- public String getLocation(long arg0) throws IOException
- {
- return getBundleStateMBean().getLocation(arg0);
- }
-
- public long[] getRegisteredServices(long arg0) throws IOException
- {
- return getBundleStateMBean().getRegisteredServices(arg0);
- }
-
- public long[] getRequiredBundles(long arg0) throws IOException
- {
- return getBundleStateMBean().getRequiredBundles(arg0);
- }
-
- public long[] getRequiringBundles(long arg0) throws IOException
- {
- return getBundleStateMBean().getRequiringBundles(arg0);
- }
-
- public long[] getServicesInUse(long arg0) throws IOException
- {
- return getBundleStateMBean().getServicesInUse(arg0);
- }
-
- public int getStartLevel(long arg0) throws IOException
- {
- return getBundleStateMBean().getStartLevel(arg0);
- }
-
- public String getState(long arg0) throws IOException
- {
- return getBundleStateMBean().getState(arg0);
- }
-
- public String getSymbolicName(long arg0) throws IOException
- {
- return getBundleStateMBean().getSymbolicName(arg0);
- }
-
- public String getVersion(long arg0) throws IOException
- {
- return getBundleStateMBean().getVersion(arg0);
- }
-
- public boolean isFragment(long arg0) throws IOException
- {
- return getBundleStateMBean().isFragment(arg0);
- }
-
- public boolean isPersistentlyStarted(long arg0) throws IOException
- {
- return getBundleStateMBean().isPersistentlyStarted(arg0);
- }
-
- public boolean isRemovalPending(long arg0) throws IOException
- {
- return getBundleStateMBean().isRemovalPending(arg0);
- }
-
- public boolean isRequired(long arg0) throws IOException
- {
- return getBundleStateMBean().isRequired(arg0);
- }
-
- public TabularData listBundles() throws IOException
- {
- return getBundleStateMBean().listBundles();
- }
-
- private Bundle assertBundle(long bundleId)
- {
- Bundle bundle = context.getBundle(bundleId);
- if (bundle == null)
- 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
Copied: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/BundleStateExt.java (from rev 101408, 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/BundleStateExt.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/BundleStateExt.java 2010-02-24 20:18:06 UTC (rev 101419)
@@ -0,0 +1,349 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.jmx.internal;
+
+//$Id$
+
+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.osgi.jmx.BundleStateMBeanExt;
+import org.jboss.osgi.spi.management.ObjectNameFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.jmx.JmxConstants;
+import org.osgi.jmx.framework.BundleStateMBean;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+/**
+ * An extension to {@link BundleStateMBean}.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 23-Feb-2010
+ */
+public class BundleStateExt extends AbstractState implements BundleStateMBeanExt
+{
+ public BundleStateExt(BundleContext context, MBeanServer mbeanServer)
+ {
+ super(context, mbeanServer);
+ }
+
+ @Override
+ ObjectName getObjectName()
+ {
+ return ObjectNameFactory.create(OBJECTNAME);
+ }
+
+ @Override
+ StandardMBean getStandardMBean() throws NotCompliantMBeanException
+ {
+ return new StandardMBean(this, BundleStateMBeanExt.class);
+ }
+
+ @Override
+ public CompositeData getBundle(long bundleId) throws IOException
+ {
+ TabularData bundleList = listBundles();
+ CompositeData bundleData = bundleList.get(new Object[] { (Long)bundleId });
+ if (bundleData == null)
+ throw new IllegalArgumentException("No such bundle: " + bundleId);
+ return bundleData;
+ }
+
+ @Override
+ public String getDataFile(long bundleId, String filename) throws IOException
+ {
+ BundleContext context = assertBundleContext(bundleId);
+ File dataFile = context.getDataFile(filename);
+ return dataFile.getCanonicalPath();
+ }
+
+ @Override
+ public String getEntry(long bundleId, String path) throws IOException
+ {
+ Bundle bundle = assertBundle(bundleId);
+ URL entry = bundle.getEntry(path);
+ return entry.toExternalForm();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public TabularData getHeaders(long bundleId, String locale) throws IOException
+ {
+ Bundle bundle = assertBundle(bundleId);
+ 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
+ public CompositeData getProperty(long bundleId, String key) throws IOException
+ {
+ BundleContext bundleContext = assertBundleContext(bundleId);
+ String value = bundleContext.getProperty(key);
+ if (value == null)
+ return null;
+
+ Map<String, Object> items = new HashMap<String, Object>();
+ items.put(KEY, key);
+ items.put(VALUE, value);
+ try
+ {
+ return new CompositeDataSupport(JmxConstants.PROPERTY_TYPE, items);
+ }
+ catch (OpenDataException ex)
+ {
+ throw new JMRuntimeException("Failed to create CompositeData for property [" + key + ":" + value + "] - " + ex.getMessage());
+ }
+ }
+
+ @Override
+ public String getResource(long bundleId, String name) throws IOException
+ {
+ Bundle bundle = assertBundle(bundleId);
+ URL entry = bundle.getResource(name);
+ return entry.toExternalForm();
+ }
+
+ @Override
+ public long loadClass(long bundleId, String name) throws ClassNotFoundException, IOException
+ {
+ Bundle bundle = assertBundle(bundleId);
+ Class<?> clazz = bundle.loadClass(name);
+ ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
+ PackageAdmin service = (PackageAdmin)context.getService(sref);
+ Bundle exporter = service.getBundle(clazz);
+ if (exporter == null)
+ return 0;
+
+ return exporter.getBundleId();
+ }
+
+ public String[] getExportedPackages(long arg0) throws IOException
+ {
+ return getBundleStateMBean().getExportedPackages(arg0);
+ }
+
+ public long[] getFragments(long arg0) throws IOException
+ {
+ return getBundleStateMBean().getFragments(arg0);
+ }
+
+ public TabularData getHeaders(long arg0) throws IOException
+ {
+ return getBundleStateMBean().getHeaders(arg0);
+ }
+
+ public long[] getHosts(long arg0) throws IOException
+ {
+ return getBundleStateMBean().getHosts(arg0);
+ }
+
+ public String[] getImportedPackages(long arg0) throws IOException
+ {
+ return getBundleStateMBean().getImportedPackages(arg0);
+ }
+
+ public long getLastModified(long arg0) throws IOException
+ {
+ return getBundleStateMBean().getLastModified(arg0);
+ }
+
+ public String getLocation(long arg0) throws IOException
+ {
+ return getBundleStateMBean().getLocation(arg0);
+ }
+
+ public long[] getRegisteredServices(long arg0) throws IOException
+ {
+ return getBundleStateMBean().getRegisteredServices(arg0);
+ }
+
+ public long[] getRequiredBundles(long arg0) throws IOException
+ {
+ return getBundleStateMBean().getRequiredBundles(arg0);
+ }
+
+ public long[] getRequiringBundles(long arg0) throws IOException
+ {
+ return getBundleStateMBean().getRequiringBundles(arg0);
+ }
+
+ public long[] getServicesInUse(long arg0) throws IOException
+ {
+ return getBundleStateMBean().getServicesInUse(arg0);
+ }
+
+ public int getStartLevel(long arg0) throws IOException
+ {
+ return getBundleStateMBean().getStartLevel(arg0);
+ }
+
+ public String getState(long arg0) throws IOException
+ {
+ return getBundleStateMBean().getState(arg0);
+ }
+
+ public String getSymbolicName(long arg0) throws IOException
+ {
+ return getBundleStateMBean().getSymbolicName(arg0);
+ }
+
+ public String getVersion(long arg0) throws IOException
+ {
+ return getBundleStateMBean().getVersion(arg0);
+ }
+
+ public boolean isFragment(long arg0) throws IOException
+ {
+ return getBundleStateMBean().isFragment(arg0);
+ }
+
+ public boolean isPersistentlyStarted(long arg0) throws IOException
+ {
+ return getBundleStateMBean().isPersistentlyStarted(arg0);
+ }
+
+ public boolean isRemovalPending(long arg0) throws IOException
+ {
+ return getBundleStateMBean().isRemovalPending(arg0);
+ }
+
+ public boolean isRequired(long arg0) throws IOException
+ {
+ return getBundleStateMBean().isRequired(arg0);
+ }
+
+ public TabularData listBundles() throws IOException
+ {
+ return getBundleStateMBean().listBundles();
+ }
+
+ private Bundle assertBundle(long bundleId)
+ {
+ Bundle bundle = context.getBundle(bundleId);
+ if (bundle == null)
+ throw new IllegalArgumentException("No such bundle: " + bundleId);
+ return bundle;
+ }
+
+ private BundleContext assertBundleContext(long bundleId)
+ {
+ Bundle bundle = assertBundle(bundleId);
+ BundleContext bundleContext = bundle.getBundleContext();
+ return bundleContext;
+ }
+
+ /*
+ * 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
Deleted: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/FrameworkState.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/FrameworkState.java 2010-02-24 20:04:08 UTC (rev 101418)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/FrameworkState.java 2010-02-24 20:18:06 UTC (rev 101419)
@@ -1,217 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.jmx.internal;
-
-//$Id$
-
-import java.io.IOException;
-
-import javax.management.MBeanServer;
-import javax.management.NotCompliantMBeanException;
-import javax.management.ObjectName;
-import javax.management.StandardMBean;
-import javax.management.openmbean.CompositeData;
-
-import org.jboss.osgi.jmx.FrameworkMBeanExt;
-import org.jboss.osgi.spi.management.ObjectNameFactory;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.jmx.framework.FrameworkMBean;
-import org.osgi.service.packageadmin.PackageAdmin;
-
-/**
- * An extension to {@link FrameworkMBean}.
- *
- * @author thomas.diesler at jboss.com
- * @since 23-Feb-2009
- */
-public class FrameworkState extends AbstractStateMBean implements FrameworkMBeanExt
-{
-
- public FrameworkState(BundleContext context, MBeanServer mbeanServer)
- {
- super(context, mbeanServer);
- }
-
- @Override
- ObjectName getObjectName()
- {
- return ObjectNameFactory.create(OBJECTNAME);
- }
-
- @Override
- StandardMBean getStandardMBean() throws NotCompliantMBeanException
- {
- return new StandardMBean(this, FrameworkMBeanExt.class);
- }
-
- @Override
- public void refreshAllPackages()
- {
- ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
- PackageAdmin service = (PackageAdmin)context.getService(sref);
- service.refreshPackages(null);
- }
-
- @Override
- public boolean resolveAllBundles()
- {
- ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
- PackageAdmin service = (PackageAdmin)context.getService(sref);
- return service.resolveBundles(null);
- }
-
- public int getFrameworkStartLevel() throws IOException
- {
- return getFrameworkMBean().getFrameworkStartLevel();
- }
-
- public int getInitialBundleStartLevel() throws IOException
- {
- return getFrameworkMBean().getInitialBundleStartLevel();
- }
-
- public long installBundle(String arg0, String arg1) throws IOException
- {
- return getFrameworkMBean().installBundle(arg0, arg1);
- }
-
- public long installBundle(String arg0) throws IOException
- {
- return getFrameworkMBean().installBundle(arg0);
- }
-
- public CompositeData installBundles(String[] arg0, String[] arg1) throws IOException
- {
- return getFrameworkMBean().installBundles(arg0, arg1);
- }
-
- public CompositeData installBundles(String[] arg0) throws IOException
- {
- return getFrameworkMBean().installBundles(arg0);
- }
-
- public void refreshPackages(long arg0) throws IOException
- {
- getFrameworkMBean().refreshPackages(arg0);
- }
-
- public CompositeData refreshPackages(long[] arg0) throws IOException
- {
- return getFrameworkMBean().refreshPackages(arg0);
- }
-
- public boolean resolveBundle(long arg0) throws IOException
- {
- return getFrameworkMBean().resolveBundle(arg0);
- }
-
- public boolean resolveBundles(long[] arg0) throws IOException
- {
- return getFrameworkMBean().resolveBundles(arg0);
- }
-
- public void restartFramework() throws IOException
- {
- getFrameworkMBean().restartFramework();
- }
-
- public void setBundleStartLevel(long arg0, int arg1) throws IOException
- {
- getFrameworkMBean().setBundleStartLevel(arg0, arg1);
- }
-
- public CompositeData setBundleStartLevels(long[] arg0, int[] arg1) throws IOException
- {
- return getFrameworkMBean().setBundleStartLevels(arg0, arg1);
- }
-
- public void setFrameworkStartLevel(int arg0) throws IOException
- {
- getFrameworkMBean().setFrameworkStartLevel(arg0);
- }
-
- public void setInitialBundleStartLevel(int arg0) throws IOException
- {
- getFrameworkMBean().setInitialBundleStartLevel(arg0);
- }
-
- public void shutdownFramework() throws IOException
- {
- getFrameworkMBean().shutdownFramework();
- }
-
- public void startBundle(long arg0) throws IOException
- {
- getFrameworkMBean().startBundle(arg0);
- }
-
- public CompositeData startBundles(long[] arg0) throws IOException
- {
- return getFrameworkMBean().startBundles(arg0);
- }
-
- public void stopBundle(long arg0) throws IOException
- {
- getFrameworkMBean().stopBundle(arg0);
- }
-
- public CompositeData stopBundles(long[] arg0) throws IOException
- {
- return getFrameworkMBean().stopBundles(arg0);
- }
-
- public void uninstallBundle(long arg0) throws IOException
- {
- getFrameworkMBean().uninstallBundle(arg0);
- }
-
- public CompositeData uninstallBundles(long[] arg0) throws IOException
- {
- return getFrameworkMBean().uninstallBundles(arg0);
- }
-
- public void updateBundle(long arg0, String arg1) throws IOException
- {
- getFrameworkMBean().updateBundle(arg0, arg1);
- }
-
- public void updateBundle(long arg0) throws IOException
- {
- getFrameworkMBean().updateBundle(arg0);
- }
-
- public CompositeData updateBundles(long[] arg0, String[] arg1) throws IOException
- {
- return getFrameworkMBean().updateBundles(arg0, arg1);
- }
-
- public CompositeData updateBundles(long[] arg0) throws IOException
- {
- return getFrameworkMBean().updateBundles(arg0);
- }
-
- public void updateFramework() throws IOException
- {
- getFrameworkMBean().updateFramework();
- }
-}
\ No newline at end of file
Copied: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/FrameworkStateExt.java (from rev 101404, projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/FrameworkState.java)
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/FrameworkStateExt.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/FrameworkStateExt.java 2010-02-24 20:18:06 UTC (rev 101419)
@@ -0,0 +1,217 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.jmx.internal;
+
+//$Id$
+
+import java.io.IOException;
+
+import javax.management.MBeanServer;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectName;
+import javax.management.StandardMBean;
+import javax.management.openmbean.CompositeData;
+
+import org.jboss.osgi.jmx.FrameworkMBeanExt;
+import org.jboss.osgi.spi.management.ObjectNameFactory;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.jmx.framework.FrameworkMBean;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+/**
+ * An extension to {@link FrameworkMBean}.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 23-Feb-2009
+ */
+public class FrameworkStateExt extends AbstractState implements FrameworkMBeanExt
+{
+
+ public FrameworkStateExt(BundleContext context, MBeanServer mbeanServer)
+ {
+ super(context, mbeanServer);
+ }
+
+ @Override
+ ObjectName getObjectName()
+ {
+ return ObjectNameFactory.create(OBJECTNAME);
+ }
+
+ @Override
+ StandardMBean getStandardMBean() throws NotCompliantMBeanException
+ {
+ return new StandardMBean(this, FrameworkMBeanExt.class);
+ }
+
+ @Override
+ public void refreshAllPackages()
+ {
+ ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
+ PackageAdmin service = (PackageAdmin)context.getService(sref);
+ service.refreshPackages(null);
+ }
+
+ @Override
+ public boolean resolveAllBundles()
+ {
+ ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
+ PackageAdmin service = (PackageAdmin)context.getService(sref);
+ return service.resolveBundles(null);
+ }
+
+ public int getFrameworkStartLevel() throws IOException
+ {
+ return getFrameworkMBean().getFrameworkStartLevel();
+ }
+
+ public int getInitialBundleStartLevel() throws IOException
+ {
+ return getFrameworkMBean().getInitialBundleStartLevel();
+ }
+
+ public long installBundle(String arg0, String arg1) throws IOException
+ {
+ return getFrameworkMBean().installBundle(arg0, arg1);
+ }
+
+ public long installBundle(String arg0) throws IOException
+ {
+ return getFrameworkMBean().installBundle(arg0);
+ }
+
+ public CompositeData installBundles(String[] arg0, String[] arg1) throws IOException
+ {
+ return getFrameworkMBean().installBundles(arg0, arg1);
+ }
+
+ public CompositeData installBundles(String[] arg0) throws IOException
+ {
+ return getFrameworkMBean().installBundles(arg0);
+ }
+
+ public void refreshPackages(long arg0) throws IOException
+ {
+ getFrameworkMBean().refreshPackages(arg0);
+ }
+
+ public CompositeData refreshPackages(long[] arg0) throws IOException
+ {
+ return getFrameworkMBean().refreshPackages(arg0);
+ }
+
+ public boolean resolveBundle(long arg0) throws IOException
+ {
+ return getFrameworkMBean().resolveBundle(arg0);
+ }
+
+ public boolean resolveBundles(long[] arg0) throws IOException
+ {
+ return getFrameworkMBean().resolveBundles(arg0);
+ }
+
+ public void restartFramework() throws IOException
+ {
+ getFrameworkMBean().restartFramework();
+ }
+
+ public void setBundleStartLevel(long arg0, int arg1) throws IOException
+ {
+ getFrameworkMBean().setBundleStartLevel(arg0, arg1);
+ }
+
+ public CompositeData setBundleStartLevels(long[] arg0, int[] arg1) throws IOException
+ {
+ return getFrameworkMBean().setBundleStartLevels(arg0, arg1);
+ }
+
+ public void setFrameworkStartLevel(int arg0) throws IOException
+ {
+ getFrameworkMBean().setFrameworkStartLevel(arg0);
+ }
+
+ public void setInitialBundleStartLevel(int arg0) throws IOException
+ {
+ getFrameworkMBean().setInitialBundleStartLevel(arg0);
+ }
+
+ public void shutdownFramework() throws IOException
+ {
+ getFrameworkMBean().shutdownFramework();
+ }
+
+ public void startBundle(long arg0) throws IOException
+ {
+ getFrameworkMBean().startBundle(arg0);
+ }
+
+ public CompositeData startBundles(long[] arg0) throws IOException
+ {
+ return getFrameworkMBean().startBundles(arg0);
+ }
+
+ public void stopBundle(long arg0) throws IOException
+ {
+ getFrameworkMBean().stopBundle(arg0);
+ }
+
+ public CompositeData stopBundles(long[] arg0) throws IOException
+ {
+ return getFrameworkMBean().stopBundles(arg0);
+ }
+
+ public void uninstallBundle(long arg0) throws IOException
+ {
+ getFrameworkMBean().uninstallBundle(arg0);
+ }
+
+ public CompositeData uninstallBundles(long[] arg0) throws IOException
+ {
+ return getFrameworkMBean().uninstallBundles(arg0);
+ }
+
+ public void updateBundle(long arg0, String arg1) throws IOException
+ {
+ getFrameworkMBean().updateBundle(arg0, arg1);
+ }
+
+ public void updateBundle(long arg0) throws IOException
+ {
+ getFrameworkMBean().updateBundle(arg0);
+ }
+
+ public CompositeData updateBundles(long[] arg0, String[] arg1) throws IOException
+ {
+ return getFrameworkMBean().updateBundles(arg0, arg1);
+ }
+
+ public CompositeData updateBundles(long[] arg0) throws IOException
+ {
+ return getFrameworkMBean().updateBundles(arg0);
+ }
+
+ public void updateFramework() throws IOException
+ {
+ getFrameworkMBean().updateFramework();
+ }
+}
\ No newline at end of file
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 20:04:08 UTC (rev 101418)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java 2010-02-24 20:18:06 UTC (rev 101419)
@@ -56,10 +56,9 @@
private String jmxRmiPort;
private String rmiAdaptorPath;
private MBeanServer mbeanServer;
- private FrameworkState frameworkState;
- private ServiceState serviceState;
- private BundleState bundleState;
- private ManagedBundleTracker bundleTracker;
+ private FrameworkStateExt frameworkState;
+ private ServiceStateExt serviceState;
+ private BundleStateExt bundleState;
public void start(BundleContext context)
{
@@ -71,21 +70,17 @@
BundleContext sysContext = context.getBundle(0).getBundleContext();
// Register the FrameworkMBean
- frameworkState = new FrameworkState(sysContext, mbeanServer);
+ frameworkState = new FrameworkStateExt(sysContext, mbeanServer);
frameworkState.start();
// Register the ServiceStateMBean
- serviceState = new ServiceState(sysContext, mbeanServer);
+ serviceState = new ServiceStateExt(sysContext, mbeanServer);
serviceState.start();
// Register the BundleStateMBean
- bundleState = new BundleState(sysContext, mbeanServer);
+ bundleState = new BundleStateExt(sysContext, mbeanServer);
bundleState.start();
- // Start tracking the bundles
- bundleTracker = new ManagedBundleTracker(sysContext, mbeanServer);
- bundleTracker.open();
-
jmxHost = context.getProperty(JMXConstantsExt.REMOTE_JMX_HOST);
if (jmxHost == null)
jmxHost = "localhost";
@@ -114,9 +109,6 @@
// Unregister the BundleStateMBean
bundleState.stop();
- // Stop tracking the bundles
- bundleTracker.close();
-
if (jmxConnector != null)
{
jmxConnector.stop();
Deleted: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ManagedBundleTracker.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ManagedBundleTracker.java 2010-02-24 20:04:08 UTC (rev 101418)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ManagedBundleTracker.java 2010-02-24 20:18:06 UTC (rev 101419)
@@ -1,118 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.jmx.internal;
-
-//$Id$
-
-import javax.management.JMException;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
-import org.jboss.logging.Logger;
-import org.jboss.osgi.spi.management.ManagedBundle;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.util.tracker.BundleTracker;
-
-/**
- * Track and register/unregister bundles with the MBeanServer.
- *
- * @author thomas.diesler at jboss.com
- * @since 29-Oct-2009
- */
-public class ManagedBundleTracker extends BundleTracker
-{
- // Provide logging
- private static final Logger log = Logger.getLogger(ManagedBundleTracker.class);
-
- private BundleContext systemContext;
- private MBeanServer mbeanServer;
-
- public ManagedBundleTracker(BundleContext context, MBeanServer mbeanServer)
- {
- super(context, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE | Bundle.UNINSTALLED, null);
- this.mbeanServer = mbeanServer;
- this.systemContext = context;
- }
-
- @Override
- public Object addingBundle(Bundle bundle, BundleEvent event)
- {
- Object retObject = super.addingBundle(bundle, event);
- register(bundle);
- return retObject;
- }
-
- @Override
- public void modifiedBundle(Bundle bundle, BundleEvent event, Object object)
- {
- if (event != null && event.getType() == BundleEvent.UNINSTALLED)
- unregister(bundle);
- }
-
- private ManagedBundle register(Bundle bundle)
- {
- if (log.isTraceEnabled())
- log.trace("register(" + bundle + ")");
-
- try
- {
- ManagedBundle mb = new ManagedBundle(systemContext, bundle);
- ObjectName oname = mb.getObjectName();
-
- if (mbeanServer.isRegistered(oname) == false)
- {
- log.debug("Register managed bundle: " + oname);
- mbeanServer.registerMBean(mb, oname);
- }
-
- return mb;
- }
- catch (JMException ex)
- {
- log.error("Cannot register managed bundle", ex);
- return null;
- }
- }
-
- private void unregister(Bundle bundle)
- {
- if (log.isTraceEnabled())
- log.trace("unregister(" + bundle + ")");
-
- try
- {
- ObjectName oname = ManagedBundle.getObjectName(bundle);
- if (mbeanServer.isRegistered(oname))
- {
- log.debug("Unregister managed bundle: " + oname);
- mbeanServer.unregisterMBean(oname);
- }
-
- }
- catch (JMException ex)
- {
- log.error("Cannot register managed bundle", ex);
- }
- }
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ServiceState.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ServiceState.java 2010-02-24 20:04:08 UTC (rev 101418)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ServiceState.java 2010-02-24 20:18:06 UTC (rev 101419)
@@ -1,165 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.jmx.internal;
-
-//$Id$
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-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.osgi.jmx.ServiceStateMBeanExt;
-import org.jboss.osgi.spi.management.ObjectNameFactory;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.jmx.framework.ServiceStateMBean;
-
-/**
- * An extension to {@link ServiceStateMBean}.
- *
- * @author thomas.diesler at jboss.com
- * @since 23-Feb-2010
- */
-public class ServiceState extends AbstractStateMBean implements ServiceStateMBeanExt
-{
- public ServiceState(BundleContext context, MBeanServer mbeanServer)
- {
- super(context, mbeanServer);
- }
-
- @Override
- ObjectName getObjectName()
- {
- return ObjectNameFactory.create(OBJECTNAME);
- }
-
- @Override
- StandardMBean getStandardMBean() throws NotCompliantMBeanException
- {
- return new StandardMBean(this, ServiceStateMBeanExt.class);
- }
-
- @Override
- public CompositeData getService(String clazz) throws IOException
- {
- ServiceReference sref = context.getServiceReference(clazz);
- if (sref == null)
- return null;
-
- return getCompositeData(sref);
- }
-
- @Override
- public TabularData getServices(String clazz, String filter) throws IOException
- {
- ServiceReference[] srefs;
- try
- {
- srefs = context.getServiceReferences(clazz, filter);
- }
- catch (InvalidSyntaxException e)
- {
- throw new IllegalArgumentException("Invalid filter syntax: " + filter);
- }
-
- if (srefs == null)
- return null;
-
- TabularDataSupport tabularData = new TabularDataSupport(SERVICES_TYPE);
- for (ServiceReference sref : srefs)
- {
- CompositeDataSupport compData = getCompositeData(sref);
- tabularData.put(compData.get(IDENTIFIER), compData);
- }
-
- return tabularData;
- }
-
- private CompositeDataSupport getCompositeData(ServiceReference sref) throws IOException
- {
- Long serviceId = (Long)sref.getProperty(Constants.SERVICE_ID);
-
- List<Long> usingBundles = new ArrayList<Long>();
- for (Bundle aux : sref.getUsingBundles())
- usingBundles.add(aux.getBundleId());
-
- Map<String, Object> items = new HashMap<String, Object>();
- items.put(BUNDLE_IDENTIFIER, sref.getBundle().getBundleId());
- items.put(IDENTIFIER, serviceId);
- items.put(OBJECT_CLASS, sref.getProperty(Constants.OBJECTCLASS));
- items.put(USING_BUNDLES, usingBundles.toArray(new Long[usingBundles.size()]));
-
- // [TODO] Remove once ServiceType does not require this item any more
- items.put(PROPERTIES, getProperties(serviceId));
-
- CompositeDataSupport compData;
- try
- {
- compData = new CompositeDataSupport(SERVICE_TYPE, items);
- }
- catch (OpenDataException ex)
- {
- throw new IllegalStateException(ex);
- }
- return compData;
- }
-
- public long getBundleIdentifier(long arg0) throws IOException
- {
- return getServiceStateMBean().getBundleIdentifier(arg0);
- }
-
- public String[] getObjectClass(long arg0) throws IOException
- {
- return getServiceStateMBean().getObjectClass(arg0);
- }
-
- public TabularData getProperties(long arg0) throws IOException
- {
- return getServiceStateMBean().getProperties(arg0);
- }
-
- public long[] getUsingBundles(long arg0) throws IOException
- {
- return getServiceStateMBean().getUsingBundles(arg0);
- }
-
- public TabularData listServices() throws IOException
- {
- return getServiceStateMBean().listServices();
- }
-}
\ No newline at end of file
Copied: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ServiceStateExt.java (from rev 101404, projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ServiceState.java)
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ServiceStateExt.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ServiceStateExt.java 2010-02-24 20:18:06 UTC (rev 101419)
@@ -0,0 +1,171 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.jmx.internal;
+
+//$Id$
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+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.osgi.jmx.ServiceStateMBeanExt;
+import org.jboss.osgi.spi.management.ObjectNameFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.jmx.framework.ServiceStateMBean;
+
+/**
+ * An extension to {@link ServiceStateMBean}.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 23-Feb-2010
+ */
+public class ServiceStateExt extends AbstractState implements ServiceStateMBeanExt
+{
+ public ServiceStateExt(BundleContext context, MBeanServer mbeanServer)
+ {
+ super(context, mbeanServer);
+ }
+
+ @Override
+ ObjectName getObjectName()
+ {
+ return ObjectNameFactory.create(OBJECTNAME);
+ }
+
+ @Override
+ StandardMBean getStandardMBean() throws NotCompliantMBeanException
+ {
+ return new StandardMBean(this, ServiceStateMBeanExt.class);
+ }
+
+ @Override
+ public CompositeData getService(String clazz) throws IOException
+ {
+ ServiceReference sref = context.getServiceReference(clazz);
+ if (sref == null)
+ return null;
+
+ return getCompositeData(sref);
+ }
+
+ @Override
+ public TabularData getServices(String clazz, String filter) throws IOException
+ {
+ ServiceReference[] srefs;
+ try
+ {
+ srefs = context.getServiceReferences(clazz, filter);
+ }
+ catch (InvalidSyntaxException e)
+ {
+ throw new IllegalArgumentException("Invalid filter syntax: " + filter);
+ }
+
+ if (srefs == null)
+ return null;
+
+ TabularDataSupport tabularData = new TabularDataSupport(SERVICES_TYPE);
+ for (ServiceReference sref : srefs)
+ {
+ CompositeDataSupport compData = getCompositeData(sref);
+ tabularData.put(compData.get(IDENTIFIER), compData);
+ }
+
+ return tabularData;
+ }
+
+ private CompositeDataSupport getCompositeData(ServiceReference sref) throws IOException
+ {
+ Long serviceId = (Long)sref.getProperty(Constants.SERVICE_ID);
+
+ // Get the array of using bundles identifiers
+ List<Long> usingIdentifiers = new ArrayList<Long>();
+ Bundle[] usingBundles = sref.getUsingBundles();
+ if (usingBundles != null)
+ {
+ for (Bundle aux : usingBundles)
+ usingIdentifiers.add(aux.getBundleId());
+ }
+ Long[] usingArr = usingIdentifiers.toArray(new Long[usingIdentifiers.size()]);
+
+ Map<String, Object> items = new HashMap<String, Object>();
+ items.put(BUNDLE_IDENTIFIER, sref.getBundle().getBundleId());
+ items.put(IDENTIFIER, serviceId);
+ items.put(OBJECT_CLASS, sref.getProperty(Constants.OBJECTCLASS));
+ items.put(USING_BUNDLES, usingArr);
+
+ // [TODO] Remove once ServiceType does not require this item any more
+ items.put(PROPERTIES, getProperties(serviceId));
+
+ CompositeDataSupport compData;
+ try
+ {
+ compData = new CompositeDataSupport(SERVICE_TYPE, items);
+ }
+ catch (OpenDataException ex)
+ {
+ throw new IllegalStateException(ex);
+ }
+ return compData;
+ }
+
+ public long getBundleIdentifier(long arg0) throws IOException
+ {
+ return getServiceStateMBean().getBundleIdentifier(arg0);
+ }
+
+ public String[] getObjectClass(long arg0) throws IOException
+ {
+ return getServiceStateMBean().getObjectClass(arg0);
+ }
+
+ public TabularData getProperties(long arg0) throws IOException
+ {
+ return getServiceStateMBean().getProperties(arg0);
+ }
+
+ public long[] getUsingBundles(long arg0) throws IOException
+ {
+ return getServiceStateMBean().getUsingBundles(arg0);
+ }
+
+ public TabularData listServices() throws IOException
+ {
+ return getServiceStateMBean().listServices();
+ }
+}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java 2010-02-24 20:04:08 UTC (rev 101418)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java 2010-02-24 20:18:06 UTC (rev 101419)
@@ -1,201 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.spi.management;
-
-//$Id$
-
-import static org.jboss.osgi.spi.OSGiConstants.DOMAIN_NAME;
-
-import java.io.File;
-import java.net.URL;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.Hashtable;
-
-import javax.management.ObjectName;
-
-import org.jboss.logging.Logger;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.Version;
-import org.osgi.service.packageadmin.PackageAdmin;
-
-/**
- * The managed view of an OSGi Bundle
- *
- * @author thomas.diesler at jboss.com
- * @since 23-Jan-2009
- */
-public class ManagedBundle implements ManagedBundleMBean
-{
- // Provide logging
- private static final Logger log = Logger.getLogger(ManagedBundle.class);
-
- public static final String PROPERTY_ID = "id";
- public static final String PROPERTY_SYMBOLIC_NAME = "name";
- public static final String PROPERTY_VERSION = "version";
-
- private BundleContext systemContext;
- private Bundle bundle;
- private ObjectName oname;
-
- public ManagedBundle(BundleContext syscontext, Bundle bundle)
- {
- if (syscontext == null)
- throw new IllegalArgumentException("Null system context");
- if (bundle == null)
- throw new IllegalArgumentException("Null bundle");
-
- this.bundle = bundle;
- this.systemContext = syscontext;
- this.oname = getObjectName(bundle);
-
- if (log.isTraceEnabled())
- log.trace("new ManagedBundle[" + oname + "]");
- }
-
- public static ObjectName getObjectName(Bundle bundle)
- {
- if (bundle == null)
- throw new IllegalArgumentException("Null bundle");
-
- long id = bundle.getBundleId();
- String name = bundle.getSymbolicName();
- Version version = bundle.getVersion();
- return getObjectName(id, name, version);
- }
-
- public static ObjectName getObjectName(long id, String name, Version version)
- {
- String oname = DOMAIN_NAME + ":" + PROPERTY_ID + "=" + id + "," + PROPERTY_SYMBOLIC_NAME + "=" + name + "," + PROPERTY_VERSION + "=" + version;
- return ObjectNameFactory.create(oname);
- }
-
- @Override
- public ObjectName getObjectName()
- {
- return oname;
- }
-
- @Override
- public String getProperty(String key)
- {
- String value = bundle.getBundleContext().getProperty(key);
-
- if (log.isTraceEnabled())
- log.trace("getProperty[" + oname + "](" + key + ") => " + value);
-
- return value;
- }
-
- @Override
- public Dictionary<String, String> getHeaders()
- {
- return getHeaders(null);
- }
-
- @Override
- @SuppressWarnings("rawtypes")
- public Dictionary<String, String> getHeaders(String locale)
- {
- Hashtable<String, String> retHeaders = new Hashtable<String, String>();
- Dictionary bundleHeaders = bundle.getHeaders(locale);
- Enumeration keys = bundleHeaders.keys();
- while (keys.hasMoreElements())
- {
- String key = (String)keys.nextElement();
- String value = (String)bundleHeaders.get(key);
- retHeaders.put(key, value);
- }
-
- if (log.isTraceEnabled())
- log.trace("getHeaders[" + oname + "](" + locale + ") => " + retHeaders);
-
- return retHeaders;
- }
-
- @Override
- public String getEntry(String path)
- {
- URL url = bundle.getEntry(path);
- String entry = url != null ? url.toExternalForm() : null;
-
- if (log.isTraceEnabled())
- log.trace("getEntry[" + oname + "](" + path + ") => " + entry);
-
- return entry;
- }
-
- @Override
- public String getResource(String name)
- {
- URL url = bundle.getResource(name);
- String resource = url != null ? url.toExternalForm() : null;
-
- if (log.isTraceEnabled())
- log.trace("getResource[" + oname + "](" + name + ") => " + resource);
-
- return resource;
- }
-
- @Override
- public ObjectName loadClass(String name) throws ClassNotFoundException
- {
- Class<?> clazz = bundle.loadClass(name);
- Bundle providingBundle = getPackageAdmin().getBundle(clazz);
- ObjectName oname = providingBundle != null ? getObjectName(providingBundle) : null;
-
- if (log.isTraceEnabled())
- log.trace("loadClass[" + oname + "](" + name + ") => " + oname);
-
- return oname;
- }
-
- @Override
- public File getDataFile(String filename)
- {
- BundleContext context = bundle.getBundleContext();
- File dataFile = context.getDataFile(filename);
-
- if (log.isTraceEnabled())
- log.trace("getDataFile[" + oname + "](" + filename + ") => " + dataFile);
-
- return dataFile;
- }
-
- @Override
- public void update() throws BundleException
- {
- if (log.isTraceEnabled())
- log.trace("update[" + oname + "]");
-
- bundle.update();
- }
-
- private PackageAdmin getPackageAdmin()
- {
- ServiceReference sref = systemContext.getServiceReference(PackageAdmin.class.getName());
- return (PackageAdmin)systemContext.getService(sref);
- }
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundleMBean.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundleMBean.java 2010-02-24 20:04:08 UTC (rev 101418)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/management/ManagedBundleMBean.java 2010-02-24 20:18:06 UTC (rev 101419)
@@ -1,98 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.spi.management;
-
-//$Id$
-
-import java.io.File;
-import java.util.Dictionary;
-
-import javax.management.ObjectName;
-
-import org.osgi.framework.BundleException;
-
-/**
- * The managed view of an OSGi Bundle.
- *
- * Bundles are registered under the name
- *
- * jboss.osgi:name=[SymbolicName],id=[BundleId],version=[BundleVersion]
- *
- * @author thomas.diesler at jboss.com
- * @since 04-Mar-2009
- */
-public interface ManagedBundleMBean
-{
- /**
- * Get the bundles object name.
- */
- ObjectName getObjectName();
-
- /**
- * Returns the bundle manifest headers
- */
- Dictionary<String, String> getHeaders();
-
- /**
- * Returns this bundle's Manifest headers and values localized to the specified locale.
- */
- Dictionary<String, String> getHeaders(String locale);
-
- /**
- * Returns the value of the specified property from the BundleContext.
- */
- String getProperty(String key);
-
- /**
- * Loads the specified class using this bundle's class loader.
- *
- * @param name The name of the class to load
- * @return The object name of the bundle that is wired to this bundle class loader and contains the class.
- * @throws ClassNotFoundException If no such class can be found or if this bundle is a fragment bundle
- */
- ObjectName loadClass(String name) throws ClassNotFoundException;
-
- /**
- * Returns a string encoded URL to the entry at the specified path in this bundle.
- *
- * @param path The path name of the entry
- * @return A URL to the entry, or null if no entry could be found
- */
- String getEntry(String path);
-
- /**
- * Find the specified resource from this bundle's class loader.
- * @param name The name of the resource.
- * @return A string encoded URL to the named resource, or null if the resource could not be found
- */
- String getResource(String name);
-
- /**
- * Creates a File object for a file in the persistent storage area provided for the bundle by the Framework.
- */
- File getDataFile(String filename);
-
- /**
- * Update this bundle.
- */
- void update() throws BundleException;
-}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteBundle.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteBundle.java 2010-02-24 20:04:08 UTC (rev 101418)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteBundle.java 2010-02-24 20:18:06 UTC (rev 101419)
@@ -29,21 +29,26 @@
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
+import java.util.Collection;
import java.util.Dictionary;
+import java.util.Hashtable;
import javax.management.InstanceNotFoundException;
import javax.management.ObjectName;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
import org.jboss.logging.Logger;
+import org.jboss.osgi.jmx.BundleStateMBeanExt;
import org.jboss.osgi.spi.management.MBeanProxy;
-import org.jboss.osgi.spi.management.ManagedBundle;
-import org.jboss.osgi.spi.management.ManagedBundleMBean;
+import org.jboss.osgi.spi.management.ObjectNameFactory;
import org.jboss.osgi.spi.util.UnmodifiableDictionary;
import org.jboss.osgi.testing.OSGiBundle;
import org.jboss.osgi.testing.OSGiRuntime;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Version;
+import org.osgi.jmx.JmxConstants;
import org.osgi.jmx.framework.BundleStateMBean;
/**
@@ -60,8 +65,7 @@
private long bundleId;
private String location;
private String symbolicName;
- private ObjectName objectName;
- private ManagedBundleMBean bundleMBean;
+ private BundleStateMBeanExt bundleState;
private Dictionary<String, String> defaultHeaders;
private Dictionary<String, String> rawHeaders;
private Version version;
@@ -72,29 +76,41 @@
super(runtime);
this.bundleId = bundleId;
- BundleStateMBean bundleState = runtime.getBundleStateMBean();
+ ObjectName objectName = ObjectNameFactory.create(BundleStateMBeanExt.OBJECTNAME);
+ bundleState = MBeanProxy.get(runtime.getMBeanServer(), objectName, BundleStateMBeanExt.class);
try
{
symbolicName = bundleState.getSymbolicName(bundleId);
location = bundleState.getLocation(bundleId);
-
+
String versionStr = bundleState.getVersion(bundleId);
version = Version.parseVersion(versionStr);
+
+ // The getHeaders methods must continue to provide the manifest header
+ // information after the bundle enters the UNINSTALLED state.
+ defaultHeaders = getHeadersInternal(null);
+ rawHeaders = getHeadersInternal("");
}
catch (IOException ex)
{
throw new IllegalStateException("Cannot initialize remote bundle", ex);
}
-
- objectName = ManagedBundle.getObjectName(bundleId, symbolicName, version);
- bundleMBean = MBeanProxy.get(runtime.getMBeanServer(), objectName, ManagedBundleMBean.class);
-
- // The getHeaders methods must continue to provide the manifest header
- // information after the bundle enters the UNINSTALLED state.
- defaultHeaders = bundleMBean.getHeaders(null);
- rawHeaders = bundleMBean.getHeaders("");
}
+ @SuppressWarnings("unchecked")
+ private Dictionary<String, String> getHeadersInternal(String locale) throws IOException
+ {
+ Dictionary<String, String> defaultHeaders = new Hashtable<String, String>();
+ TabularData headers = bundleState.getHeaders(bundleId, null);
+ for (CompositeData aux : (Collection<CompositeData>)headers.values())
+ {
+ String key = (String)aux.get(JmxConstants.KEY);
+ String value = (String)aux.get(JmxConstants.VALUE);
+ defaultHeaders.put(key, value);
+ }
+ return new UnmodifiableDictionary(defaultHeaders);
+ }
+
@Override
public int getState()
{
@@ -117,7 +133,7 @@
return Bundle.STOPPING;
if ("UNINSTALLED".equals(state))
return Bundle.UNINSTALLED;
-
+
}
catch (Exception rte)
{
@@ -160,55 +176,102 @@
}
@Override
- @SuppressWarnings("unchecked")
public Dictionary<String, String> getHeaders(String locale)
{
if (locale == null)
- return new UnmodifiableDictionary(defaultHeaders);
+ {
+ return defaultHeaders;
+ }
else if (locale.length() == 0)
- return new UnmodifiableDictionary(rawHeaders);
+ {
+ return rawHeaders;
+ }
else
- return bundleMBean.getHeaders(locale);
+ {
+ try
+ {
+ return getHeadersInternal(locale);
+ }
+ catch (IOException ex)
+ {
+ throw new IllegalStateException("Cannot obtain headers for locale: " + locale, ex);
+ }
+ }
}
@Override
public String getProperty(String key)
{
assertNotUninstalled();
- return bundleMBean.getProperty(key);
+ try
+ {
+ CompositeData propData = bundleState.getProperty(bundleId, key);
+ if (propData == null)
+ return null;
+
+ return (String)propData.get(JmxConstants.VALUE);
+ }
+ catch (IOException ex)
+ {
+ throw new IllegalStateException("Cannot obtain property: " + key, ex);
+ }
}
@Override
public URL getEntry(String path)
{
assertNotUninstalled();
- return toURL(bundleMBean.getEntry(path), null);
+ try
+ {
+ return toURL(bundleState.getEntry(bundleId, path), null);
+ }
+ catch (IOException ex)
+ {
+ throw new IllegalStateException("Cannot getEntry: " + path, ex);
+ }
}
@Override
public URL getResource(String name)
{
assertNotUninstalled();
- return toURL(bundleMBean.getResource(name), null);
+ try
+ {
+ return toURL(bundleState.getResource(bundleId, name), null);
+ }
+ catch (IOException ex)
+ {
+ throw new IllegalStateException("Cannot getResource: " + name, ex);
+ }
}
@Override
public File getDataFile(String filename)
{
assertNotUninstalled();
- return bundleMBean.getDataFile(filename);
+ try
+ {
+ return new File(bundleState.getDataFile(bundleId, filename));
+ }
+ catch (IOException ex)
+ {
+ throw new IllegalStateException("Cannot getDataFile: " + filename, ex);
+ }
}
@Override
public OSGiBundle loadClass(String name) throws ClassNotFoundException
{
assertNotUninstalled();
- ObjectName providerBundle = bundleMBean.loadClass(name);
- if (providerBundle == null)
- return null;
-
- String bundleId = providerBundle.getKeyProperty(ManagedBundle.PROPERTY_ID);
- return getRuntime().getBundle(new Long(bundleId));
+ try
+ {
+ long exporterId = bundleState.loadClass(bundleId, name);
+ return getRuntime().getBundle(new Long(exporterId));
+ }
+ catch (IOException ex)
+ {
+ throw new IllegalStateException("Cannot loadClass: " + name, ex);
+ }
}
@Override
@@ -221,7 +284,7 @@
}
catch (IOException ex)
{
- throw new BundleException("Cannot start bundle: " + objectName, ex);
+ throw new BundleException("Cannot start bundle: " + bundleId, ex);
}
}
@@ -235,7 +298,7 @@
}
catch (IOException ex)
{
- throw new BundleException("Cannot stop bundle: " + objectName, ex);
+ throw new BundleException("Cannot stop bundle: " + bundleId, ex);
}
}
More information about the jboss-cvs-commits
mailing list