aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1236164 - in /aries/trunk/sandbox/jmx-next: jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java jmx-itests/src/test/java/org/apache/aries/jmx/framework/FrameworkMBeanTest.java
Date Thu, 26 Jan 2012 13:00:57 GMT
Author: davidb
Date: Thu Jan 26 13:00:57 2012
New Revision: 1236164

URL: http://svn.apache.org/viewvc?rev=1236164&view=rev
Log:
Fix FrameworkMBean.refreshBundleAndWait() semantics.

Modified:
    aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java
    aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/FrameworkMBeanTest.java

Modified: aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java?rev=1236164&r1=1236163&r2=1236164&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java
Thu Jan 26 13:00:57 2012
@@ -230,7 +230,8 @@ public class Framework implements Framew
      */
     public boolean refreshBundleAndWait(long bundleIdentifier) throws IOException {
         Bundle[] bundleArray = new Bundle[1];
-        return refreshBundlesAndWait(new long[] {bundleIdentifier}, bundleArray);
+        refreshBundlesAndWait(new long[] {bundleIdentifier}, bundleArray);
+        return isResolved(bundleArray[0].getState());
     }
 
     /**
@@ -258,11 +259,11 @@ public class Framework implements Framew
      */
     public CompositeData refreshBundlesAndWait(long[] bundleIdentifiers) throws IOException
{
         Bundle [] bundles = bundleIdentifiers != null ? new Bundle[bundleIdentifiers.length]
: null;
-        boolean result = refreshBundlesAndWait(bundleIdentifiers, bundles);
-        return constructResolveResult(bundles, result);
+        refreshBundlesAndWait(bundleIdentifiers, bundles);
+        return constructResolveResult(bundles);
     }
 
-    private boolean refreshBundlesAndWait(long[] bundleIdentifiers, Bundle[] bundles) throws
IOException {
+    private void refreshBundlesAndWait(long[] bundleIdentifiers, Bundle[] bundles) throws
IOException {
         final CountDownLatch latch = new CountDownLatch(1);
         FrameworkListener listener = new FrameworkListener() {
             public void frameworkEvent(FrameworkEvent event) {
@@ -280,7 +281,11 @@ public class Framework implements Framew
                     }
                 }
                 packageAdmin.refreshPackages(bundles);
-                return latch.await(30, TimeUnit.SECONDS);
+
+                if (latch.await(30, TimeUnit.SECONDS))
+                    return;
+                else
+                    throw new IOException("Refresh operation timed out");
             } catch (InterruptedException e) {
                 IOException ex = new IOException();
                 ex.initCause(e);
@@ -291,21 +296,27 @@ public class Framework implements Framew
         }
     }
 
-    private CompositeData constructResolveResult(Bundle[] bundles, boolean result) {
+    private CompositeData constructResolveResult(Bundle[] bundles) {
         if (bundles == null)
             bundles = context.getBundles();
 
+        boolean result = true;
         List<Long> successList = new ArrayList<Long>();
         for (Bundle bundle : bundles) {
             int state = bundle.getState();
-            if ((state & (Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE)) > 0)
{
+            if (isResolved(state)) {
                 successList.add(bundle.getBundleId());
-            }
+            } else
+                result = false;
         }
 
         return new BatchResolveResult(result, successList.toArray(new Long[] {})).toCompositeData();
     }
 
+    private boolean isResolved(int state) {
+        return (state & (Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE)) > 0;
+    }
+
     /**
      * @see org.osgi.jmx.framework.FrameworkMBean#resolveBundle(long)
      */
@@ -346,8 +357,8 @@ public class Framework implements Framew
         if (bundleIdentifiers != null)
             bundles = new Bundle[bundleIdentifiers.length];
 
-        boolean result = resolveBundles(bundleIdentifiers, bundles);
-        return constructResolveResult(bundles, result);
+        resolveBundles(bundleIdentifiers, bundles);
+        return constructResolveResult(bundles);
     }
 
     /**

Modified: aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/FrameworkMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/FrameworkMBeanTest.java?rev=1236164&r1=1236163&r2=1236164&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/FrameworkMBeanTest.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/FrameworkMBeanTest.java
Thu Jan 26 13:00:57 2012
@@ -320,7 +320,6 @@ public class FrameworkMBeanTest extends 
 
         FrameworkMBean framework = getMBean(FrameworkMBean.OBJECTNAME, FrameworkMBean.class);
         CompositeData result = framework.refreshBundlesAndWait(null);
-        assertTrue((Boolean) result.get(FrameworkMBean.SUCCESS));
         Set<Long> completed = new HashSet<Long>(Arrays.asList((Long []) result.get(FrameworkMBean.COMPLETED)));
         assertTrue(completed.contains(bundleA.getBundleId()));
         assertTrue(completed.contains(bundleB.getBundleId()));



Mime
View raw message