365709 Adding support for the new BundleState methods proposed in the JMX Update RFC
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/BundleState.java b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/BundleState.java
index 53cf7d5..8220e2f 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/BundleState.java
+++ b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/BundleState.java
@@ -19,6 +19,7 @@
import java.util.ArrayList;
import javax.management.Notification;
+import javax.management.openmbean.CompositeData;
import javax.management.openmbean.TabularData;
import javax.management.openmbean.TabularDataSupport;
@@ -88,136 +89,195 @@
* {@inheritDoc}
*/
public String[] getExportedPackages(long bundleId) throws IOException {
- return BundleUtil.getBundleExportedPackages(getBundle(bundleId));
+ return BundleUtil.getBundleExportedPackages(retrieveBundle(bundleId));
}
/**
* {@inheritDoc}
*/
public long[] getFragments(long bundleId) throws IOException {
- return BundleUtil.getBundleFragments(getBundle(bundleId));
+ return BundleUtil.getBundleFragments(retrieveBundle(bundleId));
}
/**
* {@inheritDoc}
*/
public TabularData getHeaders(long bundleId) throws IOException {
- return OSGiBundle.headerTable(getBundle(bundleId));
+ return OSGiBundle.headerTable(retrieveBundle(bundleId).getHeaders());
}
/**
* {@inheritDoc}
*/
public long[] getHosts(long fragment) throws IOException {
- return BundleUtil.getBundleHosts(getBundle(fragment));
+ return BundleUtil.getBundleHosts(retrieveBundle(fragment));
}
/**
* {@inheritDoc}
*/
public String[] getImportedPackages(long bundleId) throws IOException {
- return BundleUtil.getBundleImportedPackages(getBundle(bundleId));
+ return BundleUtil.getBundleImportedPackages(retrieveBundle(bundleId));
}
/**
* {@inheritDoc}
*/
public long getLastModified(long bundleId) throws IOException {
- return getBundle(bundleId).getLastModified();
+ return retrieveBundle(bundleId).getLastModified();
}
/**
* {@inheritDoc}
*/
public long[] getRegisteredServices(long bundleId) throws IOException {
- return BundleUtil.serviceIds(getBundle(bundleId).getRegisteredServices());
+ return BundleUtil.serviceIds(retrieveBundle(bundleId).getRegisteredServices());
}
/**
* {@inheritDoc}
*/
public long[] getRequiringBundles(long bundleId) throws IOException {
- return BundleUtil.getRequiringBundles(getBundle(bundleId));
+ return BundleUtil.getRequiringBundles(retrieveBundle(bundleId));
}
/**
* {@inheritDoc}
*/
public long[] getServicesInUse(long bundleIdentifier) throws IOException {
- return BundleUtil.serviceIds(getBundle(bundleIdentifier).getServicesInUse());
+ return BundleUtil.serviceIds(retrieveBundle(bundleIdentifier).getServicesInUse());
}
/**
* {@inheritDoc}
*/
public int getStartLevel(long bundleId) throws IOException {
- return BundleUtil.getBundleStartLevel(getBundle(bundleId));
+ return BundleUtil.getBundleStartLevel(retrieveBundle(bundleId));
}
/**
* {@inheritDoc}
*/
public String getState(long bundleId) throws IOException {
- return BundleUtil.getBundleState(getBundle(bundleId));
+ return BundleUtil.getBundleState(retrieveBundle(bundleId));
}
/**
* {@inheritDoc}
*/
public String getSymbolicName(long bundleId) throws IOException {
- return getBundle(bundleId).getSymbolicName();
+ return retrieveBundle(bundleId).getSymbolicName();
}
/**
* {@inheritDoc}
*/
public String getLocation(long bundleId) throws IOException {
- return getBundle(bundleId).getLocation();
+ return retrieveBundle(bundleId).getLocation();
}
/**
* {@inheritDoc}
*/
public long[] getRequiredBundles(long bundleIdentifier) throws IOException {
- return BundleUtil.getRequiredBundles(getBundle(bundleIdentifier));
+ return BundleUtil.getRequiredBundles(retrieveBundle(bundleIdentifier));
}
/**
* {@inheritDoc}
*/
public String getVersion(long bundleId) throws IOException {
- return getBundle(bundleId).getVersion().toString();
+ return retrieveBundle(bundleId).getVersion().toString();
}
/**
* {@inheritDoc}
*/
public boolean isPersistentlyStarted(long bundleId) throws IOException {
- return BundleUtil.isBundlePersistentlyStarted(getBundle(bundleId));
+ return BundleUtil.isBundlePersistentlyStarted(retrieveBundle(bundleId));
}
/**
* {@inheritDoc}
*/
public boolean isFragment(long bundleId) throws IOException {
- return BundleUtil.isBundleFragment(getBundle(bundleId));
+ return BundleUtil.isBundleFragment(retrieveBundle(bundleId));
}
/**
* {@inheritDoc}
*/
public boolean isRemovalPending(long bundleId) throws IOException {
- return BundleUtil.isRemovalPending(getBundle(bundleId));
+ return BundleUtil.isRemovalPending(retrieveBundle(bundleId));
}
/**
* {@inheritDoc}
*/
public boolean isRequired(long bundleId) throws IOException {
- return BundleUtil.isRequired(getBundle(bundleId));
+ return BundleUtil.isRequired(retrieveBundle(bundleId));
}
- private Bundle getBundle(long bundleId) throws IOException {
+ //New methods from the JMX Update RFC 169
+
+ /**
+ * {@inheritDoc}
+ */
+ public CompositeData getBundle(long bundleId) throws IOException {
+ return new OSGiBundle(retrieveBundle(bundleId)).asCompositeData();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public TabularData listBundles(String... bundleTypeItems) throws IOException {
+ try {
+ ArrayList<OSGiBundle> bundles = new ArrayList<OSGiBundle>();
+ for (Bundle bundle : bundleContext.getBundles()) {
+ bundles.add(new OSGiBundle(bundle));
+ }
+ TabularData table = OSGiBundle.tableFrom(bundles, bundleTypeItems);
+ return table;
+ } catch (Throwable e) {
+ throw new IOException(e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isActivationPolicyUsed(long bundleId) throws IOException {
+ return BundleUtil.isBundleActivationPolicyUsed(retrieveBundle(bundleId));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getHeader(long bundleId, String key) throws IOException {
+ return retrieveBundle(bundleId).getHeaders().get(key);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public TabularData getHeaders(long bundleId, String locale) throws IOException {
+ return OSGiBundle.headerTable(retrieveBundle(bundleId).getHeaders(locale));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public CompositeData getHeaders(long bundleId, String key, String locale) throws IOException {
+ String value = retrieveBundle(bundleId).getHeaders(locale).get(key);
+ if(value == null){
+ return null;
+ }
+ return OSGiBundle.getHeaderCompositeData(key, value);
+ }
+
+ //End methods for the MBean
+
+ private Bundle retrieveBundle(long bundleId) throws IOException {
Bundle b = bundleContext.getBundle(bundleId);
if (b == null) {
throw new IOException("Bundle with id: " + bundleId + " does not exist");
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/CustomBundleStateMBean.java b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/CustomBundleStateMBean.java
index 25e9aef..393225d 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/CustomBundleStateMBean.java
+++ b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/CustomBundleStateMBean.java
@@ -16,8 +16,11 @@
import java.io.IOException;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.SimpleType;
import javax.management.openmbean.TabularData;
+import org.osgi.jmx.Item;
import org.osgi.jmx.framework.BundleStateMBean;
public interface CustomBundleStateMBean extends BundleStateMBean{
@@ -144,6 +147,12 @@
public final static int REQUIRED_BUNDLES = 2 << 18;
/**
+ * Mask for listBundles method, that requires bundle "activation policy used" attribute to be
+ * included in the returned data.
+ */
+ public final static int ACTIVATION_POLICY = 2 << 19;
+
+ /**
* Mask for listBundles method, that returns all available data. Equivalent to listBundles()
*/
public final static int DEFAULT = LOCATION + IDENTIFIER
@@ -163,4 +172,68 @@
* @throws IOException
*/
TabularData listBundles(int mask) throws IOException;
+
+ /**
+ * The key PERSISTENTLY_STARTED, used in {@link #PERSISTENTLY_STARTED_ITEM}.
+ */
+ String ACTIVATION_POLICY_USED = "ActivationPolicyUsed";
+
+ /**
+ * The item containing the indication of persistently started in
+ * {@link #BUNDLE_TYPE}. The key is {@link #PERSISTENTLY_STARTED} and the
+ * the type is {@link SimpleType#BOOLEAN}.
+ */
+ Item ACTIVATION_POLICY_ITEM = new Item(ACTIVATION_POLICY_USED, "Whether the bundle is using an activation policy", SimpleType.BOOLEAN);
+
+ //New methods from the JMX Update RFC 169
+
+ /**
+ *
+ * @param bundleId
+ * @return
+ * @throws IOException
+ */
+ CompositeData getBundle(long bundleId) throws IOException;
+
+ /**
+ *
+ * @param bundleTypeItems
+ * @return
+ * @throws IOException
+ */
+ TabularData listBundles(String... bundleTypeItems) throws IOException;
+
+ /**
+ *
+ * @return
+ */
+ boolean isActivationPolicyUsed(long bundleId) throws IOException;
+
+ /**
+ *
+ * @param bundleId
+ * @param key
+ * @return
+ * @throws IOException
+ */
+ String getHeader(long bundleId, String key) throws IOException;
+
+ /**
+ *
+ * @param bundleId
+ * @param locale
+ * @return
+ * @throws IOException
+ */
+ TabularData getHeaders(long bundleId, String locale) throws IOException;
+
+ /**
+ *
+ * @param bundleId
+ * @param key
+ * @param locale
+ * @return
+ * @throws IOException
+ */
+ CompositeData getHeaders(long bundleId, String key, String locale) throws IOException;
}
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/CustomServiceStateMBean.java b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/CustomServiceStateMBean.java
index 936c5be..1f88db1 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/CustomServiceStateMBean.java
+++ b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/CustomServiceStateMBean.java
@@ -26,6 +26,7 @@
*/
public interface CustomServiceStateMBean extends ServiceStateMBean {
+ //New methods from the JMX Update RFC 169
/**
*
@@ -36,6 +37,7 @@
public CompositeData getService(long serviceId) throws IOException;
/**
+ * Get a single property by it's key and
*
* @param serviceId
* @param key
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/ServiceState.java b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/ServiceState.java
index 8cdd536..c2e144f 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/ServiceState.java
+++ b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/ServiceState.java
@@ -104,6 +104,8 @@
return ServiceUtil.getBundlesUsing(getServiceReference(serviceId));
}
+ //New methods from the JMX Update RFC 169
+
/**
* {@inheritDoc}
*/
@@ -207,7 +209,6 @@
//End methods for the MBean
-
/**
* {@inheritDoc}
*/
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundle.java b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundle.java
index 26ab6dc..070eb89 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundle.java
+++ b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiBundle.java
@@ -17,6 +17,7 @@
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
@@ -48,8 +49,6 @@
*/
public final class OSGiBundle {
- private static final String[] HEADER_PROPERTY_ITEM_NAMES = new String[] {BundleStateMBean.KEY, BundleStateMBean.VALUE };
-
private Bundle bundle;
/**
@@ -61,6 +60,153 @@
this.bundle = b;
}
+ public static TabularData tableFrom(List<OSGiBundle> bundles, String... bundleTypeItems) throws IOException {
+ List<String> bundleTypes = Arrays.asList(bundleTypeItems);
+ CompositeType computeBundleType = OSGiBundle.computeBundleType(bundleTypes);
+ TabularDataSupport table = new TabularDataSupport(Item.tabularType("BUNDLES", "A list of bundles", computeBundleType, new String[] { BundleStateMBean.IDENTIFIER }));
+ for (OSGiBundle bundle : bundles) {
+ table.put(bundle.asCompositeData(computeBundleType, bundleTypes));
+ }
+ return table;
+ }
+
+ private static CompositeType computeBundleType(List<String> bundleTypes) {
+ List<Item> bundleTypeItems = new ArrayList<Item>();
+ bundleTypeItems.add(BundleStateMBean.IDENTIFIER_ITEM);
+ if(bundleTypes.contains(BundleStateMBean.LOCATION)) {
+ bundleTypeItems.add(BundleStateMBean.LOCATION_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.SYMBOLIC_NAME)) {
+ bundleTypeItems.add(BundleStateMBean.SYMBOLIC_NAME_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.VERSION)) {
+ bundleTypeItems.add(BundleStateMBean.VERSION_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.START_LEVEL)) {
+ bundleTypeItems.add(BundleStateMBean.START_LEVEL_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.STATE)) {
+ bundleTypeItems.add(BundleStateMBean.STATE_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.LAST_MODIFIED)) {
+ bundleTypeItems.add(BundleStateMBean.LAST_MODIFIED_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.PERSISTENTLY_STARTED)) {
+ bundleTypeItems.add(BundleStateMBean.PERSISTENTLY_STARTED_ITEM);
+ }
+ if(bundleTypes.contains(CustomBundleStateMBean.ACTIVATION_POLICY)) {
+ bundleTypeItems.add(CustomBundleStateMBean.ACTIVATION_POLICY_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.REMOVAL_PENDING)) {
+ bundleTypeItems.add(BundleStateMBean.REMOVAL_PENDING_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.REQUIRED)) {
+ bundleTypeItems.add(BundleStateMBean.REQUIRED_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.FRAGMENT)) {
+ bundleTypeItems.add(BundleStateMBean.FRAGMENT_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.REGISTERED_SERVICES)) {
+ bundleTypeItems.add(BundleStateMBean.REGISTERED_SERVICES_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.SERVICES_IN_USE)) {
+ bundleTypeItems.add(BundleStateMBean.SERVICES_IN_USE_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.HEADERS)) {
+ bundleTypeItems.add(BundleStateMBean.HEADERS_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.EXPORTED_PACKAGES)) {
+ bundleTypeItems.add(BundleStateMBean.EXPORTED_PACKAGES_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.IMPORTED_PACKAGES)) {
+ bundleTypeItems.add(BundleStateMBean.IMPORTED_PACKAGES_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.FRAGMENTS)) {
+ bundleTypeItems.add(BundleStateMBean.FRAGMENTS_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.HOSTS)) {
+ bundleTypeItems.add(BundleStateMBean.HOSTS_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.REQUIRING_BUNDLES)) {
+ bundleTypeItems.add(BundleStateMBean.REQUIRING_BUNDLES_ITEM);
+ }
+ if(bundleTypes.contains(BundleStateMBean.REQUIRED_BUNDLES)) {
+ bundleTypeItems.add(BundleStateMBean.REQUIRED_BUNDLES_ITEM);
+ }
+ CompositeType currentCompositeType = Item.compositeType("BUNDLE", "This type encapsulates OSGi bundles", bundleTypeItems.toArray(new Item[]{}));
+ return currentCompositeType;
+ }
+
+ private CompositeData asCompositeData(CompositeType computeBundleType, List<String> bundleTypes) throws IOException {
+ Map<String, Object> items = new HashMap<String, Object>();
+ items.put(BundleStateMBean.IDENTIFIER, getIdentifier());
+ if(bundleTypes.contains(BundleStateMBean.LOCATION)) {
+ items.put(BundleStateMBean.LOCATION, getLocation());
+ }
+ if(bundleTypes.contains(BundleStateMBean.SYMBOLIC_NAME)) {
+ items.put(BundleStateMBean.SYMBOLIC_NAME, getSymbolicName());
+ }
+ if(bundleTypes.contains(BundleStateMBean.VERSION)) {
+ items.put(BundleStateMBean.VERSION, getVersion());
+ }
+ if(bundleTypes.contains(BundleStateMBean.START_LEVEL)) {
+ items.put(BundleStateMBean.START_LEVEL, getStartLevel());
+ }
+ if(bundleTypes.contains(BundleStateMBean.STATE)) {
+ items.put(BundleStateMBean.STATE, getState());
+ }
+ if(bundleTypes.contains(BundleStateMBean.LAST_MODIFIED)) {
+ items.put(BundleStateMBean.LAST_MODIFIED, getLastModified());
+ }
+ if(bundleTypes.contains(BundleStateMBean.PERSISTENTLY_STARTED)) {
+ items.put(BundleStateMBean.PERSISTENTLY_STARTED, isPersistentlyStarted());
+ }
+ if(bundleTypes.contains(CustomBundleStateMBean.ACTIVATION_POLICY)) {
+ items.put(CustomBundleStateMBean.ACTIVATION_POLICY_USED, isActivationPolicyUsed());
+ }
+ if(bundleTypes.contains(BundleStateMBean.REMOVAL_PENDING)) {
+ items.put(BundleStateMBean.REMOVAL_PENDING, isRemovalPending());
+ }
+ if(bundleTypes.contains(BundleStateMBean.REQUIRED)) {
+ items.put(BundleStateMBean.REQUIRED, isRequired());
+ }
+ if(bundleTypes.contains(BundleStateMBean.FRAGMENT)) {
+ items.put(BundleStateMBean.FRAGMENT, isFragment());
+ }
+ if(bundleTypes.contains(BundleStateMBean.REGISTERED_SERVICES)) {
+ items.put(BundleStateMBean.REGISTERED_SERVICES, BundleUtil.LongArrayFrom(getRegisteredServices()));
+ }
+ if(bundleTypes.contains(BundleStateMBean.SERVICES_IN_USE)) {
+ items.put(BundleStateMBean.SERVICES_IN_USE, BundleUtil.LongArrayFrom(getServicesInUse()));
+ }
+ if(bundleTypes.contains(BundleStateMBean.HEADERS)) {
+ items.put(BundleStateMBean.HEADERS, headerTable(getHeaders()));
+ }
+ if(bundleTypes.contains(BundleStateMBean.EXPORTED_PACKAGES)) {
+ items.put(BundleStateMBean.EXPORTED_PACKAGES, getExportedPackages());
+ }
+ if(bundleTypes.contains(BundleStateMBean.IMPORTED_PACKAGES)) {
+ items.put(BundleStateMBean.IMPORTED_PACKAGES, getImportedPackages());
+ }
+ if(bundleTypes.contains(BundleStateMBean.FRAGMENTS)) {
+ items.put(BundleStateMBean.FRAGMENTS, BundleUtil.LongArrayFrom(getFragments()));
+ }
+ if(bundleTypes.contains(BundleStateMBean.HOSTS)) {
+ items.put(BundleStateMBean.HOSTS, BundleUtil.LongArrayFrom(getHosts()));
+ }
+ if(bundleTypes.contains(BundleStateMBean.REQUIRING_BUNDLES)) {
+ items.put(BundleStateMBean.REQUIRING_BUNDLES, BundleUtil.LongArrayFrom(getRequiringBundles()));
+ }
+ if(bundleTypes.contains(BundleStateMBean.REQUIRED_BUNDLES)) {
+ items.put(BundleStateMBean.REQUIRED_BUNDLES, BundleUtil.LongArrayFrom(getRequiredBundles()));
+ }
+ try {
+ return new CompositeDataSupport(computeBundleType, items);
+ } catch (OpenDataException e) {
+ throw new IllegalStateException("Cannot form bundle open data", e);
+ }
+ }
+
/**
* Answer the TabularData representing the list of OSGiBundle state
*
@@ -80,147 +226,71 @@
}
private static CompositeType computeBundleType(int mask) {
- List<Item> bundleTypes = new ArrayList<Item>();
- bundleTypes.add(BundleStateMBean.IDENTIFIER_ITEM);
+ List<Item> bundleTypeItems = new ArrayList<Item>();
+ bundleTypeItems.add(BundleStateMBean.IDENTIFIER_ITEM);
if((mask | CustomBundleStateMBean.LOCATION) == mask) {
- bundleTypes.add(BundleStateMBean.LOCATION_ITEM);
+ bundleTypeItems.add(BundleStateMBean.LOCATION_ITEM);
}
if((mask | CustomBundleStateMBean.SYMBOLIC_NAME) == mask) {
- bundleTypes.add(BundleStateMBean.SYMBOLIC_NAME_ITEM);
+ bundleTypeItems.add(BundleStateMBean.SYMBOLIC_NAME_ITEM);
}
if((mask | CustomBundleStateMBean.VERSION) == mask) {
- bundleTypes.add(BundleStateMBean.VERSION_ITEM);
+ bundleTypeItems.add(BundleStateMBean.VERSION_ITEM);
}
if((mask | CustomBundleStateMBean.START_LEVEL) == mask) {
- bundleTypes.add(BundleStateMBean.START_LEVEL_ITEM);
+ bundleTypeItems.add(BundleStateMBean.START_LEVEL_ITEM);
}
if((mask | CustomBundleStateMBean.STATE) == mask) {
- bundleTypes.add(BundleStateMBean.STATE_ITEM);
+ bundleTypeItems.add(BundleStateMBean.STATE_ITEM);
}
if((mask | CustomBundleStateMBean.LAST_MODIFIED) == mask) {
- bundleTypes.add(BundleStateMBean.LAST_MODIFIED_ITEM);
+ bundleTypeItems.add(BundleStateMBean.LAST_MODIFIED_ITEM);
}
if((mask | CustomBundleStateMBean.PERSISTENTLY_STARTED) == mask) {
- bundleTypes.add(BundleStateMBean.PERSISTENTLY_STARTED_ITEM);
+ bundleTypeItems.add(BundleStateMBean.PERSISTENTLY_STARTED_ITEM);
+ }
+ if((mask | CustomBundleStateMBean.ACTIVATION_POLICY) == mask) {
+ bundleTypeItems.add(CustomBundleStateMBean.ACTIVATION_POLICY_ITEM);
}
if((mask | CustomBundleStateMBean.REMOVAL_PENDING) == mask) {
- bundleTypes.add(BundleStateMBean.REMOVAL_PENDING_ITEM);
+ bundleTypeItems.add(BundleStateMBean.REMOVAL_PENDING_ITEM);
}
if((mask | CustomBundleStateMBean.REQUIRED) == mask) {
- bundleTypes.add(BundleStateMBean.REQUIRED_ITEM);
+ bundleTypeItems.add(BundleStateMBean.REQUIRED_ITEM);
}
if((mask | CustomBundleStateMBean.FRAGMENT) == mask) {
- bundleTypes.add(BundleStateMBean.FRAGMENT_ITEM);
+ bundleTypeItems.add(BundleStateMBean.FRAGMENT_ITEM);
}
if((mask | CustomBundleStateMBean.REGISTERED_SERVICES) == mask) {
- bundleTypes.add(BundleStateMBean.REGISTERED_SERVICES_ITEM);
+ bundleTypeItems.add(BundleStateMBean.REGISTERED_SERVICES_ITEM);
}
if((mask | CustomBundleStateMBean.SERVICES_IN_USE) == mask) {
- bundleTypes.add(BundleStateMBean.SERVICES_IN_USE_ITEM);
+ bundleTypeItems.add(BundleStateMBean.SERVICES_IN_USE_ITEM);
}
if((mask | CustomBundleStateMBean.HEADERS) == mask) {
- bundleTypes.add(BundleStateMBean.HEADERS_ITEM);
+ bundleTypeItems.add(BundleStateMBean.HEADERS_ITEM);
}
if((mask | CustomBundleStateMBean.EXPORTED_PACKAGES) == mask) {
- bundleTypes.add(BundleStateMBean.EXPORTED_PACKAGES_ITEM);
+ bundleTypeItems.add(BundleStateMBean.EXPORTED_PACKAGES_ITEM);
}
if((mask | CustomBundleStateMBean.IMPORTED_PACKAGES) == mask) {
- bundleTypes.add(BundleStateMBean.IMPORTED_PACKAGES_ITEM);
+ bundleTypeItems.add(BundleStateMBean.IMPORTED_PACKAGES_ITEM);
}
if((mask | CustomBundleStateMBean.FRAGMENTS) == mask) {
- bundleTypes.add(BundleStateMBean.FRAGMENTS_ITEM);
+ bundleTypeItems.add(BundleStateMBean.FRAGMENTS_ITEM);
}
if((mask | CustomBundleStateMBean.HOSTS) == mask) {
- bundleTypes.add(BundleStateMBean.HOSTS_ITEM);
+ bundleTypeItems.add(BundleStateMBean.HOSTS_ITEM);
}
if((mask | CustomBundleStateMBean.REQUIRING_BUNDLES) == mask) {
- bundleTypes.add(BundleStateMBean.REQUIRING_BUNDLES_ITEM);
+ bundleTypeItems.add(BundleStateMBean.REQUIRING_BUNDLES_ITEM);
}
if((mask | CustomBundleStateMBean.REQUIRED_BUNDLES) == mask) {
- bundleTypes.add(BundleStateMBean.REQUIRED_BUNDLES_ITEM);
+ bundleTypeItems.add(BundleStateMBean.REQUIRED_BUNDLES_ITEM);
}
- CompositeType currentCompositeType = Item.compositeType("BUNDLE", "This type encapsulates OSGi bundles", bundleTypes.toArray(new Item[]{}));
+ CompositeType currentCompositeType = Item.compositeType("BUNDLE", "This type encapsulates OSGi bundles", bundleTypeItems.toArray(new Item[]{}));
return currentCompositeType;
}
-
- /**
- * Answer the TabularData representing the list of bundle headers for a
- * bundle
- *
- * @param b
- * @return the bundle headers
- */
- public static TabularData headerTable(Bundle b) {
- TabularDataSupport table = new TabularDataSupport(BundleStateMBean.HEADERS_TYPE);
- Dictionary<String, String> map = b.getHeaders();
- for (Enumeration<String> headers = map.keys(); headers.hasMoreElements();) {
- String key = (String) headers.nextElement();
- table.put(headerData(key, (String) map.get(key)));
- }
- return table;
- }
-
- /**
- * Answer the TabularData representing the supplied map of bundle headers
- *
- * @param headers
- * @return the bundle headers
- */
- public static TabularData headerTable(Map<String, String> headers) {
- TabularDataSupport table = new TabularDataSupport(BundleStateMBean.HEADERS_TYPE);
- for (Map.Entry<String, String> entry : headers.entrySet()) {
- table.put(headerData(entry.getKey(), entry.getValue()));
- }
- return table;
- }
-
- private static CompositeData headerData(String key, String value) {
- Object[] itemValues = new Object[HEADER_PROPERTY_ITEM_NAMES.length];
- itemValues[0] = key;
- itemValues[1] = value;
-
- try {
- return new CompositeDataSupport(BundleStateMBean.HEADER_TYPE, HEADER_PROPERTY_ITEM_NAMES, itemValues);
- } catch (OpenDataException e) {
- throw new IllegalStateException("Cannot form bundle header open data", e);
- }
- }
-
- /**
- * Answer the receiver encoded as CompositeData
- * @param mask
- *
- * @return the CompositeData encoding of the receiver.
- * @throws IOException
- */
- public CompositeData asCompositeData() throws IOException {
- Map<String, Object> items = new HashMap<String, Object>();
- items.put(BundleStateMBean.IDENTIFIER, getIdentifier());
- items.put(BundleStateMBean.LOCATION, getLocation());
- items.put(BundleStateMBean.SYMBOLIC_NAME, getSymbolicName());
- items.put(BundleStateMBean.VERSION, getVersion());
- items.put(BundleStateMBean.START_LEVEL, getStartLevel());
- items.put(BundleStateMBean.STATE, getState());
- items.put(BundleStateMBean.LAST_MODIFIED, getLastModified());
- items.put(BundleStateMBean.PERSISTENTLY_STARTED, isPersistentlyStarted());
- items.put(BundleStateMBean.REMOVAL_PENDING, isRemovalPending());
- items.put(BundleStateMBean.REQUIRED, isRequired());
- items.put(BundleStateMBean.FRAGMENT, isFragment());
- items.put(BundleStateMBean.REGISTERED_SERVICES, BundleUtil.LongArrayFrom(getRegisteredServices()));
- items.put(BundleStateMBean.SERVICES_IN_USE, BundleUtil.LongArrayFrom(getServicesInUse()));
- items.put(BundleStateMBean.HEADERS, headerTable(getHeaders()));
- items.put(BundleStateMBean.EXPORTED_PACKAGES, getExportedPackages());
- items.put(BundleStateMBean.IMPORTED_PACKAGES, getImportedPackages());
- items.put(BundleStateMBean.FRAGMENTS, BundleUtil.LongArrayFrom(getFragments()));
- items.put(BundleStateMBean.HOSTS, BundleUtil.LongArrayFrom(getHosts()));
- items.put(BundleStateMBean.REQUIRING_BUNDLES, BundleUtil.LongArrayFrom(getRequiringBundles()));
- items.put(BundleStateMBean.REQUIRED_BUNDLES, BundleUtil.LongArrayFrom(getRequiredBundles()));
- try {
- return new CompositeDataSupport(BundleStateMBean.BUNDLE_TYPE, items);
- } catch (OpenDataException e) {
- throw new IllegalStateException("Cannot form bundle open data", e);
- }
- }
/**
* Answer the receiver encoded as CompositeData
@@ -253,6 +323,9 @@
if((mask | CustomBundleStateMBean.PERSISTENTLY_STARTED) == mask) {
items.put(BundleStateMBean.PERSISTENTLY_STARTED, isPersistentlyStarted());
}
+ if((mask | CustomBundleStateMBean.ACTIVATION_POLICY) == mask) {
+ items.put(CustomBundleStateMBean.ACTIVATION_POLICY_USED, isActivationPolicyUsed());
+ }
if((mask | CustomBundleStateMBean.REMOVAL_PENDING) == mask) {
items.put(BundleStateMBean.REMOVAL_PENDING, isRemovalPending());
}
@@ -298,6 +371,69 @@
}
/**
+ * Answer the receiver encoded as CompositeData
+ * @param mask
+ *
+ * @return the CompositeData encoding of the receiver.
+ * @throws IOException
+ */
+ public CompositeData asCompositeData() throws IOException {
+ Map<String, Object> items = new HashMap<String, Object>();
+ items.put(BundleStateMBean.IDENTIFIER, getIdentifier());
+ items.put(BundleStateMBean.LOCATION, getLocation());
+ items.put(BundleStateMBean.SYMBOLIC_NAME, getSymbolicName());
+ items.put(BundleStateMBean.VERSION, getVersion());
+ items.put(BundleStateMBean.START_LEVEL, getStartLevel());
+ items.put(BundleStateMBean.STATE, getState());
+ items.put(BundleStateMBean.LAST_MODIFIED, getLastModified());
+ items.put(BundleStateMBean.PERSISTENTLY_STARTED, isPersistentlyStarted());
+ items.put(CustomBundleStateMBean.ACTIVATION_POLICY_USED, isActivationPolicyUsed());
+ items.put(BundleStateMBean.REMOVAL_PENDING, isRemovalPending());
+ items.put(BundleStateMBean.REQUIRED, isRequired());
+ items.put(BundleStateMBean.FRAGMENT, isFragment());
+ items.put(BundleStateMBean.REGISTERED_SERVICES, BundleUtil.LongArrayFrom(getRegisteredServices()));
+ items.put(BundleStateMBean.SERVICES_IN_USE, BundleUtil.LongArrayFrom(getServicesInUse()));
+ items.put(BundleStateMBean.HEADERS, headerTable(getHeaders()));
+ items.put(BundleStateMBean.EXPORTED_PACKAGES, getExportedPackages());
+ items.put(BundleStateMBean.IMPORTED_PACKAGES, getImportedPackages());
+ items.put(BundleStateMBean.FRAGMENTS, BundleUtil.LongArrayFrom(getFragments()));
+ items.put(BundleStateMBean.HOSTS, BundleUtil.LongArrayFrom(getHosts()));
+ items.put(BundleStateMBean.REQUIRING_BUNDLES, BundleUtil.LongArrayFrom(getRequiringBundles()));
+ items.put(BundleStateMBean.REQUIRED_BUNDLES, BundleUtil.LongArrayFrom(getRequiredBundles()));
+ try {
+ return new CompositeDataSupport(BundleStateMBean.BUNDLE_TYPE, items);
+ } catch (OpenDataException e) {
+ throw new IllegalStateException("Cannot form bundle open data", e);
+ }
+ }
+
+ /**
+ * Answer the TabularData representing the supplied map of bundle headers
+ *
+ * @param headers
+ * @return the bundle headers
+ */
+ public static TabularData headerTable(Dictionary<String, String> headersDictionary) {
+ TabularDataSupport table = new TabularDataSupport(BundleStateMBean.HEADERS_TYPE);
+ for(Enumeration<String> headers = headersDictionary.keys(); headers.hasMoreElements();) {
+ String key = (String) headers.nextElement();
+ table.put(getHeaderCompositeData(key, (String) headersDictionary.get(key)));
+ }
+ return table;
+ }
+
+ public static CompositeData getHeaderCompositeData(String key, String value) {
+ Map<String, Object> items = new HashMap<String, Object>();
+ items.put(BundleStateMBean.KEY, key);
+ items.put(BundleStateMBean.VALUE, value);
+ try {
+ return new CompositeDataSupport(BundleStateMBean.HEADER_TYPE, items);
+ } catch (OpenDataException e) {
+ throw new IllegalStateException("Cannot form bundle header open data", e);
+ }
+ }
+
+ /**
* @return The list of exported packages by this bundle, in the form of
* <packageName>;<version>
*
@@ -317,8 +453,8 @@
/**
* @return the map of headers for this bundle
*/
- private Map<String, String> getHeaders() {
- return BundleUtil.getBundleHeaders(bundle);
+ private Dictionary<String, String> getHeaders() {
+ return bundle.getHeaders();
}
/**
@@ -430,6 +566,13 @@
}
/**
+ * @return true if this bundle is persistently started
+ */
+ private boolean isActivationPolicyUsed() {
+ return BundleUtil.isBundleActivationPolicyUsed(bundle);
+ }
+
+ /**
* @return true if this bundle is pending removal
*/
private boolean isRemovalPending() {
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiService.java b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiService.java
index 7afcb02..67ab7ce 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiService.java
+++ b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/framework/internal/OSGiService.java
@@ -186,33 +186,4 @@
throw new IllegalStateException("Cannot form service open data", e);
}
}
-
-// /**
-// * @return the identifier of the bundle the service belongs to
-// */
-// public long getBundle() {
-// return bundle;
-// }
-//
-// /**
-// * @return the identifier of the service
-// */
-// public long getIdentifier() {
-// return identifier;
-// }
-//
-// /**
-// * @return the interfaces implemented by the service
-// */
-// public String[] getInterfaces() {
-// return interfaces;
-// }
-//
-// /**
-// * @return the identifiers of the bundles which are using the service
-// */
-// public long[] getUsingBundles() {
-// return usingBundles;
-// }
-
}
diff --git a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/internal/BundleUtil.java b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/internal/BundleUtil.java
index 08fa39e..024990e 100644
--- a/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/internal/BundleUtil.java
+++ b/org.eclipse.gemini.mgmt/src/org/eclipse/gemini/mgmt/internal/BundleUtil.java
@@ -19,11 +19,7 @@
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.Hashtable;
import java.util.List;
-import java.util.Map;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
@@ -130,22 +126,6 @@
}
return providerWires;
}
-
- /**
- * Answer the map of bundle headers
- *
- * @param b
- * @return the map of bundle headers
- */
- public static Map<String, String> getBundleHeaders(Bundle b) {
- Map<String, String> headers = new Hashtable<String, String>();
- Dictionary<?, ?> h = b.getHeaders();
- for (Enumeration<?> keys = h.keys(); keys.hasMoreElements();) {
- String key = (String) keys.nextElement();
- headers.put(key, (String) h.get(key));
- }
- return headers;
- }
/**
* Answer the string representation of the packages imported by a bundle
@@ -221,6 +201,18 @@
BundleStartLevel startLevel = bundle.adapt(BundleStartLevel.class);
return startLevel.isPersistentlyStarted();
}
+
+ /**
+ * Answer true if the bundle has been persitently started
+ *
+ * @param bundle
+ * @param sl
+ * @return true if the bundle has been persitently started
+ */
+ public static boolean isBundleActivationPolicyUsed(Bundle bundle) {
+ BundleStartLevel startLevel = bundle.adapt(BundleStartLevel.class);
+ return startLevel.isActivationPolicyUsed();
+ }
/**
* Answer true if the bundle is required