Search in sources :

Example 11 with PackageAdmin

use of org.osgi.service.packageadmin.PackageAdmin in project jetty.project by eclipse.

the class PackageAdminServiceTracker method getFragmentsAndRequiredBundles.

/**
     * Returns the fragments and the required-bundles of a bundle. Recursively
     * collect the required-bundles and fragment when the directive
     * visibility:=reexport is added to a required-bundle.
     * 
     * @param bundle the bundle
     * @return the bundle fragment and required list
     */
public Bundle[] getFragmentsAndRequiredBundles(Bundle bundle) {
    ServiceReference sr = _context.getServiceReference(PackageAdmin.class.getName());
    if (sr == null) {
        // we should never be here really.
        return null;
    }
    PackageAdmin admin = (PackageAdmin) _context.getService(sr);
    LinkedHashMap<String, Bundle> deps = new LinkedHashMap<String, Bundle>();
    collectFragmentsAndRequiredBundles(bundle, admin, deps, false);
    return deps.values().toArray(new Bundle[deps.size()]);
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) Bundle(org.osgi.framework.Bundle) ServiceReference(org.osgi.framework.ServiceReference) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with PackageAdmin

use of org.osgi.service.packageadmin.PackageAdmin in project aries by apache.

the class BundleFrameworkImpl method isFragment.

/**
   * This method uses the PackageAdmin service to identify if a bundle
   * is a fragment.
   * @param b
   * @return
   */
private boolean isFragment(Bundle b) {
    LOGGER.debug(LOG_ENTRY, "isFragment", new Object[] { b });
    PackageAdmin admin = null;
    boolean isFragment = false;
    try {
        if (_packageAdminTracker != null) {
            admin = (PackageAdmin) _packageAdminTracker.getService();
            if (admin != null) {
                isFragment = (admin.getBundleType(b) == PackageAdmin.BUNDLE_TYPE_FRAGMENT);
            }
        }
    } catch (RuntimeException re) {
        LOGGER.debug(LOG_EXCEPTION, re);
    }
    LOGGER.debug(LOG_EXIT, "isFragment", new Object[] { Boolean.valueOf(isFragment) });
    return isFragment;
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin)

Example 13 with PackageAdmin

use of org.osgi.service.packageadmin.PackageAdmin 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 14 with PackageAdmin

use of org.osgi.service.packageadmin.PackageAdmin in project aries by apache.

the class FrameworkMBeanHandler method open.

/**
     * @see org.apache.aries.jmx.MBeanHandler#open()
     */
public void open() {
    ServiceReference adminRef = context.getServiceReference(PackageAdmin.class.getCanonicalName());
    PackageAdmin packageAdmin = (PackageAdmin) context.getService(adminRef);
    ServiceReference startLevelRef = context.getServiceReference(StartLevel.class.getCanonicalName());
    StartLevel startLevel = (StartLevel) context.getService(startLevelRef);
    FrameworkMBean framework = new Framework(context, startLevel, packageAdmin);
    try {
        mbean = new StandardMBean(framework, FrameworkMBean.class);
    } catch (NotCompliantMBeanException e) {
        logger.log(LogService.LOG_ERROR, "Not compliant MBean", e);
    }
    agentContext.registerMBean(this);
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) StartLevel(org.osgi.service.startlevel.StartLevel) FrameworkMBean(org.osgi.jmx.framework.FrameworkMBean) ServiceReference(org.osgi.framework.ServiceReference)

Example 15 with PackageAdmin

use of org.osgi.service.packageadmin.PackageAdmin in project aries by apache.

the class BundleStateMBeanHandler method open.

/**
     * @see org.apache.aries.jmx.MBeanHandler#open()
     */
public void open() {
    packageAdminRef = bundleContext.getServiceReference(PackageAdmin.class.getName());
    PackageAdmin packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminRef);
    startLevelRef = bundleContext.getServiceReference(StartLevel.class.getName());
    StartLevel startLevel = (StartLevel) bundleContext.getService(startLevelRef);
    bundleStateMBean = new BundleState(bundleContext, packageAdmin, startLevel, stateConfig, logger);
    try {
        mbean = new RegistrableStandardEmitterMBean(bundleStateMBean, BundleStateMBean.class);
    } catch (NotCompliantMBeanException e) {
        logger.log(LogService.LOG_ERROR, "Failed to instantiate MBean for " + BundleStateMBean.class.getName(), e);
    }
    agentContext.registerMBean(this);
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) RegistrableStandardEmitterMBean(org.apache.aries.jmx.util.shared.RegistrableStandardEmitterMBean) StartLevel(org.osgi.service.startlevel.StartLevel) BundleStateMBean(org.osgi.jmx.framework.BundleStateMBean)

Aggregations

PackageAdmin (org.osgi.service.packageadmin.PackageAdmin)27 Bundle (org.osgi.framework.Bundle)17 BundleContext (org.osgi.framework.BundleContext)13 ServiceReference (org.osgi.framework.ServiceReference)12 Test (org.junit.Test)11 ExportedPackage (org.osgi.service.packageadmin.ExportedPackage)7 RequiredBundle (org.osgi.service.packageadmin.RequiredBundle)6 StartLevel (org.osgi.service.startlevel.StartLevel)6 FrameworkUtils.getServicesInUseByBundle (org.apache.aries.jmx.util.FrameworkUtils.getServicesInUseByBundle)5 ArrayList (java.util.ArrayList)4 Version (org.osgi.framework.Version)4 IOException (java.io.IOException)3 Hashtable (java.util.Hashtable)3 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)3 Logger (org.apache.aries.jmx.Logger)3 Expectations (org.jmock.Expectations)3 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)3 File (java.io.File)2 ExecutorService (java.util.concurrent.ExecutorService)2 MBeanServer (javax.management.MBeanServer)2