Search in sources :

Example 21 with FrameworkWiring

use of org.osgi.framework.wiring.FrameworkWiring in project bnd by bndtools.

the class EmbeddedActivator method refresh.

/*
	 * Refresh the stopped bundles
	 */
void refresh(BundleContext context, List<Bundle> toStop) throws InterruptedException {
    Bundle bundle = context.getBundle(0);
    FrameworkWiring framework = bundle.adapt(FrameworkWiring.class);
    final Semaphore s = new Semaphore(0);
    framework.refreshBundles(toStop, new FrameworkListener() {

        @Override
        public void frameworkEvent(FrameworkEvent event) {
            s.release();
        }
    });
    s.tryAcquire(10, TimeUnit.SECONDS);
}
Also used : FrameworkEvent(org.osgi.framework.FrameworkEvent) Bundle(org.osgi.framework.Bundle) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) Semaphore(java.util.concurrent.Semaphore) FrameworkListener(org.osgi.framework.FrameworkListener)

Example 22 with FrameworkWiring

use of org.osgi.framework.wiring.FrameworkWiring in project rt.equinox.framework by eclipse.

the class EclipseStarter method refreshPackages.

// returns true if the refreshPackages operation caused the framework to shutdown
private static boolean refreshPackages(Bundle[] bundles) throws InterruptedException {
    FrameworkWiring frameworkWiring = context.getBundle().adapt(FrameworkWiring.class);
    if (frameworkWiring == null)
        return false;
    Semaphore semaphore = new Semaphore(0);
    StartupEventListener listener = new StartupEventListener(semaphore, FrameworkEvent.PACKAGES_REFRESHED);
    context.addBundleListener(listener);
    frameworkWiring.refreshBundles(Arrays.asList(bundles), listener);
    updateSplash(semaphore, listener);
    return isForcedRestart();
}
Also used : FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) Semaphore(java.util.concurrent.Semaphore)

Example 23 with FrameworkWiring

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

the class BundlesMBeanImpl method update.

public void update(String bundleId, String location, boolean refresh) throws MBeanException {
    try {
        List<Bundle> bundles = selectBundles(bundleId);
        if (location == null) {
            for (Bundle bundle : bundles) {
                bundle.update();
            }
            return;
        }
        if (bundles.size() != 1) {
            throw new IllegalArgumentException("Provided bundle Id doesn't return any bundle or more than one bundle selected");
        }
        InputStream is = new URL(location).openStream();
        bundles.get(0).update(is);
        if (refresh) {
            FrameworkWiring wiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
            wiring.refreshBundles(null);
        }
    } catch (Exception e) {
        throw new MBeanException(null, e.toString());
    }
}
Also used : Bundle(org.osgi.framework.Bundle) InputStream(java.io.InputStream) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) URL(java.net.URL) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException)

Example 24 with FrameworkWiring

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

the class Update method doExecute.

protected Object doExecute(Bundle bundle) throws Exception {
    if (location != null) {
        update(bundle, location.toURL());
    } else {
        String loc = bundle.getHeaders().get(Constants.BUNDLE_UPDATELOCATION);
        if (loc != null && !loc.equals(bundle.getLocation())) {
            update(bundle, new URL(loc));
        } else {
            bundle.update();
        }
    }
    if (refresh) {
        FrameworkWiring wiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
        wiring.refreshBundles(null);
    }
    return null;
}
Also used : FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) URL(java.net.URL)

Example 25 with FrameworkWiring

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

the class BundleInstallSupportImpl method refreshPackages.

@Override
public void refreshPackages(Collection<Bundle> bundles) throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    FrameworkWiring fw = systemBundleContext.getBundle().adapt(FrameworkWiring.class);
    fw.refreshBundles(bundles, (FrameworkListener) event -> {
        if (event.getType() == FrameworkEvent.ERROR) {
            LOGGER.error("Framework error", event.getThrowable());
        }
        latch.countDown();
    });
    latch.await();
}
Also used : DigraphHelper(org.apache.karaf.features.internal.region.DigraphHelper) ResolverHookFactory(org.osgi.framework.hooks.resolver.ResolverHookFactory) Region(org.eclipse.equinox.region.Region) RegionFilterBuilder(org.eclipse.equinox.region.RegionFilterBuilder) ExecutionEnvironmentNamespace(org.osgi.framework.namespace.ExecutionEnvironmentNamespace) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) FeaturesService(org.apache.karaf.features.FeaturesService) FrameworkListener(org.osgi.framework.FrameworkListener) HashSet(java.util.HashSet) BundleCapability(org.osgi.framework.wiring.BundleCapability) Map(java.util.Map) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleException(org.osgi.framework.BundleException) ServiceRegistration(org.osgi.framework.ServiceRegistration) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Resource(org.osgi.resource.Resource) Collection(java.util.Collection) FrameworkStartLevel(org.osgi.framework.startlevel.FrameworkStartLevel) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Feature(org.apache.karaf.features.Feature) FrameworkEvent(org.osgi.framework.FrameworkEvent) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) Set(java.util.Set) IOException(java.io.IOException) ResolverHook(org.osgi.framework.hooks.resolver.ResolverHook) FileInputStream(java.io.FileInputStream) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) RegionDigraph(org.eclipse.equinox.region.RegionDigraph) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) Wire(org.osgi.resource.Wire) BundleUtils(org.apache.karaf.util.bundles.BundleUtils) HostNamespace(org.osgi.framework.namespace.HostNamespace) InputStream(java.io.InputStream) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) CountDownLatch(java.util.concurrent.CountDownLatch)

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