use of org.osgi.framework.startlevel.FrameworkStartLevel in project karaf by apache.
the class BundleInstallSupportImpl method getInfo.
@Override
public FrameworkInfo getInfo() {
FrameworkInfo info = new FrameworkInfo();
info.ourBundle = ourBundle;
FrameworkStartLevel fsl = systemBundleContext.getBundle().adapt(FrameworkStartLevel.class);
info.initialBundleStartLevel = fsl.getInitialBundleStartLevel();
info.currentStartLevel = fsl.getStartLevel();
info.bundles = new HashMap<>();
for (Bundle bundle : systemBundleContext.getBundles()) {
info.bundles.put(bundle.getBundleId(), bundle);
}
info.systemBundle = info.bundles.get(0);
return info;
}
use of org.osgi.framework.startlevel.FrameworkStartLevel in project aries by apache.
the class StartAction method startBundleResource.
private void startBundleResource(Resource resource, Coordination coordination) throws BundleException {
if (target.isRoot())
// root region.
return;
if (Utils.isRegionContextBundle(resource))
// The region context bundle was persistently started elsewhere.
return;
final Bundle bundle = ((BundleRevision) resource).getBundle();
if ((bundle.getState() & (Bundle.STARTING | Bundle.ACTIVE)) != 0)
return;
if (logger.isDebugEnabled()) {
int bundleStartLevel = bundle.adapt(BundleStartLevel.class).getStartLevel();
Bundle systemBundle = Activator.getInstance().getBundleContext().getBundle(0);
int fwStartLevel = systemBundle.adapt(FrameworkStartLevel.class).getStartLevel();
logger.debug("StartAction: starting bundle " + bundle.getSymbolicName() + " " + bundle.getVersion().toString() + " bundleStartLevel=" + bundleStartLevel + " frameworkStartLevel=" + fwStartLevel);
}
bundle.start(Bundle.START_TRANSIENT | Bundle.START_ACTIVATION_POLICY);
if (logger.isDebugEnabled()) {
logger.debug("StartAction: bundle " + bundle.getSymbolicName() + " " + bundle.getVersion().toString() + " started correctly");
}
if (coordination == null)
return;
coordination.addParticipant(new Participant() {
public void ended(Coordination coordination) throws Exception {
// noop
}
public void failed(Coordination coordination) throws Exception {
bundle.stop();
}
});
}
use of org.osgi.framework.startlevel.FrameworkStartLevel in project karaf by apache.
the class Main method launch.
public void launch() throws Exception {
if (config == null) {
config = new ConfigProperties();
}
config.performInit();
if (config.delayConsoleStart) {
System.out.println(config.startupMessage);
}
String log4jConfigPath = System.getProperty("karaf.etc") + "/org.ops4j.pax.logging.cfg";
BootstrapLogManager.setProperties(config.props, log4jConfigPath);
lockCallback = new KarafLockCallback();
InstanceHelper.updateInstancePid(config.karafHome, config.karafBase, true);
BootstrapLogManager.configureLogger(LOG);
for (String provider : config.securityProviders) {
addSecurityProvider(provider);
}
List<File> bundleDirs = getBundleRepos();
ArtifactResolver resolver = new SimpleMavenResolver(bundleDirs);
// Start up the OSGI framework
ClassLoader classLoader = createClassLoader(resolver);
FrameworkFactory factory = loadFrameworkFactory(classLoader);
framework = factory.newFramework(config.props);
setLogger();
framework.init();
framework.getBundleContext().addFrameworkListener(lockCallback);
framework.start();
FrameworkStartLevel sl = framework.adapt(FrameworkStartLevel.class);
sl.setInitialBundleStartLevel(config.defaultBundleStartlevel);
// If we have a clean state, install everything
if (framework.getBundleContext().getBundles().length == 1) {
LOG.info("Installing and starting initial bundles");
File startupPropsFile = new File(config.karafEtc, STARTUP_PROPERTIES_FILE_NAME);
List<BundleInfo> bundles = readBundlesFromStartupProperties(startupPropsFile);
installAndStartBundles(resolver, framework.getBundleContext(), bundles);
LOG.info("All initial bundles installed and set to start");
}
ServerInfo serverInfo = new ServerInfoImpl(args, config);
framework.getBundleContext().registerService(ServerInfo.class, serverInfo, null);
activatorManager = new KarafActivatorManager(classLoader, framework);
activatorManager.startKarafActivators();
setStartLevel(config.lockStartLevel);
// Progress bar
if (config.delayConsoleStart) {
new StartupListener(LOG, framework.getBundleContext());
}
monitor();
registerSignalHandler();
watchdog();
}
use of org.osgi.framework.startlevel.FrameworkStartLevel in project karaf by apache.
the class MainLockingTest method testLostMasterLock.
@Test
public void testLostMasterLock() throws Exception {
File basedir = new File(getClass().getClassLoader().getResource("foo").getPath()).getParentFile();
File home = new File(basedir, "test-karaf-home");
File data = new File(home, "data");
Utils.deleteDirectory(data);
String[] args = new String[0];
System.setProperty("karaf.home", home.toString());
System.setProperty("karaf.data", data.toString());
System.setProperty("karaf.framework.factory", "org.apache.felix.framework.FrameworkFactory");
System.setProperty("karaf.lock", "true");
System.setProperty("karaf.lock.delay", "1000");
System.setProperty("karaf.lock.class", "org.apache.karaf.main.MockLock");
Main main = new Main(args);
main.launch();
Framework framework = main.getFramework();
String activatorName = TimeoutShutdownActivator.class.getName().replace('.', '/') + ".class";
Bundle bundle = framework.getBundleContext().installBundle("foo", TinyBundles.bundle().set(Constants.BUNDLE_ACTIVATOR, TimeoutShutdownActivator.class.getName()).add(activatorName, getClass().getClassLoader().getResourceAsStream(activatorName)).build(withBnd()));
bundle.start();
FrameworkStartLevel sl = framework.adapt(FrameworkStartLevel.class);
MockLock lock = (MockLock) main.getLock();
Assert.assertEquals(100, sl.getStartLevel());
// simulate losing a lock
lock.setIsAlive(false);
lock.setLock(false);
// lets wait until the start level change is complete
lock.waitForLock();
Assert.assertEquals(1, sl.getStartLevel());
Thread.sleep(1000);
// get lock back
lock.setIsAlive(true);
lock.setLock(true);
Thread.sleep(1000);
// exit framework + lock loop
main.destroy();
}
use of org.osgi.framework.startlevel.FrameworkStartLevel in project karaf by apache.
the class List method doExecute.
@Override
protected Object doExecute(java.util.List<Bundle> bundles) throws Exception {
if (noFormat) {
noEllipsis = true;
}
determineBundleLevelThreshold();
// Display active start level.
FrameworkStartLevel fsl = this.bundleContext.getBundle(0).adapt(FrameworkStartLevel.class);
if (fsl != null) {
System.out.println("START LEVEL " + fsl.getStartLevel() + " , List Threshold: " + bundleLevelThreshold);
}
ShellTable table = new ShellTable();
if (!noEllipsis && terminal != null && terminal.getWidth() > 0) {
table.size(terminal.getWidth());
}
table.column("ID").alignRight();
table.column("State");
table.column("Lvl").alignRight();
table.column("Version");
boolean effectiveShowName = showName || (!showLocation && !showSymbolic && !showUpdate && !showRevisions);
if (effectiveShowName) {
table.column("Name");
}
if (showLocation) {
table.column(new Col("Location") {
@Override
protected String cut(String value, int size) {
if (showLocation && value.length() > size) {
String[] parts = value.split("/");
String cut = "";
int c = parts[0].length() + 4;
for (int idx = parts.length - 1; idx > 0; idx--) {
if (cut.length() + c + parts[idx].length() + 1 < size) {
cut = "/" + parts[idx] + cut;
} else {
break;
}
}
cut = parts[0] + "/..." + cut;
return cut;
} else {
return super.cut(value, size);
}
}
});
}
if (showSymbolic) {
table.column("Symbolic name");
}
if (showUpdate) {
table.column("Update location");
}
if (showRevisions) {
table.column("Revisions");
}
for (Bundle bundle : bundles) {
BundleInfo info = this.bundleService.getInfo(bundle);
if (info.getStartLevel() >= bundleLevelThreshold) {
String version = info.getVersion();
ArrayList<Object> rowData = new ArrayList<>();
rowData.add(info.getBundleId());
rowData.add(getStateString(info.getState()));
rowData.add(info.getStartLevel());
rowData.add(version);
if (effectiveShowName) {
String bundleName = (info.getName() == null) ? info.getSymbolicName() : info.getName();
bundleName = (bundleName == null) ? info.getUpdateLocation() : bundleName;
String name = bundleName + printFragments(info) + printHosts(info);
rowData.add(name);
}
if (showLocation) {
rowData.add(info.getUpdateLocation());
}
if (showSymbolic) {
rowData.add(info.getSymbolicName() == null ? "<no symbolic name>" : info.getSymbolicName());
}
if (showUpdate) {
rowData.add(info.getUpdateLocation());
}
if (showRevisions) {
rowData.add(info.getRevisions());
}
Row row = table.addRow();
row.addContent(rowData);
}
}
table.print(System.out, !noFormat);
return null;
}
Aggregations