You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by da...@apache.org on 2011/10/28 13:18:01 UTC

svn commit: r1190247 - in /aries/trunk/sandbox/jmx-next: jmx-api/src/main/java/org/osgi/jmx/framework/ jmx-core/ jmx-core/src/main/java/org/apache/aries/jmx/codec/ jmx-core/src/main/java/org/apache/aries/jmx/framework/ tck/

Author: davidb
Date: Fri Oct 28 11:18:01 2011
New Revision: 1190247

URL: http://svn.apache.org/viewvc?rev=1190247&view=rev
Log:
Additions to BundleStateMBean:
* getBundle(id)
* getHeader(id, key)
* listBundles(String ... bundleTypeItems)

Modified:
    aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/BundleStateMBean.java
    aries/trunk/sandbox/jmx-next/jmx-core/pom.xml
    aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleData.java
    aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java
    aries/trunk/sandbox/jmx-next/tck/apply_to_tck.sh

Modified: aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/BundleStateMBean.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/BundleStateMBean.java?rev=1190247&r1=1190246&r2=1190247&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/BundleStateMBean.java (original)
+++ aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/BundleStateMBean.java Fri Oct 28 11:18:01 2011
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) OSGi Alliance (2009, 2010). All Rights Reserved.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -18,6 +18,7 @@ package org.osgi.jmx.framework;
 
 import java.io.IOException;
 
+import javax.management.openmbean.CompositeData;
 import javax.management.openmbean.CompositeType;
 import javax.management.openmbean.SimpleType;
 import javax.management.openmbean.TabularData;
@@ -30,7 +31,7 @@ import org.osgi.jmx.JmxConstants;
  * This MBean represents the Bundle state of the framework. This MBean also
  * emits events that clients can use to get notified of the changes in the
  * bundle state of the framework.
- * 
+ *
  * @version $Revision$
  * @ThreadSafe
  */
@@ -369,7 +370,7 @@ public interface BundleStateMBean {
 			EVENT,
 			"The type of the event: {INSTALLED=1, STARTED=2, STOPPED=4, UPDATED=8, UNINSTALLED=16}",
 			SimpleType.INTEGER);
-	
+
 	/**
 	 * The Composite Type that represents a bundle event.  This composite consists of:
 	 * <ul>
@@ -426,9 +427,11 @@ public interface BundleStateMBean {
 																BUNDLE_TYPE,
 																IDENTIFIER);
 
+    CompositeData getBundle(long id) throws IOException;
+
 	/**
 	 * Answer the list of identifiers of the bundles this bundle depends upon
-	 * 
+	 *
 	 * @param bundleIdentifier
 	 *            the bundle identifier
 	 * @return the list of bundle identifiers
@@ -441,18 +444,20 @@ public interface BundleStateMBean {
 
 	/**
 	 * Answer the bundle state of the system in tabular form.
-	 * 
+	 *
 	 * Each row of the returned table represents a single bundle. The Tabular
 	 * Data consists of Composite Data that is type by {@link #BUNDLES_TYPE}.
-	 * 
+	 *
 	 * @return the tabular representation of the bundle state
 	 * @throws IOException
 	 */
 	TabularData listBundles() throws IOException;
 
+	TabularData listBundles(String ... items) throws IOException;
+
 	/**
 	 * Answer the list of exported packages for this bundle.
-	 * 
+	 *
 	 * @param bundleId
 	 * @return the array of package names, combined with their version in the
 	 *         format &lt;packageName;version&gt;
@@ -466,7 +471,7 @@ public interface BundleStateMBean {
 	/**
 	 * Answer the list of the bundle ids of the fragments associated with this
 	 * bundle
-	 * 
+	 *
 	 * @param bundleId
 	 * @return the array of bundle identifiers
 	 * @throws IOException
@@ -479,7 +484,7 @@ public interface BundleStateMBean {
 	/**
 	 * Answer the headers for the bundle uniquely identified by the bundle id.
 	 * The Tabular Data is typed by the {@link #HEADERS_TYPE}.
-	 * 
+	 *
 	 * @param bundleId
 	 *            the unique identifier of the bundle
 	 * @return the table of associated header key and values
@@ -489,10 +494,11 @@ public interface BundleStateMBean {
 	 *             if the bundle indicated does not exist
 	 */
 	TabularData getHeaders(long bundleId) throws IOException;
+    String getHeader(long bundleId, String key) throws IOException;
 
 	/**
 	 * Answer the list of bundle ids of the bundles which host a fragment
-	 * 
+	 *
 	 * @param fragment
 	 *            the bundle id of the fragment
 	 * @return the array of bundle identifiers
@@ -505,7 +511,7 @@ public interface BundleStateMBean {
 
 	/**
 	 * Answer the array of the packages imported by this bundle
-	 * 
+	 *
 	 * @param bundleId
 	 *            the bundle identifier
 	 * @return the array of package names, combined with their version in the
@@ -519,7 +525,7 @@ public interface BundleStateMBean {
 
 	/**
 	 * Answer the last modified time of a bundle
-	 * 
+	 *
 	 * @param bundleId
 	 *            the unique identifier of a bundle
 	 * @return the last modified time
@@ -533,7 +539,7 @@ public interface BundleStateMBean {
 	/**
 	 * Answer the list of service identifiers representing the services this
 	 * bundle exports
-	 * 
+	 *
 	 * @param bundleId
 	 *            the bundle identifier
 	 * @return the list of service identifiers
@@ -546,7 +552,7 @@ public interface BundleStateMBean {
 
 	/**
 	 * Answer the list of identifiers of the bundles which require this bundle
-	 * 
+	 *
 	 * @param bundleIdentifier
 	 *            the bundle identifier
 	 * @return the list of bundle identifiers
@@ -560,7 +566,7 @@ public interface BundleStateMBean {
 	/**
 	 * Answer the list of service identifiers which refer to the the services
 	 * this bundle is using
-	 * 
+	 *
 	 * @param bundleIdentifier
 	 *            the bundle identifier
 	 * @return the list of service identifiers
@@ -573,7 +579,7 @@ public interface BundleStateMBean {
 
 	/**
 	 * Answer the start level of the bundle
-	 * 
+	 *
 	 * @param bundleId
 	 *            the identifier of the bundle
 	 * @return the start level
@@ -586,7 +592,7 @@ public interface BundleStateMBean {
 
 	/**
 	 * Answer the symbolic name of the state of the bundle
-	 * 
+	 *
 	 * @param bundleId
 	 *            the identifier of the bundle
 	 * @return the string name of the bundle state
@@ -599,7 +605,7 @@ public interface BundleStateMBean {
 
 	/**
 	 * Answer the symbolic name of the bundle
-	 * 
+	 *
 	 * @param bundleId
 	 *            the identifier of the bundle
 	 * @return the symbolic name
@@ -613,7 +619,7 @@ public interface BundleStateMBean {
 	/**
 	 * Answer if the bundle is persistently started when its start level is
 	 * reached
-	 * 
+	 *
 	 * @param bundleId
 	 *            the identifier of the bundle
 	 * @return true if the bundle is persistently started
@@ -626,7 +632,7 @@ public interface BundleStateMBean {
 
 	/**
 	 * Answer whether the bundle is a fragment or not
-	 * 
+	 *
 	 * @param bundleId
 	 *            the identifier of the bundle
 	 * @return true if the bundle is a fragment
@@ -639,7 +645,7 @@ public interface BundleStateMBean {
 
 	/**
 	 * Answer true if the bundle is pending removal
-	 * 
+	 *
 	 * @param bundleId
 	 *            the identifier of the bundle
 	 * @return true if the bundle is pending removal
@@ -652,7 +658,7 @@ public interface BundleStateMBean {
 
 	/**
 	 * Answer true if the bundle is required by another bundle
-	 * 
+	 *
 	 * @param bundleId
 	 *            the identifier of the bundle
 	 * @return true if the bundle is required by another bundle
@@ -665,7 +671,7 @@ public interface BundleStateMBean {
 
 	/**
 	 * Answer the location of the bundle.
-	 * 
+	 *
 	 * @param bundleId
 	 *            the identifier of the bundle
 	 * @return The location string of this bundle
@@ -678,7 +684,7 @@ public interface BundleStateMBean {
 
 	/**
 	 * Answer the location of the bundle.
-	 * 
+	 *
 	 * @param bundleId
 	 *            the identifier of the bundle
 	 * @return The location string of this bundle

Modified: aries/trunk/sandbox/jmx-next/jmx-core/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/pom.xml?rev=1190247&r1=1190246&r2=1190247&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/pom.xml (original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/pom.xml Fri Oct 28 11:18:01 2011
@@ -81,6 +81,7 @@
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
+            <version>4.3.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Modified: aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleData.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleData.java?rev=1190247&r1=1190246&r2=1190247&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleData.java (original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleData.java Fri Oct 28 11:18:01 2011
@@ -81,7 +81,7 @@ import org.osgi.service.startlevel.Start
  * <tt>BundleData</tt> represents BundleData Type @see {@link BundleStateMBean#BUNDLE_TYPE}. It is a codec for the
  * <code>CompositeData</code> representing an OSGi BundleData.
  * </p>
- * 
+ *
  * @version $Rev$ $Date$
  */
 public class BundleData {
@@ -227,48 +227,97 @@ public class BundleData {
 
     /**
      * Returns CompositeData representing a BundleData complete state typed by {@link BundleStateMBean#BUNDLE_TYPE}
-     * 
+     *
      * @return
      */
     public CompositeData toCompositeData() {
-        CompositeData result = null;
+        return toCompositeData(BundleStateMBean.BUNDLE_TYPE.keySet());
+    }
+
+    public CompositeData toCompositeData(Collection<String> itemNames) {
         Map<String, Object> items = new HashMap<String, Object>();
-        items.put(EXPORTED_PACKAGES, this.exportedPackages);
-        items.put(FRAGMENT, this.fragment);
-        items.put(FRAGMENTS, toLong(this.fragments));
-        items.put(HOSTS, toLong(this.hosts));
         items.put(IDENTIFIER, this.identifier);
-        items.put(IMPORTED_PACKAGES, this.importedPackages);
-        items.put(LAST_MODIFIED, this.lastModified);
-        items.put(LOCATION, this.location);
-        items.put(PERSISTENTLY_STARTED, this.persistentlyStarted);
-        items.put(REGISTERED_SERVICES, toLong(this.registeredServices));
-        items.put(REMOVAL_PENDING, this.removalPending);
-        items.put(REQUIRED, this.required);
-        items.put(REQUIRED_BUNDLES, toLong(this.requiredBundles));
-        items.put(REQUIRING_BUNDLES, toLong(this.requiringBundles));
-        items.put(SERVICES_IN_USE, toLong(this.servicesInUse));
-        items.put(START_LEVEL, this.bundleStartLevel);
-        items.put(STATE, this.state);
-        items.put(SYMBOLIC_NAME, this.symbolicName);
-        items.put(VERSION, this.version);
-        TabularData headerTable = new TabularDataSupport(HEADERS_TYPE);
-        for (Header header : this.headers) {
-            headerTable.put(header.toCompositeData());
+
+        if (itemNames.contains(EXPORTED_PACKAGES))
+            items.put(EXPORTED_PACKAGES, this.exportedPackages);
+
+        if (itemNames.contains(FRAGMENT))
+            items.put(FRAGMENT, this.fragment);
+
+        if (itemNames.contains(FRAGMENTS))
+            items.put(FRAGMENTS, toLong(this.fragments));
+
+        if (itemNames.contains(HOSTS))
+            items.put(HOSTS, toLong(this.hosts));
+
+        if (itemNames.contains(IMPORTED_PACKAGES))
+            items.put(IMPORTED_PACKAGES, this.importedPackages);
+
+        if (itemNames.contains(LAST_MODIFIED))
+            items.put(LAST_MODIFIED, this.lastModified);
+
+        if (itemNames.contains(LOCATION))
+            items.put(LOCATION, this.location);
+
+        if (itemNames.contains(PERSISTENTLY_STARTED))
+            items.put(PERSISTENTLY_STARTED, this.persistentlyStarted);
+
+        if (itemNames.contains(REGISTERED_SERVICES))
+            items.put(REGISTERED_SERVICES, toLong(this.registeredServices));
+
+        if (itemNames.contains(REMOVAL_PENDING))
+            items.put(REMOVAL_PENDING, this.removalPending);
+
+        if (itemNames.contains(REQUIRED))
+            items.put(REQUIRED, this.required);
+
+        if (itemNames.contains(REQUIRED_BUNDLES))
+            items.put(REQUIRED_BUNDLES, toLong(this.requiredBundles));
+
+        if (itemNames.contains(REQUIRING_BUNDLES))
+            items.put(REQUIRING_BUNDLES, toLong(this.requiringBundles));
+
+        if (itemNames.contains(SERVICES_IN_USE))
+            items.put(SERVICES_IN_USE, toLong(this.servicesInUse));
+
+        if (itemNames.contains(START_LEVEL))
+            items.put(START_LEVEL, this.bundleStartLevel);
+
+        if (itemNames.contains(STATE))
+            items.put(STATE, this.state);
+
+        if (itemNames.contains(SYMBOLIC_NAME))
+            items.put(SYMBOLIC_NAME, this.symbolicName);
+
+        if (itemNames.contains(VERSION))
+            items.put(VERSION, this.version);
+
+        if (itemNames.contains(HEADERS)) {
+            TabularData headerTable = new TabularDataSupport(HEADERS_TYPE);
+            for (Header header : this.headers) {
+                headerTable.put(header.toCompositeData());
+            }
+            items.put(HEADERS, headerTable);
         }
-        items.put(HEADERS, headerTable);
+
+        String[] allItemNames = BUNDLE_TYPE.keySet().toArray(new String [] {});
+        Object[] itemValues = new Object[allItemNames.length];
+        for (int i=0; i < allItemNames.length; i++) {
+            itemValues[i] = items.get(allItemNames[i]);
+        }
+
         try {
-            result = new CompositeDataSupport(BUNDLE_TYPE, items);
+            return new CompositeDataSupport(BUNDLE_TYPE, allItemNames, itemValues);
+            // return new CompositeDataSupport(BUNDLE_TYPE, items);
         } catch (OpenDataException e) {
             throw new IllegalStateException("Failed to create CompositeData for BundleData [" + this.identifier
                     + "]", e);
         }
-        return result;
     }
 
     /**
      * Constructs a <code>BundleData</code> object from the given <code>CompositeData</code>
-     * 
+     *
      * @param compositeData
      * @return
      * @throws IlleglArgumentException

Modified: aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java?rev=1190247&r1=1190246&r2=1190247&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java (original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java Fri Oct 28 11:18:01 2011
@@ -31,6 +31,8 @@ import static org.apache.aries.jmx.util.
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.List;
@@ -47,14 +49,15 @@ import javax.management.MBeanServer;
 import javax.management.Notification;
 import javax.management.NotificationBroadcasterSupport;
 import javax.management.ObjectName;
+import javax.management.openmbean.CompositeData;
 import javax.management.openmbean.TabularData;
 import javax.management.openmbean.TabularDataSupport;
 
 import org.apache.aries.jmx.JMXThreadFactory;
 import org.apache.aries.jmx.Logger;
 import org.apache.aries.jmx.codec.BundleData;
-import org.apache.aries.jmx.codec.BundleEventData;
 import org.apache.aries.jmx.codec.BundleData.Header;
+import org.apache.aries.jmx.codec.BundleEventData;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
@@ -67,7 +70,7 @@ import org.osgi.service.startlevel.Start
 /**
  * Implementation of <code>BundleStateMBean</code> which emits JMX <code>Notification</code> on <code>Bundle</code>
  * state changes
- * 
+ *
  * @version $Rev$ $Date$
  */
 public class BundleState extends NotificationBroadcasterSupport implements BundleStateMBean, MBeanRegistration {
@@ -129,6 +132,11 @@ public class BundleState extends Notific
         return headerTable;
     }
 
+    public String getHeader(long bundleId, String key) throws IOException {
+        Bundle bundle = resolveBundle(bundleContext, bundleId);
+        return bundle.getHeaders().get(key);
+    }
+
     /**
      * @see org.osgi.jmx.framework.BundleStateMBean#getHosts(long)
      */
@@ -257,20 +265,39 @@ public class BundleState extends Notific
         return isBundleRequiredByOthers(bundle, packageAdmin);
     }
 
+
+
+    public CompositeData getBundle(long id) throws IOException {
+        Bundle bundle = bundleContext.getBundle(id);
+        if (bundle == null)
+            return null;
+
+        BundleData data = new BundleData(bundleContext, bundle, packageAdmin, startLevel);
+        return data.toCompositeData();
+    }
+
     /**
      * @see org.osgi.jmx.framework.BundleStateMBean#listBundles()
      */
     public TabularData listBundles() throws IOException {
+        return listBundles(BundleStateMBean.BUNDLE_TYPE.keySet());
+    }
+
+    public TabularData listBundles(String ... items) throws IOException {
+        return listBundles(Arrays.asList(items));
+    }
+
+    private TabularData listBundles(Collection<String> items) throws IOException {
         Bundle[] containerBundles = bundleContext.getBundles();
         List<BundleData> bundleDatas = new ArrayList<BundleData>();
         if (containerBundles != null) {
             for (Bundle containerBundle : containerBundles) {
                 bundleDatas.add(new BundleData(bundleContext, containerBundle, packageAdmin, startLevel));
-            } 
+            }
         }
         TabularData bundleTable = new TabularDataSupport(BUNDLES_TYPE);
         for (BundleData bundleData : bundleDatas) {
-            bundleTable.put(bundleData.toCompositeData());
+            bundleTable.put(bundleData.toCompositeData(items));
         }
         return bundleTable;
     }
@@ -357,10 +384,10 @@ public class BundleState extends Notific
             }
             catch (Exception e) {
                // ignore
-            }  
+            }
         }
         if (eventDispatcher != null) {
-            eventDispatcher.shutdown(); 
+            eventDispatcher.shutdown();
         }
     }
 

Modified: aries/trunk/sandbox/jmx-next/tck/apply_to_tck.sh
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/tck/apply_to_tck.sh?rev=1190247&r1=1190246&r2=1190247&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/tck/apply_to_tck.sh (original)
+++ aries/trunk/sandbox/jmx-next/tck/apply_to_tck.sh Fri Oct 28 11:18:01 2011
@@ -11,7 +11,7 @@ LIB_BASE=$OSGI_GIT_DIR/cnf/repo/org.apac
 LIB_FILE=$LIB_BASE/org.apache.aries.impl.jmx-4.2.0.lib
 
 mkdir -p -v $JMX_TARGET_DIR/org.apache.aries.jmx
-cp $ARIES_DIR/jmx/jmx-bundle/target/org.apache.aries.jmx-0.3.1-SNAPSHOT.jar $JMX_TARGET_DIR/org.apache.aries.jmx/org.apache.aries.jmx-$ARIES_TARGET_VERSION.jar
+cp $ARIES_DIR/sandbox/jmx-next/jmx-bundle/target/org.apache.aries.jmx-0.3.1-SNAPSHOT.jar $JMX_TARGET_DIR/org.apache.aries.jmx/org.apache.aries.jmx-$ARIES_TARGET_VERSION.jar
 
 mkdir -p -v $JMX_TARGET_DIR/org.apache.aries.util
 cp $ARIES_DIR/util/target/org.apache.aries.util-0.4-SNAPSHOT.jar $JMX_TARGET_DIR/org.apache.aries.util/org.apache.aries.util-$ARIES_TARGET_VERSION.jar
@@ -22,4 +22,4 @@ echo "slf4j.simple; version=1.5.10" >> $
 echo "org.apache.aries.util; version=$ARIES_TARGET_VERSION" >> $LIB_FILE
 echo "org.apache.aries.jmx; version=$ARIES_TARGET_VERSION" >> $LIB_FILE
 
-cp $ARIES_DIR/jmx/tck/org.osgi.test.cases.jmx.bnd.bnd $OSGI_GIT_DIR/org.osgi.test.cases.jmx/bnd.bnd
+cp $ARIES_DIR/sandbox/jmx-next/tck/org.osgi.test.cases.jmx.bnd.bnd $OSGI_GIT_DIR/org.osgi.test.cases.jmx/bnd.bnd