[jboss-cvs] JBossAS SVN: r101401 - in projects/jboss-osgi/projects/bundles/jmx/trunk: jmx-api/src/main/java/org/jboss/osgi/jmx and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 24 09:59:24 EST 2010
Author: thomas.diesler at jboss.com
Date: 2010-02-24 09:59:23 -0500 (Wed, 24 Feb 2010)
New Revision: 101401
Added:
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/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/ServiceState.java
Removed:
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/FrameworkImpl.java
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ServiceStateImpl.java
Modified:
projects/jboss-osgi/projects/bundles/jmx/trunk/EEG-Feedback-JMX.txt
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-api/src/main/java/org/jboss/osgi/jmx/FrameworkMBeanExt.java
projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java
Log:
Add BundleStateMBeanExt
Modified: projects/jboss-osgi/projects/bundles/jmx/trunk/EEG-Feedback-JMX.txt
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/EEG-Feedback-JMX.txt 2010-02-24 14:46:52 UTC (rev 101400)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/EEG-Feedback-JMX.txt 2010-02-24 14:59:23 UTC (rev 101401)
@@ -1,15 +1,2 @@
$Id$
-------------------------------------------------------------------------------------------
-JMX FrameworkMBean does not allow to resolve/refresh all bundles
-https://www.osgi.org/members/bugzilla/show_bug.cgi?id=1586
-
-The signature and API docs of
-
-FrameworkMBean.refreshBundles(long[] bundleIdentifiers)
-FrameworkMBean.resolveBundles(long[] bundleIdentifiers)
-
-does not obviously allow to resolve/refresh all bundles.
-
-A client would be forced to collect all ids before making the call.
-PackageAdmin however uses a null paramter to mean 'all bundles'.
Added: 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 (rev 0)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-api/src/main/java/org/jboss/osgi/jmx/BundleStateMBeanExt.java 2010-02-24 14:59:23 UTC (rev 101401)
@@ -0,0 +1,101 @@
+/*
+ * 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;
+
+//$Id$
+
+import java.io.IOException;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
+
+import org.osgi.jmx.framework.BundleStateMBean;
+
+/**
+ * An extension to {@link BundleStateMBean}.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 24-Feb-2010
+ */
+public interface BundleStateMBeanExt extends BundleStateMBean
+{
+ /** The default object name: jboss.osgi:service=jmx,type=BundleState */
+ String OBJECTNAME = "jboss.osgi:service=jmx,type=BundleState";
+
+ /**
+ * Answer the bundle state for a single bundle.
+ * Composite Data that is type by {@link BundleStateMBean#BUNDLE_TYPE}.
+ *
+ * @param bundleId the bundle identifier
+ * @return The composite bundle information
+ * @throws IOException if the operation fails
+ * @throws IllegalArgumentException if the bundle indicated does not exist
+ */
+ CompositeData getBundle(long bundleId) throws IOException;
+
+ /**
+ * Answer the headers for the bundle uniquely identified by the bundle id.
+ * The Tabular Data is typed by the {@link BundleStateMBean#HEADERS_TYPE}.
+ *
+ * @param bundleId the unique identifier of the bundle
+ * @param locale The locale name into which the header values are to be localized.
+ * @throws IOException if the operation fails
+ * @throws IllegalArgumentException if the bundle indicated does not exist
+ */
+ TabularData getHeaders(long bundleId, String locale) 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
+ * @param name The name of the class to load
+ * @return The bundle id of the bundle that loaded the class.
+ * @throws ClassNotFoundException If no such class can be found or if the given bundle is a fragment bundle
+ */
+ long loadClass(long bundleId, String name) throws ClassNotFoundException, IOException;
+
+ /**
+ * Returns a string encoded URL to the entry at the specified path in the given bundle.
+ *
+ * @param bundleId the unique identifier of the 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(long bundleId, String path) throws IOException;
+
+ /**
+ * Find the specified resource from the given bundle's class loader.
+ *
+ * @param bundleId the unique identifier of the bundle
+ * @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(long bundleId, String name) throws IOException;
+
+ /**
+ * Get the string encoded file path in the persistent storage area provided for the given bundle.
+ *
+ * @param bundleId the unique identifier of the bundle
+ * @param filename A relative name to the file to be accessed
+ */
+ String getDataFile(long bundleId, String filename) throws IOException;
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-api/src/main/java/org/jboss/osgi/jmx/BundleStateMBeanExt.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-api/src/main/java/org/jboss/osgi/jmx/FrameworkMBeanExt.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-api/src/main/java/org/jboss/osgi/jmx/FrameworkMBeanExt.java 2010-02-24 14:46:52 UTC (rev 101400)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-api/src/main/java/org/jboss/osgi/jmx/FrameworkMBeanExt.java 2010-02-24 14:59:23 UTC (rev 101401)
@@ -25,7 +25,6 @@
//$Id$
-
/**
* An extension to {@link FrameworkMBean}.
*
Added: 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 (rev 0)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/AbstractStateMBean.java 2010-02-24 14:59:23 UTC (rev 101401)
@@ -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 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
Property changes on: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/AbstractStateMBean.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: 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 (rev 0)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/BundleState.java 2010-02-24 14:59:23 UTC (rev 101401)
@@ -0,0 +1,236 @@
+/*
+ * 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.Dictionary;
+
+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.TabularData;
+
+import org.jboss.logging.Logger;
+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
+ 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;
+ }
+
+ @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;
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/BundleState.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Deleted: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/FrameworkImpl.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/FrameworkImpl.java 2010-02-24 14:46:52 UTC (rev 101400)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/FrameworkImpl.java 2010-02-24 14:59:23 UTC (rev 101401)
@@ -1,266 +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.JMException;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.management.StandardMBean;
-import javax.management.openmbean.CompositeData;
-
-import org.jboss.logging.Logger;
-import org.jboss.osgi.jmx.FrameworkMBeanExt;
-import org.jboss.osgi.spi.management.MBeanProxy;
-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 FrameworkImpl implements FrameworkMBeanExt
-{
- // Provide logging
- private static final Logger log = Logger.getLogger(FrameworkImpl.class);
-
- private MBeanServer mbeanServer;
- private BundleContext context;
- private FrameworkMBean delegate;
-
- public FrameworkImpl(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;
- }
-
- @Override
- public void refreshAllPackages()
- {
- if (log.isTraceEnabled())
- log.trace("refreshPackages(null)");
-
- ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
- PackageAdmin service = (PackageAdmin)context.getService(sref);
- service.refreshPackages(null);
- }
-
- @Override
- public boolean resolveAllBundles()
- {
- if (log.isTraceEnabled())
- log.trace("resolveBundles(null)");
-
- ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
- PackageAdmin service = (PackageAdmin)context.getService(sref);
- return service.resolveBundles(null);
- }
-
- void start()
- {
- try
- {
- ObjectName objectName = ObjectNameFactory.create(FrameworkMBeanExt.OBJECTNAME);
- StandardMBean mbean = new StandardMBean(this, FrameworkMBeanExt.class);
- mbeanServer.registerMBean(mbean, objectName);
- }
- catch (JMException ex)
- {
- log.warn("Cannot register: " + FrameworkMBeanExt.OBJECTNAME);
- }
- }
-
- void stop()
- {
- try
- {
- ObjectName objectName = ObjectNameFactory.create(FrameworkMBeanExt.OBJECTNAME);
- if (mbeanServer.isRegistered(objectName))
- mbeanServer.unregisterMBean(objectName);
- }
- catch (JMException ex)
- {
- log.warn("Cannot register: " + FrameworkMBeanExt.OBJECTNAME);
- }
- }
-
- 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();
- }
-
- private FrameworkMBean getFrameworkMBean()
- {
- if (delegate == null)
- {
- ObjectName objectName = ObjectNameFactory.create(FrameworkMBean.OBJECTNAME);
- delegate = MBeanProxy.get(mbeanServer, objectName, FrameworkMBean.class);
- }
- return delegate;
- }
-}
\ No newline at end of file
Copied: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/FrameworkState.java (from rev 101378, projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/FrameworkImpl.java)
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/FrameworkState.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/FrameworkState.java 2010-02-24 14:59:23 UTC (rev 101401)
@@ -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 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
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 14:46:52 UTC (rev 101400)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/JMXServiceActivator.java 2010-02-24 14:59:23 UTC (rev 101401)
@@ -56,8 +56,8 @@
private String jmxRmiPort;
private String rmiAdaptorPath;
private MBeanServer mbeanServer;
- private FrameworkImpl framework;
- private ServiceStateImpl serviceState;
+ private FrameworkState framework;
+ private ServiceState serviceState;
private ManagedBundleTracker bundleTracker;
public void start(BundleContext context)
@@ -70,11 +70,11 @@
BundleContext sysContext = context.getBundle(0).getBundleContext();
// Register the FrameworkMBean
- framework = new FrameworkImpl(sysContext, mbeanServer);
+ framework = new FrameworkState(sysContext, mbeanServer);
framework.start();
// Register the ServiceStateMBean
- serviceState = new ServiceStateImpl(sysContext, mbeanServer);
+ serviceState = new ServiceState(sysContext, mbeanServer);
serviceState.start();
// Start tracking the bundles
Copied: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ServiceState.java (from rev 101378, projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ServiceStateImpl.java)
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ServiceState.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ServiceState.java 2010-02-24 14:59:23 UTC (rev 101401)
@@ -0,0 +1,165 @@
+/*
+ * 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
Deleted: projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ServiceStateImpl.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ServiceStateImpl.java 2010-02-24 14:46:52 UTC (rev 101400)
+++ projects/jboss-osgi/projects/bundles/jmx/trunk/jmx-bundle/src/main/java/org/jboss/osgi/jmx/internal/ServiceStateImpl.java 2010-02-24 14:59:23 UTC (rev 101401)
@@ -1,210 +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.JMException;
-import javax.management.MBeanServer;
-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.FrameworkMBeanExt;
-import org.jboss.osgi.jmx.ServiceStateMBeanExt;
-import org.jboss.osgi.spi.management.MBeanProxy;
-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 ServiceStateImpl implements ServiceStateMBeanExt
-{
- // Provide logging
- private static final Logger log = Logger.getLogger(ServiceStateImpl.class);
-
- private MBeanServer mbeanServer;
- private BundleContext context;
- private ServiceStateMBean delegate;
-
- public ServiceStateImpl(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;
- }
-
- @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;
- }
-
- void start()
- {
- try
- {
- ObjectName objectName = ObjectNameFactory.create(ServiceStateMBeanExt.OBJECTNAME);
- StandardMBean mbean = new StandardMBean(this, ServiceStateMBeanExt.class);
- mbeanServer.registerMBean(mbean, objectName);
- }
- catch (JMException ex)
- {
- log.warn("Cannot register: " + FrameworkMBeanExt.OBJECTNAME);
- }
- }
-
- void stop()
- {
- try
- {
- ObjectName objectName = ObjectNameFactory.create(ServiceStateMBeanExt.OBJECTNAME);
- if (mbeanServer.isRegistered(objectName))
- mbeanServer.unregisterMBean(objectName);
- }
- catch (JMException ex)
- {
- log.warn("Cannot register: " + FrameworkMBeanExt.OBJECTNAME);
- }
- }
-
- 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();
- }
-
- private ServiceStateMBean getServiceStateMBean()
- {
- if (delegate == null)
- {
- ObjectName objectName = ObjectNameFactory.create(ServiceStateMBean.OBJECTNAME);
- delegate = MBeanProxy.get(mbeanServer, objectName, ServiceStateMBean.class);
- }
- return delegate;
- }
-}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list