Examples of FrameworkWiring


Examples of org.osgi.framework.wiring.FrameworkWiring

    public Object execute() throws Exception {
        if (!confirm(session)) {
            return null;
        }
        final BundleContext bundleContext = this.bundleContext.getBundle(0).getBundleContext();
        final FrameworkWiring wiring = bundleContext.getBundle().adapt(FrameworkWiring.class);
        final CountDownLatch latch = new CountDownLatch(threads);
        final Bundle[] bundles = bundleContext.getBundles();
        final AtomicBoolean[] locks = new AtomicBoolean[bundles.length];
        for (int b = 0; b < locks.length; b++) {
            locks[b] = new AtomicBoolean(true);
            // Avoid touching excluded bundles
            if (excludes.contains(Long.toString(bundles[b].getBundleId()))
                    || excludes.contains(bundles[b].getSymbolicName())) {
                continue;
            }
            // Only touch active bundles
            if (bundles[b].getState() != Bundle.ACTIVE) {
                continue;
            }
            // Now set the lock to available
            locks[b].set(false);
        }
        for (int i = 0; i < threads; i++) {
            new Thread() {
                public void run() {
                    try {
                        Random rand = new Random();
                        for (int j = 0; j < iterations; j++) {
                            for (;;) {
                                int b = rand.nextInt(bundles.length);
                                if (locks[b].compareAndSet(false, true)) {
                                    try {
                                        // Only touch active bundles
                                        if (bundles[b].getState() != Bundle.ACTIVE) {
                                            continue;
                                        }
                                        if (rand.nextInt(100) < refresh) {
                                            try {
                                                bundles[b].update();
                                                final CountDownLatch latch = new CountDownLatch(1);
                                                wiring.refreshBundles(Collections.singletonList(bundles[b]), new FrameworkListener() {
                                                    public void frameworkEvent(FrameworkEvent event) {
                                                        latch.countDown();
                                                    }
                                                });
                                                latch.await();
View Full Code Here

Examples of org.osgi.framework.wiring.FrameworkWiring

                    }
                }
            }
            if (watchedBundles.size() > 0) {
                // Get the wiring before any in case of a refresh of a dependency
                FrameworkWiring wiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
                File localRepository = this.localRepoDetector.getLocalRepository();
                List<Bundle> updated = new ArrayList<Bundle>();
                for (Bundle bundle : watchedBundles) {
                    try {
                        updateBundleIfNecessary(localRepository, updated, bundle);
                    } catch (IOException ex) {
                        logger.error("Error watching bundle.", ex);
                    } catch (BundleException ex) {
                        logger.error("Error updating bundle.", ex);
                    }
                }
                if (!updated.isEmpty()) {
                    try {
                        final CountDownLatch latch = new CountDownLatch(1);
                        wiring.refreshBundles(updated, new FrameworkListener() {
                            public void frameworkEvent(FrameworkEvent event) {
                                latch.countDown();
                            }
                        });
                        latch.await();
View Full Code Here

Examples of org.osgi.framework.wiring.FrameworkWiring

      getServiceRegistrations().addAll(servicesRegistered);
    }
  }

  protected void startBundles(final List<Bundle> bundles) {
    final FrameworkWiring frameworkWiring = getFramework().adapt(FrameworkWiring.class);
    if (frameworkWiring.resolveBundles(bundles) == false) {
      if (logger.isWarnEnabled()) {
        logger.warn("Could not resolve all {} bundles.", bundles.size());
      }
    }
    for (final Bundle bundle : bundles) {
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.