aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1221667 - in /aries/trunk/sandbox/jmx-next: jmx-api/src/main/java/org/osgi/jmx/framework/ jmx-core/src/main/java/org/apache/aries/jmx/framework/ jmx-core/src/test/java/org/apache/aries/jmx/codec/
Date Wed, 21 Dec 2011 10:38:37 GMT
Author: davidb
Date: Wed Dec 21 10:38:37 2011
New Revision: 1221667

URL: http://svn.apache.org/viewvc?rev=1221667&view=rev
Log:
Add isActivationPolicyUsed()

Modified:
    aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/BundleStateMBean.java
    aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java
    aries/trunk/sandbox/jmx-next/jmx-core/src/test/java/org/apache/aries/jmx/codec/BundleDataTest.java

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=1221667&r1=1221666&r2=1221667&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
Wed Dec 21 10:38:37 2011
@@ -198,10 +198,24 @@ public interface BundleStateMBean {
 	 */
 	Item LAST_MODIFIED_ITEM = new Item(LAST_MODIFIED,
 			"The last modification time of the bundle", SimpleType.LONG);
+
+	/**
+	 * The key ACTIVATION_POLICY_USED, used in {@link #ACTIVATION_POLICY_USED_ITEM}.
+	 */
+	String ACTIVATION_POLICY_USED = "ActivationPolicyUsed";
+
+	/**
+	 * The item containing the indication whether the bundle activation policy
+	 * must be used in {@link #BUNDLE_TYPE}. The key is {@link #ACTIVATION_POLICY_USED} and
+	 * the type is {@link SimpleType#BOOLEAN}.
+	 */
+	Item ACTIVATION_POLICY_USED_ITEM = new Item(ACTIVATION_POLICY_USED,
+	        "Whether the bundle activation policy must be used", SimpleType.BOOLEAN);
+
 	/**
 	 * The key PERSISTENTLY_STARTED, used in {@link #PERSISTENTLY_STARTED_ITEM}.
 	 */
-	String			PERSISTENTLY_STARTED		= "PersistentlyStarted";
+	String PERSISTENTLY_STARTED = "PersistentlyStarted";
 
 	/**
 	 * The item containing the indication of persistently started in
@@ -396,6 +410,7 @@ public interface BundleStateMBean {
 	 * <li>{@link #IMPORTED_PACKAGES}</li>
 	 * <li>{@link #LAST_MODIFIED}</li>
 	 * <li>{@link #LOCATION}</li>
+	 * <li>{@link #ACTIVATION_POLICY_USED}</li>
 	 * <li>{@link #PERSISTENTLY_STARTED}</li>
 	 * <li>{@link #REGISTERED_SERVICES}</li>
 	 * <li>{@link #REMOVAL_PENDING}</li>
@@ -414,7 +429,8 @@ public interface BundleStateMBean {
 			"This type encapsulates OSGi bundles", EXPORTED_PACKAGES_ITEM,
 			FRAGMENT_ITEM, FRAGMENTS_ITEM, HEADERS_ITEM, HOSTS_ITEM,
 			IDENTIFIER_ITEM, IMPORTED_PACKAGES_ITEM, LAST_MODIFIED_ITEM,
-			LOCATION_ITEM, PERSISTENTLY_STARTED_ITEM, REGISTERED_SERVICES_ITEM,
+			LOCATION_ITEM, ACTIVATION_POLICY_USED_ITEM,
+			PERSISTENTLY_STARTED_ITEM, REGISTERED_SERVICES_ITEM,
 			REMOVAL_PENDING_ITEM, REQUIRED_ITEM, REQUIRED_BUNDLES_ITEM,
 			REQUIRING_BUNDLES_ITEM, START_LEVEL_ITEM, STATE_ITEM,
 			SERVICES_IN_USE_ITEM, SYMBOLIC_NAME_ITEM, VERSION_ITEM);
@@ -624,6 +640,21 @@ public interface BundleStateMBean {
 	String getSymbolicName(long bundleId) throws IOException;
 
 	/**
+	 * Answer whether the specified bundle's autostart setting indicates that
+	 * the activation policy declared in the bundle's manifest must be used.
+	 *
+	 * @param bundleId
+     *            the identifier of the bundle
+	 * @return true if the bundle's autostart setting indicates the activation policy
+	 * declared in the manifest must be used. false if the bundle must be eagerly activated.
+     * @throws IOException
+     *             if the operation fails
+     * @throws IllegalArgumentException
+     *             if the bundle indicated does not exist
+	 */
+	boolean isActivationPolicyUsed(long bundleId) throws IOException;
+
+	/**
 	 * Answer if the bundle is persistently started when its start level is
 	 * reached
 	 *

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=1221667&r1=1221666&r2=1221667&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
Wed Dec 21 10:38:37 2011
@@ -265,6 +265,14 @@ public class BundleState extends Notific
     }
 
     /**
+     * @see org.osgi.jmx.framework.BundleStateMBean#isActivationPolicyUsed(long)
+     */
+    public boolean isActivationPolicyUsed(long bundleId) throws IOException {
+        Bundle bundle = resolveBundle(bundleContext, bundleId);
+        return startLevel.isBundleActivationPolicyUsed(bundle);
+    }
+
+    /**
      * @see org.osgi.jmx.framework.BundleStateMBean#isPersistentlyStarted(long)
      */
     public boolean isPersistentlyStarted(long bundleId) throws IOException, IllegalArgumentException
{

Modified: aries/trunk/sandbox/jmx-next/jmx-core/src/test/java/org/apache/aries/jmx/codec/BundleDataTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/test/java/org/apache/aries/jmx/codec/BundleDataTest.java?rev=1221667&r1=1221666&r2=1221667&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/test/java/org/apache/aries/jmx/codec/BundleDataTest.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/test/java/org/apache/aries/jmx/codec/BundleDataTest.java
Wed Dec 21 10:38:37 2011
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertNotNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+import static org.osgi.jmx.framework.BundleStateMBean.ACTIVATION_POLICY_USED;
 import static org.osgi.jmx.framework.BundleStateMBean.BUNDLES_TYPE;
 import static org.osgi.jmx.framework.BundleStateMBean.BUNDLE_TYPE;
 import static org.osgi.jmx.framework.BundleStateMBean.EXPORTED_PACKAGES;
@@ -73,21 +74,21 @@ import org.osgi.service.packageadmin.Req
 import org.osgi.service.startlevel.StartLevel;
 
 /**
- * 
+ *
  *
  * @version $Rev$ $Date$
  */
 public class BundleDataTest {
 
-    
+
     @Test
     public void testToCompositeData() throws Exception {
-        
+
         Bundle bundle = mock(Bundle.class);
         BundleContext context = mock(BundleContext.class);
         PackageAdmin packageAdmin = mock(PackageAdmin.class);
         StartLevel startLevel = mock(StartLevel.class);
-        
+
         Bundle b1 = mock(Bundle.class);
         when(b1.getSymbolicName()).thenReturn("b1");
         when(b1.getBundleId()).thenReturn(new Long(44));
@@ -98,26 +99,26 @@ public class BundleDataTest {
         when(b3.getSymbolicName()).thenReturn("b3");
         when(b3.getBundleId()).thenReturn(new Long(66));
         when(context.getBundles()).thenReturn(new Bundle[] { bundle, b1, b2, b3 });
-      
+
         when(bundle.getSymbolicName()).thenReturn("test");
         when(bundle.getVersion()).thenReturn(Version.emptyVersion);
         when(bundle.getBundleId()).thenReturn(new Long(1));
         when(bundle.getLastModified()).thenReturn(new Long(12345));
         when(bundle.getLocation()).thenReturn("location");
-        
+
         //headers
         Dictionary<String, String> headers = new Hashtable<String, String>();
         headers.put(Constants.BUNDLE_SYMBOLICNAME, "test");
         headers.put(Constants.BUNDLE_VERSION, "0.0.0");
         when(bundle.getHeaders()).thenReturn(headers);
-        
+
         //exported packages
         ExportedPackage exported = mock(ExportedPackage.class);
         when(exported.getName()).thenReturn("org.apache.aries.jmx");
         when(exported.getVersion()).thenReturn(new Version("1.0.0"));
         when(exported.getExportingBundle()).thenReturn(bundle);
         when(packageAdmin.getExportedPackages(bundle)).thenReturn(new ExportedPackage[] {
exported });
-        
+
         //imported packages
         ExportedPackage ep1 = mock(ExportedPackage.class);
         when(ep1.getImportingBundles()).thenReturn(new Bundle[] { bundle, b2, b3 });
@@ -130,11 +131,11 @@ public class BundleDataTest {
         when(ep2.getVersion()).thenReturn(Version.parseVersion("2.0.1"));
         when(ep2.getExportingBundle()).thenReturn(b2);
         headers.put(Constants.DYNAMICIMPORT_PACKAGE, "*");
-  
+
         when(packageAdmin.getExportedPackages(b1)).thenReturn(new ExportedPackage[] { ep1
});
         when(packageAdmin.getExportedPackages(b2)).thenReturn(new ExportedPackage[] { ep2
});
         when(packageAdmin.getExportedPackages(b3)).thenReturn(null);
-        
+
         //required bundles
         RequiredBundle rb1 = mock(RequiredBundle.class);
         when(rb1.getBundle()).thenReturn(b1);
@@ -149,7 +150,7 @@ public class BundleDataTest {
         when(packageAdmin.getRequiredBundles("b1")).thenReturn(new RequiredBundle[] { rb1
});
         when(packageAdmin.getRequiredBundles("b2")).thenReturn(new RequiredBundle[] { rb2
});
         when(packageAdmin.getRequiredBundles("b3")).thenReturn(new RequiredBundle[] { rb3
});
-        
+
         //services in use
         ServiceReference s1 = mock(ServiceReference.class);
         when(s1.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(15));
@@ -157,12 +158,12 @@ public class BundleDataTest {
         when(s2.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(16));
         ServiceReference s3 = mock(ServiceReference.class);
         when(s3.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(17));
-        
+
         when(bundle.getServicesInUse()).thenReturn(new ServiceReference[] { s1, s2, s3 });
-        
+
         BundleData b = new BundleData(context, bundle, packageAdmin, startLevel);
         CompositeData compositeData = b.toCompositeData();
-        
+
         assertEquals("test", compositeData.get(SYMBOLIC_NAME));
         assertEquals("0.0.0", compositeData.get(VERSION));
         TabularData headerTable = (TabularData) compositeData.get(HEADERS);
@@ -173,16 +174,16 @@ public class BundleDataTest {
         assertEquals("test", value);
         String key = (String)header.get(KEY);
         assertEquals(Constants.BUNDLE_SYMBOLICNAME, key);
-        
-        
+
+
         TabularData bundleTable = new TabularDataSupport(BUNDLES_TYPE);
         bundleTable.put(b.toCompositeData());
-   
+
         CompositeData bundleData = bundleTable.get(new Object[]{Long.valueOf(1)});
         assertNotNull(bundleData);
         String location = (String) bundleData.get(LOCATION);
         assertEquals("location", location);
-        
+
         assertArrayEquals(new String[] { "org.apache.aries.jmx;1.0.0"} , (String[]) compositeData.get(EXPORTED_PACKAGES));
         assertArrayEquals(new String[] { "org.apache.aries.jmx.b1;0.0.0" , "org.apache.aries.jmx.b2;2.0.1"},
(String[]) compositeData.get(IMPORTED_PACKAGES));
         assertEquals(toSet(new long[] { 44, 55, 66 }), toSet((Long[]) compositeData.get(REQUIRED_BUNDLES)));
@@ -190,10 +191,10 @@ public class BundleDataTest {
         assertEquals("UNKNOWN", compositeData.get(STATE)); //default no return stub
         assertEquals(0,((Long[]) compositeData.get(HOSTS)).length);
         assertEquals(0, ((Long[]) compositeData.get(FRAGMENTS)).length);
-        
+
     }
 
-   
+
     @Test
     public void testFromCompositeData() throws Exception {
 
@@ -206,6 +207,7 @@ public class BundleDataTest {
         items.put(IMPORTED_PACKAGES, new String[] { "org.apache.aries.jmx.b1;0.0.0" , "org.apache.aries.jmx.b2;2.0.1"});
         items.put(LAST_MODIFIED, new Long(8797));
         items.put(LOCATION, "");
+        items.put(ACTIVATION_POLICY_USED, true);
         items.put(PERSISTENTLY_STARTED, false);
         items.put(REGISTERED_SERVICES, new Long[0]);
         items.put(REMOVAL_PENDING, false);
@@ -222,9 +224,9 @@ public class BundleDataTest {
         headerTable.put(new Header("b", "b").toCompositeData());
         items.put(HEADERS, headerTable);
         CompositeData compositeData = new CompositeDataSupport(BUNDLE_TYPE, items);
-        
+
         BundleData b = BundleData.from(compositeData);
-        
+
         assertEquals("test", b.getSymbolicName());
         assertEquals("0.0.0", b.getVersion());
         assertEquals(2, b.getHeaders().size());
@@ -239,25 +241,25 @@ public class BundleDataTest {
 
     @Test
     public void testHeaderToCompositeData() throws Exception{
-        
+
         Header h1 = new Header("a", "b");
         CompositeData compositeData = h1.toCompositeData();
-       
+
         assertEquals("a", compositeData.get(KEY));
         assertEquals("b", compositeData.get(VALUE));
-        
+
     }
-    
+
     @Test
     public void testHeaderFromCompositeData() throws Exception {
-        
+
         CompositeData compositeData = new CompositeDataSupport(HEADER_TYPE, new String[]
{ KEY, VALUE } , new String [] { "c", "d" });
         Header header = Header.from(compositeData);
         assertEquals("c", header.getKey());
         assertEquals("d", header.getValue());
-        
+
     }
-        
+
     private static Set<Long> toSet(long[] array) {
         Set<Long> set = new HashSet<Long>();
         for (long value : array) {
@@ -265,7 +267,7 @@ public class BundleDataTest {
         }
         return set;
     }
-    
+
     private static Set<Long> toSet(Long[] array) {
         Set<Long> set = new HashSet<Long>();
         for (Long value : array) {



Mime
View raw message