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/12/21 18:01:41 UTC
svn commit: r1221804 - in /aries/trunk/sandbox/jmx-next:
jmx-api/src/main/java/org/osgi/jmx/framework/
jmx-core/src/main/java/org/apache/aries/jmx/codec/
jmx-core/src/main/java/org/apache/aries/jmx/framework/
jmx-core/src/test/java/org/apache/aries/jmx...
Author: davidb
Date: Wed Dec 21 17:01:41 2011
New Revision: 1221804
URL: http://svn.apache.org/viewvc?rev=1221804&view=rev
Log:
Support for FrameworkMBean.resolve()
Added:
aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchResolveResult.java (contents, props changed)
- copied, changed from r1221787, aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchRefreshResult.java
Removed:
aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchRefreshResult.java
Modified:
aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/FrameworkMBean.java
aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java
aries/trunk/sandbox/jmx-next/jmx-core/src/test/java/org/apache/aries/jmx/framework/FrameworkTest.java
Modified: aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/FrameworkMBean.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/FrameworkMBean.java?rev=1221804&r1=1221803&r2=1221804&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/FrameworkMBean.java (original)
+++ aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/FrameworkMBean.java Wed Dec 21 17:01:41 2011
@@ -328,6 +328,14 @@ public interface FrameworkMBean {
boolean resolveBundles(long[] bundleIdentifiers) throws IOException;
/**
+ * Same as {@link #resolveBundles(long[])} but with a more detailed return type.
+ * @param bundleIdentifiers
+ * @return
+ * @throws IOException
+ */
+ CompositeData resolve(long[] bundleIdentifiers) throws IOException;
+
+ /**
* Restart the framework by updating the system bundle
*
* @throws IOException if the operation failed
Copied: aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchResolveResult.java (from r1221787, aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchRefreshResult.java)
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchResolveResult.java?p2=aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchResolveResult.java&p1=aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchRefreshResult.java&r1=1221787&r2=1221804&rev=1221804&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchRefreshResult.java (original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchResolveResult.java Wed Dec 21 17:01:41 2011
@@ -25,11 +25,11 @@ import javax.management.openmbean.OpenDa
import org.osgi.jmx.framework.FrameworkMBean;
-public class BatchRefreshResult extends BatchResult {
+public class BatchResolveResult {
private final boolean success;
private final Long[] successfulBundles;
- public BatchRefreshResult(boolean success, Long[] successfulBundles) {
+ public BatchResolveResult(boolean success, Long[] successfulBundles) {
this.success = success;
this.successfulBundles = successfulBundles;
}
Propchange: aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BatchResolveResult.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=1221804&r1=1221803&r2=1221804&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 Wed Dec 21 17:01:41 2011
@@ -28,7 +28,7 @@ import javax.management.openmbean.Compos
import org.apache.aries.jmx.codec.BatchActionResult;
import org.apache.aries.jmx.codec.BatchInstallResult;
-import org.apache.aries.jmx.codec.BatchRefreshResult;
+import org.apache.aries.jmx.codec.BatchResolveResult;
import org.apache.aries.jmx.util.FrameworkUtils;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -183,28 +183,8 @@ public class Framework implements Framew
* @see org.osgi.jmx.framework.FrameworkMBean#refreshBundleAndWait(long)
*/
public boolean refreshBundleAndWait(long bundleIdentifier) throws IOException {
- final CountDownLatch latch = new CountDownLatch(1);
- FrameworkListener listener = new FrameworkListener() {
- public void frameworkEvent(FrameworkEvent event) {
- if (FrameworkEvent.PACKAGES_REFRESHED == event.getType()) {
- latch.countDown();
- }
- }
- };
- try {
- context.addFrameworkListener(listener);
- try {
- Bundle bundle = FrameworkUtils.resolveBundle(context, bundleIdentifier);
- packageAdmin.refreshPackages(new Bundle [] { bundle });
- return latch.await(10, TimeUnit.SECONDS);
- } catch (InterruptedException e) {
- IOException ex = new IOException();
- ex.initCause(e);
- throw ex;
- }
- } finally {
- context.removeFrameworkListener(listener);
- }
+ Bundle[] bundleArray = new Bundle[1];
+ return refreshBundlesAndWait(new long[] {bundleIdentifier}, bundleArray);
}
/**
@@ -231,6 +211,12 @@ public class Framework implements Framew
* @see org.osgi.jmx.framework.FrameworkMBean#refreshBundlesAndWait(long[])
*/
public CompositeData refreshBundlesAndWait(long[] bundleIdentifiers) throws IOException {
+ Bundle [] bundles = new Bundle[bundleIdentifiers.length];
+ boolean result = refreshBundlesAndWait(bundleIdentifiers, bundles);
+ return constructResolveResult(bundles, result);
+ }
+
+ private boolean refreshBundlesAndWait(long[] bundleIdentifiers, Bundle[] bundles) throws IOException {
final CountDownLatch latch = new CountDownLatch(1);
FrameworkListener listener = new FrameworkListener() {
public void frameworkEvent(FrameworkEvent event) {
@@ -242,22 +228,11 @@ public class Framework implements Framew
try {
context.addFrameworkListener(listener);
try {
- Bundle [] bundles = new Bundle[bundleIdentifiers.length];
for (int i=0; i < bundleIdentifiers.length; i++) {
bundles[i] = FrameworkUtils.resolveBundle(context, bundleIdentifiers[i]);
}
packageAdmin.refreshPackages(bundles);
- boolean result = latch.await(30, TimeUnit.SECONDS);
-
- List<Long> successList = new ArrayList<Long>();
- for (Bundle bundle : bundles) {
- int state = bundle.getState();
- if ((state & (Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE)) > 0) {
- successList.add(bundle.getBundleId());
- }
- }
-
- return new BatchRefreshResult(result, successList.toArray(new Long[] {})).toCompositeData();
+ return latch.await(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
IOException ex = new IOException();
ex.initCause(e);
@@ -268,6 +243,21 @@ public class Framework implements Framew
}
}
+ private CompositeData constructResolveResult(Bundle[] bundles, boolean result) {
+ if (bundles == null)
+ bundles = context.getBundles();
+
+ List<Long> successList = new ArrayList<Long>();
+ for (Bundle bundle : bundles) {
+ int state = bundle.getState();
+ if ((state & (Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE)) > 0) {
+ successList.add(bundle.getBundleId());
+ }
+ }
+
+ return new BatchResolveResult(result, successList.toArray(new Long[] {})).toCompositeData();
+ }
+
/**
* @see org.osgi.jmx.framework.FrameworkMBean#resolveBundle(long)
*/
@@ -280,20 +270,36 @@ public class Framework implements Framew
* @see org.osgi.jmx.framework.FrameworkMBean#resolveBundles(long[])
*/
public boolean resolveBundles(long[] bundleIdentifiers) throws IOException {
- Bundle[] bundles = null;
- if(bundleIdentifiers != null) {
- bundles = new Bundle[bundleIdentifiers.length];
- for (int i = 0; i < bundleIdentifiers.length; i++) {
- try {
- bundles[i] = FrameworkUtils.resolveBundle(context, bundleIdentifiers[i]);
- } catch (Exception e) {
- IOException ex = new IOException("Unable to find bundle with id " + bundleIdentifiers[i]);
- ex.initCause(e);
- throw ex;
- }
- }
- }
- return packageAdmin.resolveBundles(bundles);
+ Bundle[] bundles = null;
+ if (bundleIdentifiers != null)
+ bundles = new Bundle[bundleIdentifiers.length];
+
+ return resolveBundles(bundleIdentifiers, bundles);
+ }
+
+ private boolean resolveBundles(long[] bundleIdentifiers, Bundle[] bundles) throws IOException {
+ if (bundleIdentifiers != null) {
+ for (int i = 0; i < bundleIdentifiers.length; i++) {
+ try {
+ bundles[i] = FrameworkUtils.resolveBundle(context, bundleIdentifiers[i]);
+ } catch (Exception e) {
+ IOException ex = new IOException("Unable to find bundle with id " + bundleIdentifiers[i]);
+ ex.initCause(e);
+ throw ex;
+ }
+ }
+ }
+
+ return packageAdmin.resolveBundles(bundles);
+ }
+
+ public CompositeData resolve(long[] bundleIdentifiers) throws IOException {
+ Bundle[] bundles = null;
+ if (bundleIdentifiers != null)
+ bundles = new Bundle[bundleIdentifiers.length];
+
+ boolean result = resolveBundles(bundleIdentifiers, bundles);
+ return constructResolveResult(bundles, result);
}
/**
Modified: aries/trunk/sandbox/jmx-next/jmx-core/src/test/java/org/apache/aries/jmx/framework/FrameworkTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/test/java/org/apache/aries/jmx/framework/FrameworkTest.java?rev=1221804&r1=1221803&r2=1221804&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/test/java/org/apache/aries/jmx/framework/FrameworkTest.java (original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/test/java/org/apache/aries/jmx/framework/FrameworkTest.java Wed Dec 21 17:01:41 2011
@@ -21,10 +21,9 @@ import java.io.InputStream;
import javax.management.openmbean.CompositeData;
-import org.junit.Assert;
-
import org.apache.aries.jmx.codec.BatchActionResult;
import org.apache.aries.jmx.codec.BatchInstallResult;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
@@ -39,8 +38,8 @@ import org.osgi.service.startlevel.Start
/**
* {@link FrameworkMBean} test case.
- *
- *
+ *
+ *
* @version $Rev$ $Date$
*/
public class FrameworkTest {
@@ -140,7 +139,7 @@ public class FrameworkTest {
Assert.assertNotNull(batch2.getError());
Assert.assertEquals("file:test.jar", batch2.getBundleInError());
Assert.assertNotNull(batch2.getRemainingLocationItems());
- Assert.assertEquals(0, batch2.getRemainingLocationItems().length);
+ Assert.assertEquals(0, batch2.getRemainingLocationItems().length);
}
@Test
@@ -171,7 +170,7 @@ public class FrameworkTest {
Assert.assertNotNull(batch2.getError());
Assert.assertEquals("file:test.jar", batch2.getBundleInError());
Assert.assertNotNull(batch2.getRemainingLocationItems());
- Assert.assertEquals(0, batch2.getRemainingLocationItems().length);
+ Assert.assertEquals(0, batch2.getRemainingLocationItems().length);
}
@Test
@@ -215,6 +214,7 @@ public class FrameworkTest {
public void testResolveBundles() throws IOException {
Bundle bundle = Mockito.mock(Bundle.class);
Mockito.when(context.getBundle(1)).thenReturn(bundle);
+// Mockito.when(context.getBundles()).thenReturn(new Bundle [] { bundle });
mbean.resolveBundles(new long[] { 1 });
Mockito.verify(admin).resolveBundles(new Bundle[] { bundle });
@@ -300,7 +300,7 @@ public class FrameworkTest {
} catch (IOException ioe) {
// expected
}
-
+
Mockito.when(context.getBundle(6)).thenReturn(null);
try {
mbean.startBundle(6);
@@ -338,7 +338,7 @@ public class FrameworkTest {
Mockito.when(context.getBundle(5)).thenReturn(bundle);
mbean.stopBundle(5);
Mockito.verify(bundle).stop();
-
+
Mockito.when(context.getBundle(5)).thenReturn(null);
try {
mbean.stopBundle(5);
@@ -346,7 +346,7 @@ public class FrameworkTest {
} catch (IOException e) {
//expected
}
-
+
}
@Test