Package org.osgi.util.tracker

Examples of org.osgi.util.tracker.BundleTracker


        Server defaultServer = DefaultJettyAtJettyHomeHelper.startJettyAtJettyHome(context);

        //Create a bundle tracker to help deploy webapps and ContextHandlers
        BundleWatcher bundleTrackerCustomizer = new BundleWatcher();
        bundleTrackerCustomizer.setWaitForDefaultServer(defaultServer != null);
        _webBundleTracker =  new BundleTracker(context, Bundle.ACTIVE | Bundle.STOPPING, bundleTrackerCustomizer);
        bundleTrackerCustomizer.setBundleTracker(_webBundleTracker);
        bundleTrackerCustomizer.open();
    }
View Full Code Here


    // Track the main-thread executor and register the Eclipse ApplicationLauncher around it
    executorTracker = new MainThreadExecutorTracker(context);
    executorTracker.open();

    // Ensure that the Equinox Application Admin bundle is fully started
    bundleTracker = new BundleTracker(context, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING, null) {
        @Override
        public Object addingBundle(Bundle bundle, BundleEvent event) {
            if("org.eclipse.equinox.app".equals(bundle.getSymbolicName())) {
                try {
                        bundle.start();
View Full Code Here

    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

    public RecursiveBundleTracker(BundleContext context, int stateMask, BundleTrackerCustomizer customizer) {
        //This test only makes sense for composite bundles, but in the interests of more consistent behavior lets leave it.
        // We always need INSTALLED events so we can recursively listen to the frameworks
        if ((stateMask & COMPOSITE_BUNDLE_MASK) != COMPOSITE_BUNDLE_MASK)
            throw new IllegalArgumentException();
        BundleTracker tracker = null;
        try {
            //R43, equinox composite bundles seem to produce appropriate bundle event hook notifications
            tracker = new BundleHookBundleTracker(context, stateMask, customizer);
        } catch (Throwable e) {
        }
        if (areMultipleFrameworksAvailable(context)) {
            compositeTracker = new InternalRecursiveBundleTracker(context, stateMask, customizer, tracker == null);
        } else {
            compositeTracker = null;
        }
        if (tracker == null && compositeTracker == null) {
            //R42
            tracker = new BundleTracker(context, stateMask, customizer);
        }
        this.tracker = tracker;
    }
View Full Code Here

    public void start(BundleContext context) throws Exception {
        OSGiOMMetaFactoryLocator locator = new OSGiOMMetaFactoryLocator(context);
        OMAbstractFactory.setMetaFactoryLocator(locator);
        // Bundle.STARTING covers the case where the implementation bundle has
        // "Bundle-ActivationPolicy: lazy".
        tracker = new BundleTracker(context, Bundle.STARTING | Bundle.ACTIVE, locator);
        tracker.open();
        // In an OSGi environment, the thread context class loader is generally not set in a meaningful way.
        // Therefore we should use singleton factories. Note that if the StAX API is provided by Geronimo's or
        // Servicemix's StAX bundle, then this actually doesn't change much because the factory locator code in
        // these bundles don't care about the thread context class loader anyway. Nevertheless, it prevents
View Full Code Here

        SystemInstance.get().setComponent(DiscoveryRegistry.class, registry);

        started = Boolean.FALSE;
        stopped = false;
        final ServerServiceTracker t = new ServerServiceTracker();
        tracker = new BundleTracker(bundleContext, Bundle.ACTIVE | Bundle.STOPPING, t);
        tracker.open();
    }
View Full Code Here

    {
        this.ctx = ctx;
        ServiceReference ref = ctx.getServiceReference(PackageAdmin.class.getName());
        pkgAdm = PackageAdmin.class.cast(ctx.getService(ref));

        BundleTracker bt = new BundleTracker(ctx, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE, new BundleTrackerCustomizer() {
           
            @Override
            public void modifiedBundle(Bundle bundle, BundleEvent bundleEvent, Object o) {
            }

            @Override
            public Object addingBundle(Bundle bundle, BundleEvent bundleEvent) {
                String key = makeKey(bundle);
                name2Id.put(key, bundle.getBundleId());
                if (logger != null && logger.isLoggable(Level.FINER)) {
                    logger.log(Level.FINER, "BundleTracker.addingBundle BUNDLE " + key + " ==> " + bundle.getBundleId() + "  for " + bundle.getSymbolicName());
                }
                return null;
            }

            @Override
            public void removedBundle(Bundle bundle, BundleEvent bundleEvent, Object o) {
                String key = makeKey(bundle);
                Long bundleID = name2Id.remove(key);
                if (logger.isLoggable(Level.FINER)) {
                    logger.log(Level.FINER, "BundleTracker.removedBundle BUNDLE " + key + "  ==> " + bundle.getSymbolicName());
                }
                if (bundleID == null) {
                    logger.log(Level.WARNING, NULL_BUNDLE, key);
                }
            }
            /*
            @Override
            public Object addingBundle(Bundle bundle, BundleEvent event) {
                System.out.println("ADDING BUNDLE ==> " + bundle.getSymbolicName());
                return super.addingBundle(bundle, event);    //To change body of overridden methods use File | Settings | File Templates.
            }

            @Override
            public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
                System.out.println("REMOVING BUNDLE ==> " + bundle.getSymbolicName());               
                super.removedBundle(bundle, event, object);    //To change body of overridden methods use File | Settings | File Templates.
            }
            */
        });

        bt.open();

    }
View Full Code Here

    {
        this.ctx = ctx;
        ServiceReference ref = ctx.getServiceReference(PackageAdmin.class.getName());
        pkgAdm = PackageAdmin.class.cast(ctx.getService(ref));

        BundleTracker bt = new BundleTracker(ctx, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE, new BundleTrackerCustomizer() {
           
            @Override
            public void modifiedBundle(Bundle bundle, BundleEvent bundleEvent, Object o) {
            }

            @Override
            public Object addingBundle(Bundle bundle, BundleEvent bundleEvent) {
                String key = makeKey(bundle);
                name2Id.put(key, bundle.getBundleId());
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "BundleTracker.addingBundle BUNDLE " + key + " ==> " + bundle.getBundleId() + "  for " + bundle.getSymbolicName());
                }
                return null;
            }

            @Override
            public void removedBundle(Bundle bundle, BundleEvent bundleEvent, Object o) {
                String key = makeKey(bundle);
                Long bundleID = name2Id.remove(key);
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "BundleTracker.removedBundle BUNDLE " + key + "  ==> " + bundle.getSymbolicName());
                }
                if (bundleID == null) {
                    _logger.log(Level.WARNING, "BundleTracker.removedBundle null bundleID for ==> " + key);
                }
            }
            /*
            @Override
            public Object addingBundle(Bundle bundle, BundleEvent event) {
                System.out.println("ADDING BUNDLE ==> " + bundle.getSymbolicName());
                return super.addingBundle(bundle, event);    //To change body of overridden methods use File | Settings | File Templates.
            }

            @Override
            public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
                System.out.println("REMOVING BUNDLE ==> " + bundle.getSymbolicName());               
                super.removedBundle(bundle, event, object);    //To change body of overridden methods use File | Settings | File Templates.
            }
            */
        });

        bt.open();

    }
View Full Code Here

      if ((stateMask & COMPOSITE_BUNDLE_MASK) != COMPOSITE_BUNDLE_MASK)
            throw new IllegalArgumentException();
       if (areMultipleFrameworksAvailable(context)) {
          tracker = new InternalRecursiveBundleTracker(context, stateMask, customizer);
        } else {
         tracker = new BundleTracker(context, stateMask, customizer);
        }
    }
View Full Code Here

    BundleContext compositeBundleContext = cb.getCompositeFramework().getBundleContext();
    if (!alreadyRecursedContexts.contains(compositeBundleContext)) {
      alreadyRecursedContexts.add(compositeBundleContext);

      // let's track each of the bundle in the CompositeBundle
      BundleTracker bt = new InternalRecursiveBundleTracker(compositeBundleContext, stateMask,
          customizer);
      bt.open();
      BundleTrackerFactory.registerBundleTracker(bundleScope, bt);
    }
  }
View Full Code Here

TOP

Related Classes of org.osgi.util.tracker.BundleTracker

Copyright © 2018 www.massapicom. 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.