public void waitForFeature(String featureName, Predicate<FeatureState> predicate) throws Exception { boolean ready = false; long timeoutLimit = System.currentTimeMillis() + REQUIRED_BUNDLES_TIMEOUT; while (!ready) { FeaturesService featuresService = getFeaturesService(); if (featuresService != null) { Feature feature = featuresService.getFeature(featureName); FeatureState state = featuresService.getState(feature.getName() + "/" + feature.getVersion()); if (state == null) { LOGGER.warn("No Feature found for featureName: {}", featureName); return; } else if (predicate.test(state)) { ready = true; } } if (!ready) { if (System.currentTimeMillis() > timeoutLimit) { printInactiveBundles(); fail( String.format( "Feature did not change to State [" + predicate.toString() + "] within %d minutes.", TimeUnit.MILLISECONDS.toMinutes(REQUIRED_BUNDLES_TIMEOUT))); } LOGGER.info("Feature [{}] not [{}], sleeping...", featureName, predicate.toString()); Thread.sleep(1000); } } }
public CatalogProvider waitForCatalogProvider() throws InterruptedException { LOGGER.info("Waiting for CatalogProvider to become available."); serviceManager.printInactiveBundles(); CatalogProvider provider = null; long timeoutLimit = System.currentTimeMillis() + CATALOG_PROVIDER_TIMEOUT; boolean available = false; while (!available) { if (provider == null) { ServiceReference<CatalogProvider> providerRef = serviceManager.getServiceReference(CatalogProvider.class); if (providerRef != null) { provider = serviceManager.getService(providerRef); } } if (provider != null) { available = provider.isAvailable(); } if (!available) { if (System.currentTimeMillis() > timeoutLimit) { LOGGER.info("CatalogProvider.isAvailable = false"); serviceManager.printInactiveBundles(); fail( String.format( "Catalog provider timed out after %d minutes.", TimeUnit.MILLISECONDS.toMinutes(CATALOG_PROVIDER_TIMEOUT))); } Thread.sleep(100); } } LOGGER.info("CatalogProvider is available."); return provider; }
public void waitForRequiredBundles(String symbolicNamePrefix) throws InterruptedException { boolean ready = false; if (bundleService == null) { bundleService = getService(BundleService.class); } long timeoutLimit = System.currentTimeMillis() + REQUIRED_BUNDLES_TIMEOUT; while (!ready) { List<Bundle> bundles = Arrays.asList(bundleCtx.getBundles()); ready = true; for (Bundle bundle : bundles) { if (bundle.getSymbolicName().startsWith(symbolicNamePrefix)) { String bundleName = bundle.getHeaders().get(Constants.BUNDLE_NAME); BundleInfo bundleInfo = bundleService.getInfo(bundle); BundleState bundleState = bundleInfo.getState(); if (bundleInfo.isFragment()) { if (!BundleState.Resolved.equals(bundleState)) { LOGGER.info("{} bundle not ready yet", bundleName); ready = false; } } else if (bundleState != null) { if (BundleState.Failure.equals(bundleState)) { fail("The bundle " + bundleName + " failed."); } else if (!BundleState.Active.equals(bundleState)) { LOGGER.info("{} bundle not ready with state {}", bundleName, bundleState); ready = false; } } } } if (!ready) { if (System.currentTimeMillis() > timeoutLimit) { printInactiveBundles(); fail( String.format( "Bundles and blueprint did not start within %d minutes.", TimeUnit.MILLISECONDS.toMinutes(REQUIRED_BUNDLES_TIMEOUT))); } LOGGER.info("Bundles not up, sleeping..."); Thread.sleep(1000); } } }