Examples of FrameworkWiring


Examples of org.osgi.framework.wiring.FrameworkWiring

               
        BundleContext context = applicationGBean.getBundle().getBundleContext();

        Collection<Bundle> bundles = Arrays.asList(targetBundle);
       
        FrameworkWiring wiring = context.getBundle(0).adapt(FrameworkWiring.class);

        try {
            // log dependents
            Collection<Bundle> dependents = wiring.getDependencyClosure(bundles);
            dependents.removeAll(bundles);
            if (!dependents.isEmpty()) {
                String bundleListString = bundleCollectionToString(dependents);
                LOG.info("Update of {} bundle will cause the following bundles to be refreshed: {}", bundleName, bundleListString);
            }
       
            // stop the bundle
            targetBundle.stop();

            InputStream in = null;
            String bundleLocation = targetBundle.getLocation();
            File location = BundleUtils.toFile(bundleLocation);
            if (location != null && location.isDirectory()) {
                // bundle installed from a directory - update bundle directory contents before calling update()
               
                // update bundle directory
                try {
                    updateEBA(targetBundle, bundleFile);
                } catch (Exception e) {
                    LOG.warn("Error updating application bundle with the new contents.", e);
                }
               
                URL url = new URL(bundleLocation);
                in = url.openStream();
            } else {
                // bundle is NOT installed from a directory - update bundle archive after calling update()           
                in = new FileInputStream(bundleFile);
            }
           
            // update the bundle
            try {
                targetBundle.update(in);
            } finally {
                IOUtils.close(in);
            }
           
            // resolve the bundle
            if (!wiring.resolveBundles(bundles)) {
                StringBuilder builder = new StringBuilder();
                builder.append("Updated ").append(bundleName).append(" bundle cannot be resolved.");
               
                // check for resolver errors
                ResolverErrorAnalyzer errorAnalyzer = new ResolverErrorAnalyzer(context);
                String resolverErrors = errorAnalyzer.getErrorsAsString(applicationGBean.getApplicationContent());
                if (resolverErrors != null) {
                    builder.append(" ").append(resolverErrors);
                }
               
                throw new BundleException(builder.toString());
            }
           
            if (location == null || !location.isDirectory()) {
                // update application archive
                try {
                    updateEBA(targetBundle, bundleFile);
                } catch (Exception e) {
                    LOG.warn("Error updating application archive with the new contents. " +
                             "Changes made might be gone next time the application or server is restarted.", e);
                }
            }
           
            // refresh the bundle and its dependents
            RefreshListener refreshListener = new RefreshListener();
            wiring.refreshBundles(bundles, refreshListener);
            refreshListener.waitForRefresh(bundleRefreshTimeout);

            // start the bundle
            if (BundleUtils.canStart(targetBundle)) {
                targetBundle.start(Bundle.START_TRANSIENT);
View Full Code Here

Examples of org.osgi.framework.wiring.FrameworkWiring

        URI uri = tmp.toURI();
       
        BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
        final Bundle sysBundle = EasyMock.createMock(Bundle.class);
        FrameworkWiring frameworkWiring = EasyMock.createMock(FrameworkWiring.class);
        Bundle installedBundle = EasyMock.createMock(Bundle.class);

        expect(bundleContext.getDataFile(EasyMock.<String>anyObject())).andReturn(dataFile).anyTimes();

        replay(bundleContext, installedBundle);

        FeaturesServiceImpl svc = new FeaturesServiceImpl();
        svc.setBundleContext(bundleContext);
        svc.addRepository(uri);
       
        verify(bundleContext, installedBundle);

        reset(bundleContext, installedBundle);

        // required since the sorted set uses it
        expect(installedBundle.compareTo(EasyMock.<Bundle>anyObject())).andReturn(0).anyTimes();

        // Installs f1 and 0.1
        expect(bundleContext.getBundles()).andReturn(new Bundle[0]);
        expect(bundleContext.installBundle(isA(String.class),
                                           isA(InputStream.class))).andReturn(installedBundle);
        expect(installedBundle.getBundleId()).andReturn(12345L);
        expect(installedBundle.getBundleId()).andReturn(12345L);
        expect(installedBundle.getBundleId()).andReturn(12345L);
        expect(bundleContext.getBundle(12345L)).andReturn(installedBundle);
        expect(installedBundle.getHeaders()).andReturn(new Hashtable());
        installedBundle.start();

        // Installs f1 and 0.2
        expect(bundleContext.getBundles()).andReturn(new Bundle[0]);
        expect(bundleContext.installBundle(isA(String.class),
                                           isA(InputStream.class))).andReturn(installedBundle);
        expect(installedBundle.getBundleId()).andReturn(123456L);
        expect(installedBundle.getBundleId()).andReturn(123456L);
        expect(installedBundle.getBundleId()).andReturn(123456L);
        expect(bundleContext.getBundle(123456L)).andReturn(installedBundle);
        expect(installedBundle.getHeaders()).andReturn(new Hashtable());
        installedBundle.start();

        // UnInstalls f1 and 0.1
        expect(bundleContext.getBundle(12345)).andReturn(installedBundle);
        installedBundle.uninstall();

        // UnInstalls f1 and 0.2
        expect(bundleContext.getBundle(123456)).andReturn(installedBundle);
        installedBundle.uninstall();

        expect(bundleContext.getDataFile(EasyMock.<String>anyObject())).andReturn(dataFile).anyTimes();

        // refresh
        expect(bundleContext.getBundle(0)).andStubReturn(sysBundle);
        expect(sysBundle.adapt(FrameworkWiring.class)).andStubReturn(frameworkWiring);
        final Capture<FrameworkListener> listeners =  new Capture<FrameworkListener>();
        frameworkWiring.refreshBundles(EasyMock.<Collection<Bundle>>eq(null), capture(listeners));
        expectLastCall().andStubAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                for (FrameworkListener listener : listeners.getValues()) {
                    listener.frameworkEvent(new FrameworkEvent(FrameworkEvent.PACKAGES_REFRESHED, sysBundle, null));
                }
View Full Code Here

Examples of org.osgi.framework.wiring.FrameworkWiring

        URI uri = tmp.toURI();

        BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
        final Bundle sysBundle = EasyMock.createMock(Bundle.class);
        FrameworkWiring frameworkWiring = EasyMock.createMock(FrameworkWiring.class);
        Bundle installedBundle = EasyMock.createMock(Bundle.class);

        // required since the sorted set uses it
        expect(installedBundle.compareTo(EasyMock.<Bundle>anyObject())).andReturn(0).anyTimes();

        // Installs feature f1 with dependency on f2
        // so will install f2 first
        expect(bundleContext.getBundles()).andReturn(new Bundle[0]);
        expect(bundleContext.installBundle(isA(String.class),
                                           isA(InputStream.class))).andReturn(installedBundle);
        expect(installedBundle.getBundleId()).andReturn(12345L);
        expect(installedBundle.getBundleId()).andReturn(12345L);
        expect(installedBundle.getBundleId()).andReturn(12345L);
        expect(bundleContext.getBundle(12345L)).andReturn(installedBundle);
        expect(installedBundle.getHeaders()).andReturn(new Hashtable());
        installedBundle.start();

        // Then installs f1
        expect(bundleContext.getBundles()).andReturn(new Bundle[0]).anyTimes();
        expect(bundleContext.installBundle(isA(String.class),
                                           isA(InputStream.class))).andReturn(installedBundle);
        expect(installedBundle.getBundleId()).andReturn(1234L);
        expect(installedBundle.getBundleId()).andReturn(1234L);
        expect(installedBundle.getBundleId()).andReturn(1234L);
        expect(bundleContext.getBundle(1234L)).andReturn(installedBundle);
        expect(installedBundle.getHeaders()).andReturn(new Hashtable()).anyTimes();
        installedBundle.start();

        // uninstalls first feature name = f1, version = 0.1
        expect(bundleContext.getBundle(1234)).andReturn(installedBundle);
        installedBundle.uninstall();

        // uninstalls first feature name = f2, version = 0.1
        expect(bundleContext.getBundle(12345)).andReturn(installedBundle);
        installedBundle.uninstall();

        expect(bundleContext.getDataFile(EasyMock.<String>anyObject())).andReturn(dataFile).anyTimes();

        // refresh
        expect(bundleContext.getBundle(0)).andStubReturn(sysBundle);
        expect(sysBundle.adapt(FrameworkWiring.class)).andStubReturn(frameworkWiring);
        final Capture<FrameworkListener> listeners =  new Capture<FrameworkListener>();
        frameworkWiring.refreshBundles(EasyMock.<Collection<Bundle>>eq(null), capture(listeners));
        expectLastCall().andStubAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                for (FrameworkListener listener : listeners.getValues()) {
                    listener.frameworkEvent(new FrameworkEvent(FrameworkEvent.PACKAGES_REFRESHED, sysBundle, null));
                }
View Full Code Here

Examples of org.osgi.framework.wiring.FrameworkWiring

        URI uri = tmp.toURI();

        BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
        final Bundle sysBundle = EasyMock.createMock(Bundle.class);
        FrameworkWiring frameworkWiring = EasyMock.createMock(FrameworkWiring.class);
        Bundle installedBundle = EasyMock.createMock(Bundle.class);

        // required since the sorted set uses it
        expect(installedBundle.compareTo(EasyMock.<Bundle>anyObject())).andReturn(0).anyTimes();

        // Installs feature f1 with dependency on f2
        expect(bundleContext.getBundles()).andReturn(new Bundle[0]).anyTimes();
        expect(bundleContext.installBundle(isA(String.class),
                                           isA(InputStream.class))).andReturn(installedBundle);
        expect(installedBundle.getBundleId()).andReturn(12345L).anyTimes();
        expect(bundleContext.getBundle(12345L)).andReturn(installedBundle).anyTimes();
        expect(installedBundle.getHeaders()).andReturn(new Hashtable()).anyTimes();
        installedBundle.start();

        expect(installedBundle.getSymbolicName()).andReturn(name).anyTimes();
        expect(bundleContext.installBundle(isA(String.class),
                                           isA(InputStream.class))).andReturn(installedBundle);
        installedBundle.start();

        expect(bundleContext.getBundle(0)).andReturn(sysBundle);
        expect(sysBundle.adapt(FrameworkWiring.class)).andReturn(frameworkWiring);

        // uninstalls first feature name = f2, version = 0.1
        installedBundle.uninstall();

        expect(bundleContext.getDataFile(EasyMock.<String>anyObject())).andReturn(dataFile).anyTimes();

        // refresh
        expect(bundleContext.getBundle(0)).andStubReturn(sysBundle);
        expect(sysBundle.adapt(FrameworkWiring.class)).andStubReturn(frameworkWiring);
        final Capture<FrameworkListener> listeners =  new Capture<FrameworkListener>();
        frameworkWiring.refreshBundles(EasyMock.<Collection<Bundle>>eq(null), capture(listeners));
        expectLastCall().andStubAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                for (FrameworkListener listener : listeners.getValues()) {
                    listener.frameworkEvent(new FrameworkEvent(FrameworkEvent.PACKAGES_REFRESHED, sysBundle, null));
                }
View Full Code Here

Examples of org.osgi.framework.wiring.FrameworkWiring

    private BundleContext prepareBundleContextForInstallUninstall() throws Exception {
        BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
        Bundle installedBundle = EasyMock.createMock(Bundle.class);
        final Bundle sysBundle = EasyMock.createMock(Bundle.class);
        FrameworkWiring frameworkWiring = EasyMock.createMock(FrameworkWiring.class);

        // required since the sorted set uses it
        expect(installedBundle.compareTo(EasyMock.<Bundle>anyObject())).andReturn(0).anyTimes();

        // Installs feature f1 with dependency on f2
        expect(bundleContext.getBundles()).andReturn(new Bundle[0]).anyTimes();
        expect(bundleContext.installBundle(isA(String.class),
                                           isA(InputStream.class))).andReturn(installedBundle);
        expect(installedBundle.getBundleId()).andReturn(12345L);
        expect(installedBundle.getBundleId()).andReturn(12345L);
        expect(installedBundle.getBundleId()).andReturn(12345L);
        expect(bundleContext.getBundle(12345L)).andReturn(installedBundle);
        expect(installedBundle.getHeaders()).andReturn(new Hashtable());
        installedBundle.start();

        // uninstalls first feature name = f2, version = 0.1
        expect(bundleContext.getBundle(12345)).andReturn(installedBundle);
        installedBundle.uninstall();

        expect(bundleContext.getDataFile(EasyMock.<String>anyObject())).andReturn(dataFile).anyTimes();

        // refresh
        expect(bundleContext.getBundle(0)).andStubReturn(sysBundle);
        expect(sysBundle.adapt(FrameworkWiring.class)).andStubReturn(frameworkWiring);

        final Capture<FrameworkListener> listeners =  new Capture<FrameworkListener>();
        frameworkWiring.refreshBundles(EasyMock.<Collection<Bundle>>eq(null), capture(listeners));
        expectLastCall().andStubAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                for (FrameworkListener listener : listeners.getValues()) {
                    listener.frameworkEvent(new FrameworkEvent(FrameworkEvent.PACKAGES_REFRESHED, sysBundle, null));
                }
View Full Code Here

Examples of org.osgi.framework.wiring.FrameworkWiring

        }

        // loads the state
        BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
        final Bundle sysBundle = EasyMock.createMock(Bundle.class);
        FrameworkWiring frameworkWiring = EasyMock.createMock(FrameworkWiring.class);
        Bundle installedBundle1 = EasyMock.createMock(Bundle.class);
        Bundle installedBundle2 = EasyMock.createMock(Bundle.class);

        // required since the sorted set uses it
        expect(installedBundle1.compareTo(EasyMock.<Bundle>anyObject())).andReturn(0).anyTimes();
        expect(installedBundle2.compareTo(EasyMock.<Bundle>anyObject())).andReturn(0).anyTimes();

        // Installs feature f1
        expect(installedBundle1.getBundleId()).andReturn(12345L);
        expect(installedBundle1.getBundleId()).andReturn(12345L);
        expect(installedBundle1.getBundleId()).andReturn(12345L);
        expect(installedBundle1.getSymbolicName()).andReturn(headers.get(Constants.BUNDLE_SYMBOLICNAME)).anyTimes();
        expect(installedBundle1.getHeaders()).andReturn(headers).anyTimes();
        expect(bundleContext.getBundles()).andReturn(new Bundle[] { installedBundle1 });
        expect(bundleContext.getBundles()).andReturn(new Bundle[] { installedBundle1 });

        expect(bundleContext.installBundle(eq(bundle2), isA(InputStream.class))).andReturn(installedBundle2);
        expect(bundleContext.getBundles()).andReturn(new Bundle[] { installedBundle1, installedBundle2 });
        expect(installedBundle2.getBundleId()).andReturn(54321L);
        expect(installedBundle2.getBundleId()).andReturn(54321L);
        expect(installedBundle2.getBundleId()).andReturn(54321L);
        expect(installedBundle2.getSymbolicName()).andReturn("fragment").anyTimes();
        Dictionary d = new Hashtable();
        d.put(Constants.FRAGMENT_HOST, headers.get(Constants.BUNDLE_SYMBOLICNAME));
        expect(installedBundle2.getHeaders()).andReturn(d).anyTimes();

        expect(installedBundle1.getState()).andReturn(Bundle.ACTIVE);
        expect(installedBundle1.getState()).andReturn(Bundle.ACTIVE);
        expect(installedBundle2.getState()).andReturn(Bundle.INSTALLED);
        expect(installedBundle2.getState()).andReturn(Bundle.INSTALLED);

        //
        // This is the real test to make sure the host is actually refreshed
        //
        expect(bundleContext.getBundle(0)).andReturn(sysBundle);
        expect(sysBundle.adapt(FrameworkWiring.class)).andReturn(frameworkWiring);
        final Capture<FrameworkListener> capture =  new Capture<FrameworkListener>();
        frameworkWiring.refreshBundles(eq(Collections.singleton(installedBundle1)), capture(capture));
        expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                for (FrameworkListener listener : capture.getValues()) {
                    listener.frameworkEvent(new FrameworkEvent(FrameworkEvent.PACKAGES_REFRESHED, sysBundle, null));
                }
View Full Code Here

Examples of org.osgi.framework.wiring.FrameworkWiring

        }
    }

    protected void refreshPackages(Collection<Bundle> bundles) throws InterruptedException {
        final CountDownLatch latch = new CountDownLatch(1);
        FrameworkWiring fw = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
        fw.refreshBundles(bundles, new FrameworkListener() {
            @Override
            public void frameworkEvent(FrameworkEvent event) {
                if (event.getType() == FrameworkEvent.ERROR) {
                    LOGGER.error("Framework error", event.getThrowable());
                }
View Full Code Here

Examples of org.osgi.framework.wiring.FrameworkWiring

        });
        latch.await();
    }

    protected void refreshPackagesAsync(Collection<Bundle> bundles) throws InterruptedException {
        FrameworkWiring fw = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
        fw.refreshBundles(bundles);
    }
View Full Code Here

Examples of org.osgi.framework.wiring.FrameworkWiring

    }

    try {
      // 刷新Bundle
      Bundle systemBundle = bundleContext.getBundle(0);
      FrameworkWiring frameworkWiring = systemBundle
          .adapt(FrameworkWiring.class);

      for (Bundle bundle : frameworkWiring.getRemovalPendingBundles()) {
        log.debug("RemovalPendingBundle:" + bundle.getSymbolicName());
      }
      frameworkWiring.refreshBundles(null);
    } catch (Error error) {
      log.warn("RemovalPendingBundle error." + error.getMessage());
    }

    // 休息0.001秒钟
View Full Code Here

Examples of org.osgi.framework.wiring.FrameworkWiring

    }

    try {
      // 刷新Bundle
      Bundle systemBundle = bundleContext.getBundle(0);
      FrameworkWiring frameworkWiring = systemBundle
          .adapt(FrameworkWiring.class);

      for (Bundle bundle : frameworkWiring.getRemovalPendingBundles()) {
        logger.config("RemovalPendingBundle:"
            + bundle.getSymbolicName());
      }
      frameworkWiring.refreshBundles(null);

    } catch (Error error) {
      logger.warning("RemovalPendingBundle error." + error.getMessage());
    }
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.