Search in sources :

Example 6 with BundleFramework

use of org.apache.aries.application.management.spi.framework.BundleFramework in project aries by apache.

the class BundleFrameworkManagerImpl method uninstallBundle.

public void uninstallBundle(Bundle b) throws BundleException {
    synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
        BundleFramework framework = getBundleFramework(b);
        if (framework != null) {
            for (Bundle bundle : new ArrayList<Bundle>(framework.getBundles())) {
                framework.uninstall(bundle);
            }
            BundleContext ctx = framework.getIsolatedBundleContext();
            ServiceReference ref = ctx.getServiceReference(PackageAdmin.class.getName());
            if (ref != null) {
                try {
                    PackageAdmin pa = (PackageAdmin) ctx.getService(ref);
                    if (pa != null) {
                        final Semaphore sem = new Semaphore(0);
                        FrameworkListener listener = new FrameworkListener() {

                            public void frameworkEvent(FrameworkEvent event) {
                                if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) {
                                    sem.release();
                                }
                            }
                        };
                        ctx.addFrameworkListener(listener);
                        pa.refreshPackages(null);
                        try {
                            sem.tryAcquire(60, TimeUnit.SECONDS);
                        } catch (InterruptedException ie) {
                        }
                        ctx.removeFrameworkListener(listener);
                    }
                } finally {
                    ctx.ungetService(ref);
                }
            }
            framework.close();
            // clean up our maps so we don't leak memory
            _frameworks.remove(b);
            Iterator<BundleFramework> it = _frameworksByAppScope.values().iterator();
            while (it.hasNext()) {
                if (it.next().equals(framework))
                    it.remove();
            }
        }
    }
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) FrameworkEvent(org.osgi.framework.FrameworkEvent) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) BundleFramework(org.apache.aries.application.management.spi.framework.BundleFramework) Semaphore(java.util.concurrent.Semaphore) FrameworkListener(org.osgi.framework.FrameworkListener) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference)

Example 7 with BundleFramework

use of org.apache.aries.application.management.spi.framework.BundleFramework in project aries by apache.

the class BundleFrameworkFactoryImpl method createBundleFramework.

public BundleFramework createBundleFramework(BundleContext bc, BundleFrameworkConfiguration config) throws BundleException {
    BundleFramework framework = null;
    ServiceReference sr = bc.getServiceReference(CompositeBundleFactory.class.getName());
    if (sr != null) {
        CompositeBundleFactory cbf = (CompositeBundleFactory) bc.getService(sr);
        CompositeBundle compositeBundle = cbf.installCompositeBundle(config.getFrameworkProperties(), config.getFrameworkID(), config.getFrameworkManifest());
        framework = new BundleFrameworkImpl(compositeBundle);
    } else
        throw new BundleException("Failed to obtain framework factory service");
    return framework;
}
Also used : BundleFramework(org.apache.aries.application.management.spi.framework.BundleFramework) BundleException(org.osgi.framework.BundleException) CompositeBundleFactory(org.osgi.service.framework.CompositeBundleFactory) CompositeBundle(org.osgi.service.framework.CompositeBundle) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

BundleFramework (org.apache.aries.application.management.spi.framework.BundleFramework)7 Bundle (org.osgi.framework.Bundle)4 BundleException (org.osgi.framework.BundleException)4 AriesApplication (org.apache.aries.application.management.AriesApplication)3 BundleContext (org.osgi.framework.BundleContext)3 DeploymentContent (org.apache.aries.application.DeploymentContent)2 BundleFrameworkConfiguration (org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration)2 BundleSuggestion (org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion)2 ServiceReference (org.osgi.framework.ServiceReference)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 Semaphore (java.util.concurrent.Semaphore)1 Attributes (java.util.jar.Attributes)1 Content (org.apache.aries.application.Content)1 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)1