use of org.osgi.framework.FrameworkListener 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);
}
use of org.osgi.framework.FrameworkListener in project bnd by bndtools.
the class AgentDispatcher method createFramework.
/**
* Create a new framework. This is reflectively called from the Envoy
*/
public static Descriptor createFramework(String name, Map<String, Object> configuration, final File storage, final File shacache) throws Exception {
//
// Use the service loader for loading a framework
//
ClassLoader loader = AgentServer.class.getClassLoader();
ServiceLoader<FrameworkFactory> sl = ServiceLoader.load(FrameworkFactory.class, loader);
FrameworkFactory ff = null;
for (FrameworkFactory fff : sl) {
ff = fff;
// break;
}
if (ff == null)
throw new IllegalArgumentException("No framework on runpath");
//
// Create the framework
//
@SuppressWarnings({ "unchecked", "rawtypes" }) Framework framework = ff.newFramework((Map) configuration);
framework.init();
framework.getBundleContext().addFrameworkListener(new FrameworkListener() {
@Override
public void frameworkEvent(FrameworkEvent event) {
// System.err.println("FW Event " + event);
}
});
framework.start();
Descriptor d = new Descriptor();
//
// create a new descriptor. This is returned
// to the envoy side as an Object and we will
// get this back later in toAgent. The envoy
// maintains a list of name -> framework
//
d.framework = framework;
d.shaCache = shacache;
d.storage = storage;
d.configuration = configuration;
d.name = name;
String embedded = (String) configuration.get("biz.aQute.remote.embedded");
if (embedded != null && !(embedded = embedded.trim()).isEmpty()) {
String[] activators = embedded.trim().split("\\s*,\\s*");
for (String activator : activators) try {
Class<?> activatorClass = loader.loadClass(activator);
if (BundleActivator.class.isAssignableFrom(activatorClass)) {
// TODO check immediate
BundleActivator ba = (BundleActivator) activatorClass.getConstructor().newInstance();
ba.start(framework.getBundleContext());
d.activators.add(ba);
}
} catch (Exception e) {
// TODO
System.out.println("IGNORED");
e.printStackTrace();
}
}
return d;
}
Aggregations