use of org.osgi.framework.BundleException in project camel by apache.
the class BlueprintPropertiesTest method testProperties.
@Test
public void testProperties() throws Exception {
Bundle camelCore = getBundleBySymbolicName("org.apache.camel.camel-core");
Bundle test = getBundleBySymbolicName(getClass().getSimpleName());
camelCore.stop();
test.stop();
Thread.sleep(500);
test.start();
try {
getOsgiService(BlueprintContainer.class, "(osgi.blueprint.container.symbolicname=" + getClass().getSimpleName() + ")", 500);
fail("Expected a timeout");
} catch (RuntimeException e) {
// Expected timeout
}
CamelBlueprintHelper.waitForBlueprintContainer(null, test.getBundleContext(), getClass().getSimpleName(), BlueprintEvent.CREATED, new Runnable() {
@Override
public void run() {
try {
camelCore.start();
} catch (BundleException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
});
getOsgiService(BlueprintContainer.class, "(osgi.blueprint.container.symbolicname=" + getClass().getSimpleName() + ")", 500);
}
use of org.osgi.framework.BundleException in project jersey by jersey.
the class AbstractHttpServiceTest method defaultHttpServiceTestMethod.
public void defaultHttpServiceTestMethod() throws Exception {
// log the list of bundles and result of the attempt to start
StringBuilder sb = new StringBuilder();
sb.append("-- Bundle list -- \n");
for (Bundle b : bundleContext.getBundles()) {
sb.append(String.format("%1$5s", "[" + b.getBundleId() + "]")).append(" ").append(String.format("%1$-70s", b.getSymbolicName())).append(" | ").append(String.format("%1$-20s", b.getVersion())).append(" |");
try {
b.start();
sb.append(" STARTED | ");
} catch (BundleException e) {
sb.append(" *FAILED* | ").append(e.getMessage());
}
sb.append(b.getLocation()).append("\n");
}
sb.append("-- \n\n");
LOGGER.fine(sb.toString());
// start the example bundle
bundleContext.installBundle(AccessController.doPrivileged(PropertiesHelper.getSystemProperty(BundleLocationProperty))).start();
LOGGER.fine("Waiting for jersey/test/DEPLOYED event with timeout " + MAX_WAITING_SECONDS + " seconds...");
if (!countDownLatch.await(MAX_WAITING_SECONDS, TimeUnit.SECONDS)) {
throw new TimeoutException("The event jersey/test/DEPLOYED did not arrive in " + MAX_WAITING_SECONDS + " seconds. Waiting timed out.");
}
Client c = ClientBuilder.newClient();
final WebTarget target = c.target(baseUri);
String result = target.path("/status").request().build("GET").invoke().readEntity(String.class);
LOGGER.info("JERSEY RESULT = " + result);
assertEquals("active", result);
}
use of org.osgi.framework.BundleException in project eclipse.themes.darker by jinmingjian.
the class DarkerThemer method hookDarkerCore.
private void hookDarkerCore() {
Bundle bundle = FrameworkUtil.getBundle(DarkerWeavingHook.class);
try {
if (bundle.getState() == Bundle.RESOLVED)
bundle.start();
} catch (BundleException e) {
// TODO use log in future
e.printStackTrace();
}
bundle.adapt(BundleStartLevel.class).setStartLevel(1);
}
use of org.osgi.framework.BundleException in project atlas by alibaba.
the class FrameworkLifecycleHandler method started.
private void started() {
RuntimeVariables.androidApplication.registerActivityLifecycleCallbacks(new ActivityLifeCycleObserver());
RuntimeVariables.androidApplication.registerComponentCallbacks(new ComponentCallbacks() {
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (RuntimeVariables.delegateResources != null) {
RuntimeVariables.delegateResources.updateConfiguration(newConfig, RuntimeVariables.delegateResources.getDisplayMetrics());
}
}
@Override
public void onLowMemory() {
}
});
if (RuntimeVariables.getProcessName(RuntimeVariables.androidApplication).equals(RuntimeVariables.androidApplication.getPackageName())) {
String autoStartBundle = (String) RuntimeVariables.getFrameworkProperty("autoStartBundles");
if (autoStartBundle != null) {
String[] bundles = autoStartBundle.split(",");
if (bundles.length > 0) {
for (int x = 0; x < bundles.length; x++) {
final String bundleName = bundles[0];
BundleImpl impl = (BundleImpl) Atlas.getInstance().getBundle(bundleName);
if (impl == null) {
BundleInstaller.startDelayInstall(bundleName, new BundleInstaller.InstallListener() {
@Override
public void onFinished() {
BundleImpl impl = (BundleImpl) Atlas.getInstance().getBundle(bundleName);
if (impl != null) {
try {
impl.start();
} catch (BundleException e) {
e.printStackTrace();
}
}
}
});
} else {
try {
impl.start();
} catch (BundleException e) {
e.printStackTrace();
}
}
}
}
}
}
}
use of org.osgi.framework.BundleException in project atlas by alibaba.
the class Framework method installOrUpdate.
static void installOrUpdate(final String[] locations, final File[] files, String[] newBundleVersions, long dexPatchVersion) throws BundleException {
if (locations == null || files == null || locations.length != files.length) {
throw new IllegalArgumentException("locations and files must not be null and must be same length");
}
String writeAhead = String.valueOf(System.currentTimeMillis());
File walsDir = new File(STORAGE_LOCATION, "wal");
File walDir = new File(walsDir, writeAhead);
walDir.mkdirs();
for (int i = 0; i < locations.length; i++) {
if (locations[i] == null || files[i] == null) {
continue;
}
File bundleDir = null;
try {
BundleLock.WriteLock(locations[i]);
if (isKernalBundle(locations[i])) {
KernalBundle bundle = KernalBundle.kernalBundle;
if (bundle != null) {
bundle.update(files[i], Framework.containerVersion, dexPatchVersion);
} else {
bundleDir = new File(STORAGE_LOCATION, KernalBundle.KERNAL_BUNDLE_NAME);
if (!bundleDir.exists()) {
bundleDir.mkdirs();
}
AtlasFileLock.getInstance().LockExclusive(bundleDir);
KernalBundle b = new KernalBundle(bundleDir, files[i], Framework.containerVersion, dexPatchVersion);
if (b != null) {
FileUtils.createNewDirIfNotExist(b.getArchive().getRevisionDir(), UPDATED_MARK);
}
}
} else {
Bundle bundle = Framework.getBundle(locations[i]);
if (bundle != null) {
bundle.update(files[i], newBundleVersions[i], dexPatchVersion);
} else {
if (dexPatchVersion > 0) {
bundleDir = new File(STORAGE_LOCATION, locations[i]);
} else {
bundleDir = new File(walDir, locations[i]);
}
if (!bundleDir.exists()) {
bundleDir.mkdirs();
}
// Hold the storage file lock
AtlasFileLock.getInstance().LockExclusive(bundleDir);
BundleImpl b = new BundleImpl(bundleDir, locations[i], new BundleContext(), null, files[i], newBundleVersions[i], false, dexPatchVersion);
if (b != null) {
FileUtils.createNewDirIfNotExist(b.archive.getCurrentRevision().getRevisionDir(), UPDATED_MARK);
}
}
}
} catch (Exception e) {
AtlasMonitor.getInstance().trace(AtlasMonitor.BUNDLE_INSTALL_FAIL, locations[i], AtlasMonitor.UPDATE_FAILED_MSG, FileUtils.getDataAvailableSpace());
/**
* bundle 安装需要支持事务,失败时回滚已部署的bundle
*/
for (int x = 0; x <= i; x++) {
if (isKernalBundle(locations[x])) {
if (KernalBundle.kernalBundle != null) {
try {
KernalBundle.downgradeRevision(new File(STORAGE_LOCATION, KernalBundle.KERNAL_BUNDLE_NAME), true);
} catch (IOException e2) {
}
} else {
deleteDirectory(new File(STORAGE_LOCATION, KernalBundle.KERNAL_BUNDLE_NAME));
}
} else {
try {
BundleArchive.downgradeRevision(locations[x], new File(STORAGE_LOCATION, locations[x]), true);
} catch (IOException e1) {
e1.printStackTrace();
}
deleteDirectory(walDir);
if (walDir.exists()) {
try {
new File(walDir, DEPRECATED_MARK).createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
throw new BundleException("failed to installOrUpdate bundles ", e);
} finally {
if (bundleDir != null) {
AtlasFileLock.getInstance().unLock(bundleDir);
}
BundleLock.WriteUnLock(locations[i]);
}
}
bundleUpdated = true;
WrapperUtil.appendLog("installedVersionWhenUpdated", Framework.containerVersion);
WrapperUtil.appendLog("VersionWhenUpdated", WrapperUtil.getPackageInfo(RuntimeVariables.androidApplication).versionName);
writeAheads.add(writeAhead);
InstrumentationHook.notifyAppUpdated();
storeMetadata();
}
Aggregations