Java Code Examples for org.osgi.framework.startlevel.FrameworkStartLevel#setStartLevel()

The following examples show how to use org.osgi.framework.startlevel.FrameworkStartLevel#setStartLevel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FrameworkStartLevelResource.java    From concierge with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Representation put(final Representation r,
		final Variant variant) {
	try {
		final FrameworkStartLevelPojo sl = fromRepresentation(r, r.getMediaType());
		final FrameworkStartLevel fsl = getFrameworkStartLevel();

		if (sl.getStartLevel() != 0) {
			fsl.setStartLevel(sl.getStartLevel());
		}
		if (sl.getInitialBundleStartLevel() != 0) {
			fsl.setInitialBundleStartLevel(sl.getInitialBundleStartLevel());
		}

		return SUCCESS(Status.SUCCESS_NO_CONTENT);
	} catch (final Exception e) {
		return ERROR(e, variant);
	}
}
 
Example 2
Source File: FrameworkCommandGroup.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public int cmdStartlevel(Dictionary<String, ?> opts,
                         Reader in,
                         PrintWriter out,
                         Session session)
{
  final FrameworkStartLevel fsl = bc.getBundle(0)
      .adapt(FrameworkStartLevel.class);
  final String levelStr = (String) opts.get("level");

  try {
    if (levelStr != null) {
      final int level = Integer.parseInt(levelStr);
      fsl.setStartLevel(level);
    } else {
      out.println("current start level:        " + fsl.getStartLevel());
      out.println("initial bundle start level: "
                  + fsl.getInitialBundleStartLevel());
    }
    return 0;
  } catch (final Exception e) {
    out.println("Failed to show/set startlevel=" + levelStr);
    e.printStackTrace(out);
    return -1;
  }
}
 
Example 3
Source File: NexusContextListener.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Install selected features.
 */
private void installNexusFeatures(final String featureNames) throws Exception {
  final Set<Feature> features = new LinkedHashSet<>();

  for (final String name : Splitter.on(',').trimResults().omitEmptyStrings().split(featureNames)) {
    final Feature feature = featuresService.getFeature(name);
    if (feature != null) {
      features.add(feature);
    }
    else {
      log.warn("Missing: {}", name);
    }
  }

  log.info("Installing: {}", features);

  Set<String> featureIds = new LinkedHashSet<>(features.size());
  for (final Feature f : features) {
    // feature might already be installed in the cache; if so then skip installation
    if (!featuresService.isInstalled(f)) {
      featureIds.add(f.getId());
    }
  }

  if (!featureIds.isEmpty()) {
    // avoid auto-refreshing bundles as that could trigger unwanted restart/lifecycle events
    EnumSet<Option> options = EnumSet.of(NoAutoRefreshBundles, NoAutoRefreshManagedBundles);
    featuresService.installFeatures(featureIds, options);
  }

  log.info("Installed: {}", features);

  // feature bundles have all been installed, so raise framework start level to finish activation
  FrameworkStartLevel frameworkStartLevel = bundleContext.getBundle(0).adapt(FrameworkStartLevel.class);
  if (frameworkStartLevel.getStartLevel() < NEXUS_PLUGIN_START_LEVEL) {
    frameworkStartLevel.setStartLevel(NEXUS_PLUGIN_START_LEVEL, this);
    // activation continues asynchronously in frameworkEvent method...
  }
}
 
Example 4
Source File: Desktop.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void setStartLevel(final int level)
{

  final Thread t = new Thread() {
    @Override
    public void run()
    {
      final FrameworkStartLevel fsl = getFrameworkStartLevel();
      if (null != fsl) {
        fsl.setStartLevel(level);
      }
    }
  };
  t.start();
}
 
Example 5
Source File: KfApk.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create a new framework, initialize and start it. If the init
 * parameter is true, or if there is no stored framework state, bundle
 * Jar file data will be read from the "jars" folder of the provided
 * AssetManager. If the init parameter is false and there is a stored
 * framework state, the framework will be started and its state will
 * be the stored state.
 * 
 * @param localStorage Path to application's storage location in the
 *        file system, framework state will be stored here
 * @param init If true, any stored framework state is ignored.
 * @param am AssetManager for the application, will be used to read
 *        bundle Jar file data when the framework is started without
 *        using a stored state.
 * @return a framework instance or null if the framework could not be
 *         started or initialized.
 * @throws IOException if there was a problem reading bundle Jar file
 *         data or framework/system properties using the AssestManager.
 */
public static Framework newFramework(String localStorage,
                                     boolean init,
                                     AssetManager am)
    throws IOException
{
  config = getConfiguration(am);
  String fwDir = localStorage + File.separator + FWDIR;
  config.put(Constants.FRAMEWORK_STORAGE, fwDir);

  boolean doInit = init || !new File(fwDir).exists();
  
  if (doInit) {
    config.put(Constants.FRAMEWORK_STORAGE_CLEAN,
               Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
  }

  Framework fw = new Main().getFrameworkFactory().newFramework(config);
  try {
    fw.init();
    int runlevel;
    if (doInit) {
      runlevel = scanBundles(fw, am);
      saveRunlevel(runlevel, fwDir);
    } else {
      runlevel = loadRunlevel(fwDir);
    }
    fw.start();
    // set target start level for framework start-up
    final FrameworkStartLevel fsl = fw.adapt(FrameworkStartLevel.class);
    if (fsl!=null) {
      fsl.setStartLevel(runlevel);
    }      
  } catch (BundleException be) {
    Log.e(KfApk.class.getName(), "Failed to init/start framework", be);
    return null;
  }
  
  return fw;
}
 
Example 6
Source File: StartLevelImpl.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void setStartLevel(int startlevel) {
	FrameworkStartLevel fsl = getFrameworkStartLevel0();
	fsl.setStartLevel(startlevel);
}
 
Example 7
Source File: FrameworkNodeImpl.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
public void setFrameworkStartLevel(FrameworkStartLevelDTO startLevel) {
	Bundle fw = context.getBundle(0);
	FrameworkStartLevel fwsl = fw.adapt(FrameworkStartLevel.class);
	fwsl.setInitialBundleStartLevel(startLevel.initialBundleStartLevel);
	fwsl.setStartLevel(startLevel.startLevel);
}