use of org.osgi.framework.wiring.FrameworkWiring in project karaf by apache.
the class BundleWatcherImpl method run.
public void run() {
logger.debug("Bundle watcher thread started");
int oldCounter = -1;
Set<Bundle> watchedBundles = new HashSet<>();
while (running.get() && watchURLs.size() > 0) {
if (oldCounter != counter.get()) {
oldCounter = counter.get();
watchedBundles.clear();
for (String bundleURL : watchURLs) {
// Transform into regexp
bundleURL = bundleURL.replaceAll("\\*", ".*");
for (Bundle bundle : bundleService.selectBundles(Collections.singletonList(bundleURL), false)) {
if (isMavenSnapshotUrl(getLocation(bundle))) {
watchedBundles.add(bundle);
}
}
}
}
if (watchedBundles.size() > 0) {
// Get the wiring before any in case of a refresh of a dependency
FrameworkWiring wiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
File localRepository = this.localRepoDetector.getLocalRepository();
List<Bundle> updated = new ArrayList<>();
for (Bundle bundle : watchedBundles) {
try {
updateBundleIfNecessary(localRepository, updated, bundle);
} catch (IOException ex) {
logger.error("Error watching bundle.", ex);
} catch (BundleException ex) {
logger.error("Error updating bundle.", ex);
}
}
if (!updated.isEmpty()) {
try {
final CountDownLatch latch = new CountDownLatch(1);
wiring.refreshBundles(updated, (FrameworkListener) event -> latch.countDown());
latch.await();
} catch (InterruptedException e) {
running.set(false);
}
for (Bundle bundle : updated) {
try {
if (bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null) {
logger.info("[Watch] Bundle {} is a fragment, so it's not started", bundle.getSymbolicName());
} else {
bundle.start(Bundle.START_TRANSIENT);
}
} catch (BundleException ex) {
logger.warn("[Watch] Error starting bundle", ex);
}
}
}
}
try {
Thread.sleep(interval);
} catch (InterruptedException ex) {
running.set(false);
}
}
if (logger.isDebugEnabled()) {
logger.debug("Bundle watcher thread stopped");
}
}
use of org.osgi.framework.wiring.FrameworkWiring in project karaf by apache.
the class Resolve method doExecute.
protected Object doExecute(List<Bundle> bundles) throws Exception {
FrameworkWiring wiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
wiring.resolveBundles(bundles == null || bundles.isEmpty() ? null : bundles);
return null;
}
use of org.osgi.framework.wiring.FrameworkWiring in project karaf by apache.
the class Refresh method doExecute.
protected Object doExecute(List<Bundle> bundles) throws Exception {
FrameworkWiring wiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
if (bundles == null || bundles.isEmpty()) {
bundles = null;
}
wiring.refreshBundles(bundles);
return null;
}
use of org.osgi.framework.wiring.FrameworkWiring in project felix by apache.
the class FileInstall method refresh.
/**
* Convenience to refresh the packages
*/
static void refresh(Bundle systemBundle, Collection<Bundle> bundles) throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
FrameworkWiring wiring = systemBundle.adapt(FrameworkWiring.class);
wiring.refreshBundles(bundles, new FrameworkListener() {
public void frameworkEvent(FrameworkEvent event) {
latch.countDown();
}
});
latch.await();
}
use of org.osgi.framework.wiring.FrameworkWiring in project felix by apache.
the class BaseIntegrationTest method resolveBundles.
protected boolean resolveBundles(Bundle... bundles) throws Exception {
Bundle systemBundle = m_context.getBundle(0L);
FrameworkWiring frameworkWiring = systemBundle.adapt(FrameworkWiring.class);
frameworkWiring.resolveBundles(Arrays.asList(bundles));
for (Bundle bundle : bundles) {
if ((bundle.getState() & Bundle.RESOLVED) == 0) {
return false;
}
}
return true;
}
Aggregations