Examples of BundleTracker


Examples of org.osgi.util.tracker.BundleTracker

    protected void awaitArquillianBundleActive(BundleContext syscontext, long timeout, TimeUnit unit) throws LifecycleException {
        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicReference<Bundle> bundleRef = new AtomicReference<Bundle>();
        int states = Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE;
        BundleTracker tracker = new BundleTracker(syscontext, states, null) {
            @Override
            public Bundle addingBundle(Bundle bundle, BundleEvent event) {
                if ("arquillian-osgi-bundle".equals(bundle.getSymbolicName())) {
                    bundleRef.set(bundle);
                    return bundle;
                } else {
                    return null;
                }
            }

            @Override
            public void modifiedBundle(Bundle bundle, BundleEvent event, Object tracked) {
                if (event != null && event.getType() == BundleEvent.STARTED) {
                    latch.countDown();
                }
            }
        };
        tracker.open();

        try {
            Bundle arqBundle = bundleRef.get();
            if (arqBundle == null || arqBundle.getState() != Bundle.ACTIVE) {
                try {
                    if (!latch.await(timeout, unit)) {
                        throw new LifecycleException("Framework startup timeout");
                    }
                } catch (InterruptedException ex) {
                    throw new LifecycleException("Framework startup interupted", ex);
                }
            }
        } finally {
            tracker.close();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.