Search in sources :

Example 11 with FrameworkWiring

use of org.osgi.framework.wiring.FrameworkWiring in project motech by motech.

the class JarGeneratorServiceImpl method clearModulesCache.

private void clearModulesCache(String[] moduleNames) {
    for (String moduleName : moduleNames) {
        if (StringUtils.isNotBlank(moduleName)) {
            Bundle bundleToRefresh = WebBundleUtil.findBundleBySymbolicName(bundleContext, moduleName);
            Bundle frameworkBundle = bundleContext.getBundle(0);
            FrameworkWiring frameworkWiring = frameworkBundle.adapt(FrameworkWiring.class);
            Collection<Bundle> dependencyClosureBundles = frameworkWiring.getDependencyClosure(Arrays.asList(bundleToRefresh));
            for (Bundle bundle : dependencyClosureBundles) {
                MdsBundleHelper.unregisterBundleJDOClasses(bundle);
            }
        }
    }
    ResourceBundle.clearCache();
}
Also used : Bundle(org.osgi.framework.Bundle) ResourceBundle(java.util.ResourceBundle) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring)

Example 12 with FrameworkWiring

use of org.osgi.framework.wiring.FrameworkWiring in project vespa by vespa-engine.

the class FelixFramework method refreshPackages.

@Override
public void refreshPackages() {
    FrameworkWiring wiring = felix.adapt(FrameworkWiring.class);
    final CountDownLatch latch = new CountDownLatch(1);
    wiring.refreshBundles(null, event -> {
        switch(event.getType()) {
            case FrameworkEvent.PACKAGES_REFRESHED:
                latch.countDown();
                break;
            case FrameworkEvent.ERROR:
                log.log(Level.SEVERE, "ERROR FrameworkEvent received.", event.getThrowable());
                break;
        }
    });
    try {
        long TIMEOUT_SECONDS = 60L;
        if (!latch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
            log.warning("No PACKAGES_REFRESHED FrameworkEvent received within " + TIMEOUT_SECONDS + " seconds of calling FrameworkWiring.refreshBundles()");
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
Also used : FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 13 with FrameworkWiring

use of org.osgi.framework.wiring.FrameworkWiring in project aries by apache.

the class FrameworkMBeanTest method testGetDependencyClosure.

@Test
public void testGetDependencyClosure() throws Exception {
    Bundle bundleA = getBundleByName("org.apache.aries.jmx.test.bundlea");
    Bundle bundleB = getBundleByName("org.apache.aries.jmx.test.bundleb");
    BundleWiring bw = (BundleWiring) bundleB.adapt(BundleWiring.class);
    List<BundleWire> initialRequiredWires = bw.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
    assertEquals(1, initialRequiredWires.size());
    BundleWire wire = initialRequiredWires.get(0);
    Map<String, Object> capabilityAttributes = wire.getCapability().getAttributes();
    assertEquals("Precondition", bundleA.getSymbolicName(), capabilityAttributes.get(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE));
    assertEquals("Precondition", new Version("1.0"), capabilityAttributes.get(Constants.BUNDLE_VERSION_ATTRIBUTE));
    assertEquals("Precondition", "org.apache.aries.jmx.test.bundlea.api", capabilityAttributes.get(BundleRevision.PACKAGE_NAMESPACE));
    Collection<Bundle> expectedDC = ((FrameworkWiring) context().getBundle(0).adapt(FrameworkWiring.class)).getDependencyClosure(Collections.singleton(bundleA));
    Set<Long> expectedClosure = new TreeSet<Long>();
    for (Bundle b : expectedDC) {
        expectedClosure.add(b.getBundleId());
    }
    long[] actualDC = framework.getDependencyClosure(new long[] { bundleA.getBundleId() });
    Set<Long> actualClosure = new TreeSet<Long>();
    for (long l : actualDC) {
        actualClosure.add(l);
    }
    assertEquals(expectedClosure, actualClosure);
}
Also used : Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) BundleWire(org.osgi.framework.wiring.BundleWire) Version(org.osgi.framework.Version) TreeSet(java.util.TreeSet) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Example 14 with FrameworkWiring

use of org.osgi.framework.wiring.FrameworkWiring in project aries by apache.

the class Framework method getDependencyClosure.

/**
 * @see org.osgi.jmx.framework.FrameworkMBean#getDependencyClosureBundles(long[])
 */
public long[] getDependencyClosure(long[] bundles) throws IOException {
    FrameworkWiring fw = context.getBundle(0).adapt(FrameworkWiring.class);
    List<Bundle> bl = new ArrayList<Bundle>();
    for (int i = 0; i < bundles.length; i++) {
        bl.add(context.getBundle(bundles[i]));
    }
    Collection<Bundle> rc = fw.getDependencyClosure(bl);
    Iterator<Bundle> it = rc.iterator();
    long[] result = new long[rc.size()];
    for (int i = 0; i < result.length; i++) {
        result[i] = it.next().getBundleId();
    }
    return result;
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring)

Example 15 with FrameworkWiring

use of org.osgi.framework.wiring.FrameworkWiring in project aries by apache.

the class SubsystemTest method assertResolve.

protected void assertResolve(Collection<Bundle> bundles) {
    FrameworkWiring wiring = getSystemBundleAsFrameworkWiring();
    assertTrue("Bundles not resolved", wiring.resolveBundles(bundles));
}
Also used : FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring)

Aggregations

FrameworkWiring (org.osgi.framework.wiring.FrameworkWiring)39 Bundle (org.osgi.framework.Bundle)29 Test (org.junit.Test)12 URL (java.net.URL)10 FrameworkListener (org.osgi.framework.FrameworkListener)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 BundleContext (org.osgi.framework.BundleContext)7 HashSet (java.util.HashSet)6 FrameworkEvent (org.osgi.framework.FrameworkEvent)6 Version (org.osgi.framework.Version)6 HashMap (java.util.HashMap)5 ComponentContext (org.osgi.service.component.ComponentContext)5 InputStream (java.io.InputStream)4 BundleStartLevel (org.osgi.framework.startlevel.BundleStartLevel)4 PatchManagement (io.fabric8.patch.management.PatchManagement)3 GitPatchManagementServiceImpl (io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)3 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)3 FileInputStream (java.io.FileInputStream)3