Examples of FrameworkWiring


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 = getBundleContext().getBundle(0).adapt(FrameworkWiring.class);
                File localRepository = getLocalRepository();
                List<Bundle> updated = new ArrayList<Bundle>();
                for (Bundle bundle : watchedBundles) {
                    try {
                        File location = getBundleExternalLocation(localRepository, bundle);
                        if (location != null
                                && location.exists()
                                && location.lastModified() > bundle.getLastModified())
                        {
                            InputStream is = new FileInputStream(location);
                            try {
                                logger.info("[Watch] Updating watched bundle: " + bundle.getSymbolicName() + " (" + bundle.getVersion() + ")");
                                System.out.println("[Watch] Updating watched bundle: " + bundle.getSymbolicName() + " (" + bundle.getVersion() + ")");
                                bundle.update(is);
                                updated.add(bundle);
                            } finally {
                                is.close();
                            }
                        }
                    } catch (IOException ex) {
                        logger.error("Error watching bundle.", ex);
                    } catch (BundleException ex) {
                        logger.error("Error updating bundle.", ex);
                    }
                }
                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

  @Override
  public Object execute(CommandLine commandLine)
    throws Exception
  {
    Bundle system = Platform.getBundle("system.bundle");
    FrameworkWiring framework =
      (FrameworkWiring)system.adapt(FrameworkWiring.class);

    ArrayList<Bundle> bundles = new ArrayList<Bundle>();
    bundles.add(Platform.getBundle("org.eclim.core"));
    framework.refreshBundles(bundles, new FrameworkListener[0]);

    // avoid Services.getMessage due to race condition on reload which can
    // result in a ConcurrentModificationException.
    PluginResources resources = Services.getPluginResources("org.eclim");
    return resources.getMessage("plugins.reloaded");
View Full Code Here

Examples of org.osgi.framework.wiring.FrameworkWiring

        return false;
    }

    protected void refreshPackages(Collection<Bundle> bundles) throws InterruptedException {
        final CountDownLatch latch = new CountDownLatch(1);
        FrameworkWiring fw = systemBundleContext.getBundle().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

                @Override
                public void frameworkEvent(FrameworkEvent event) {
                    l.countDown();
                }
            };
            FrameworkWiring wiring = (FrameworkWiring) bundleContext.getBundle(0).adapt(FrameworkWiring.class);
            wiring.refreshBundles((Collection<Bundle>) toRefresh, new FrameworkListener[]{listener});
            try {
                l.await();
            } catch (InterruptedException e) {
                throw new PatchException("Bundle refresh interrupted", e);
            }
View Full Code Here

Examples of org.osgi.framework.wiring.FrameworkWiring

        BundleContext bundleContext = createMock(BundleContext.class);
        Bundle sysBundle = createMock(Bundle.class);
        BundleContext sysBundleContext = createMock(BundleContext.class);
        Bundle bundle = createMock(Bundle.class);
        Bundle bundle2 = createMock(Bundle.class);
        FrameworkWiring wiring = createMock(FrameworkWiring.class);

        //
        // Create a new service, download a patch
        //
        expect(bundleContext.getBundle(0)).andReturn(sysBundle);
View Full Code Here

Examples of org.osgi.framework.wiring.FrameworkWiring

        BundleContext bundleContext = createMock(BundleContext.class);
        Bundle sysBundle = createMock(Bundle.class);
        BundleContext sysBundleContext = createMock(BundleContext.class);
        Bundle bundle = createMock(Bundle.class);
        Bundle bundle2 = createMock(Bundle.class);
        FrameworkWiring wiring = createMock(FrameworkWiring.class);

        //
        // Create a new service, download a patch
        //
        expect(bundleContext.getBundle(0)).andReturn(sysBundle);
        expect(sysBundle.getBundleContext()).andReturn(sysBundleContext);
        expect(sysBundleContext.getProperty(Service.PATCH_LOCATION))
                .andReturn(storage.toString()).anyTimes();
        replay(sysBundleContext, sysBundle, bundleContext, bundle);

        ServiceImpl service = new ServiceImpl(bundleContext);
       
        try {
            service.download(new URL("file:" + storage + "/temp/f00.zip"));
            fail("Should have thrown exception on non existent patch file.");
        } catch (Exception e) {         
        }       
       
        Iterable<Patch> patches = service.download(patch132.toURI().toURL());
        assertNotNull(patches);
        Iterator<Patch> it = patches.iterator();
        assertTrue( it.hasNext() );
        Patch patch = it.next();
        assertNotNull( patch );
        assertEquals("patch-1.3.2", patch.getId());
        assertNotNull(patch.getBundles());
        assertEquals(1, patch.getBundles().size());
        Iterator<String> itb = patch.getBundles().iterator();
        assertEquals("mvn:foo/my-bsn/1.3.2", itb.next());
        assertNull(patch.getResult());
        verify(sysBundleContext, sysBundle, bundleContext, bundle);

        //
        // Simulate the patch
        //

        reset(sysBundleContext, sysBundle, bundleContext, bundle);
       
        expect(sysBundleContext.getBundles()).andReturn(new Bundle[] { bundle });
        expect(bundle.getSymbolicName()).andReturn("my-bsn").anyTimes();
        expect(bundle.getVersion()).andReturn(new Version("1.3.1")).anyTimes();
        expect(bundle.getLocation()).andReturn("location");
        expect(bundle.getBundleId()).andReturn(123L);
        replay(sysBundleContext, sysBundle, bundleContext, bundle);
       
        Result result = patch.simulate();
        assertNotNull( result );
        assertNull( patch.getResult() );
        assertTrue(result.isSimulation());

        verify(sysBundleContext, sysBundle, bundleContext, bundle);

        //
        // Recreate a new service and verify the downloaded patch is still available
        //

        reset(sysBundleContext, sysBundle, bundleContext, bundle);
        expect(bundleContext.getBundle(0)).andReturn(sysBundle);
        expect(sysBundle.getBundleContext()).andReturn(sysBundleContext);
        expect(sysBundleContext.getProperty(Service.PATCH_LOCATION))
                .andReturn(storage.toString()).anyTimes();
        replay(sysBundleContext, sysBundle, bundleContext, bundle);

        service = new ServiceImpl(bundleContext);
        patches = service.getPatches();
        assertNotNull(patches);
        it = patches.iterator();
        assertTrue( it.hasNext() );
        patch = it.next();
        assertNotNull( patch );
        assertEquals("patch-1.3.2", patch.getId());
        assertNotNull(patch.getBundles());
        assertEquals(1, patch.getBundles().size());
        itb = patch.getBundles().iterator();
        assertEquals("mvn:foo/my-bsn/1.3.2", itb.next());
        assertNull(patch.getResult());
        verify(sysBundleContext, sysBundle, bundleContext, bundle);

        //
        // Install the patch
        //
       
        reset(sysBundleContext, sysBundle, bundleContext, bundle);

        expect(sysBundleContext.getBundles()).andReturn(new Bundle[] { bundle });
        expect(bundle.getSymbolicName()).andReturn("my-bsn").anyTimes();
        expect(bundle.getVersion()).andReturn(new Version("1.3.1")).anyTimes();
        expect(bundle.getLocation()).andReturn("location");
        expect(bundle.getHeaders()).andReturn(new Hashtable()).anyTimes();
        expect(bundle.getBundleId()).andReturn(123L);
        bundle.update(EasyMock.<InputStream>anyObject());
        expect(sysBundleContext.getBundles()).andReturn(new Bundle[] { bundle });
        expect(bundle.getState()).andReturn(Bundle.INSTALLED).anyTimes();
        expect(bundle.getRegisteredServices()).andReturn(null);
        expect(sysBundleContext.getBundle(0)).andReturn(sysBundle);
        expect(sysBundle.adapt(FrameworkWiring.class)).andReturn(wiring);
        bundle.start();
        wiring.refreshBundles(eq(asSet(bundle)), anyObject(FrameworkListener[].class));
        expectLastCall().andAnswer(new IAnswer<Object>() {
            @Override
            public Object answer() throws Throwable {
                for (FrameworkListener l : (FrameworkListener[]) (EasyMock.getCurrentArguments()[1])) {
                    l.frameworkEvent(null);
View Full Code Here

Examples of org.osgi.framework.wiring.FrameworkWiring

        BundleContext bundleContext = createMock(BundleContext.class);
        Bundle sysBundle = createMock(Bundle.class);
        BundleContext sysBundleContext = createMock(BundleContext.class);
        Bundle bundle = createMock(Bundle.class);
        Bundle bundle2 = createMock(Bundle.class);
        FrameworkWiring wiring = createMock(FrameworkWiring.class);

        //
        // Create a new service, download a patch
        //
        expect(bundleContext.getBundle(0)).andReturn(sysBundle);
View Full Code Here

Examples of org.osgi.framework.wiring.FrameworkWiring

        }
    }

    public void refreshPackages(Collection<Bundle> bundles) throws InterruptedException {
        final CountDownLatch latch = new CountDownLatch(1);
        FrameworkWiring fw = systemBundleContext.getBundle().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

@Command(scope = "bundle", name = "resolve", description = "Resolve bundles.")
@Service
public class Resolve extends BundlesCommand {

    protected Object doExecute(List<Bundle> bundles) throws Exception {
        FrameworkWiring wiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
        wiring.resolveBundles(bundles == null || bundles.isEmpty() ? null : bundles);
        return null;
    }
View Full Code Here

Examples of org.osgi.framework.wiring.FrameworkWiring

    public Refresh() {
        defaultAllBundles = false;
    }

    protected Object doExecute(List<Bundle> bundles) throws Exception {
        FrameworkWiring wiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
        if (bundles == null || bundles.isEmpty()) {
            bundles = null;
        }
        wiring.refreshBundles(bundles);
        return null;
    }
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.