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()]);
}
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;
}
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();
}
}
}
}
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);
}
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);
}
Aggregations