+ protected void waitForBundleResolvedOrActive(Bundle bundle)
+ throws Exception {
+ int originalState = bundle.getState();
+ if ((originalState == Bundle.RESOLVED)
+ || (originalState == Bundle.ACTIVE))
+ return;
+
+ String originalStateStr = stateAsString(originalState);
+
+ long begin = System.currentTimeMillis();
+ while ((bundle.getState() != Bundle.RESOLVED)
+ || (bundle.getState() != Bundle.ACTIVE)) {
+ long now = System.currentTimeMillis();
+ if ((now - begin) > defaultTimeout)
+ throw new Exception("Bundle " + bundle.getSymbolicName()
+ + " was not RESOLVED or ACTIVE after " + (now - begin)
+ + "ms (originalState=" + originalStateStr
+ + ", currentState=" + stateAsString(bundle.getState())
+ + ")");
+
+ try {
+ Thread.sleep(100l);
+ } catch (InterruptedException e) {
+ // silent
+ }
+ }
+ }
+
+ public static String stateAsString(int state) {
+ switch (state) {
+ case Bundle.UNINSTALLED:
+ return "UNINSTALLED";
+ case Bundle.INSTALLED:
+ return "INSTALLED";
+ case Bundle.RESOLVED:
+ return "RESOLVED";
+ case Bundle.STARTING:
+ return "STARTING";
+ case Bundle.ACTIVE:
+ return "ACTIVE";
+ case Bundle.STOPPING:
+ return "STOPPING";
+ default:
+ return Integer.toString(state);
+ }
+ }
+