Java Code Examples for org.osgi.framework.startlevel.BundleStartLevel#getStartLevel()

The following examples show how to use org.osgi.framework.startlevel.BundleStartLevel#getStartLevel() . 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: Desktop.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Determine if the given bundle can and needs to be started.
 *
 * <ol>
 * <li>A fragment bundle must never be started.
 * <li>If no start-level support is present in the framework then any bundle
 * in state installed, resolved or starting can be started.
 * <li>A bundle that is not persistently started can be started.
 * <li>A bundle that is persistently started and in any of the states
 * installed, resolved, starting and assigned to a start level that is lower
 * or equal to the current start level can be started.
 * </ol>
 *
 * @param bundle
 *          the bundle to check.
 * @return {@code true} if the bundle needs to be started.
 */
boolean startBundlePossible(final Bundle bundle)
{
  final BundleRevision bRevCur = bundle.adapt(BundleRevision.class);
  final boolean isFragment =
    bRevCur.getTypes() == BundleRevision.TYPE_FRAGMENT;

  if (isFragment) {
    return false;
  }

  final int state = bundle.getState();
  final boolean startable =
    (state & (Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING)) != 0;

  final BundleStartLevel bsl = bundle.adapt(BundleStartLevel.class);
  if (bsl == null) {
    return startable;
  }

  if (!bsl.isPersistentlyStarted()) {
    return true;
  }

  return startable && bsl.getStartLevel() <= getCurrentStartLevel();
}
 
Example 2
Source File: Desktop.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Determine if the given bundle can and needs to be stopped.
 *
 * <ol>
 * <li>A fragment bundle must never be stopped.
 * <li>If no start-level support is present in the framework then any bundle
 * in state starting, active can be stopped.
 * <li>A bundle that is persistently started can be stopped.
 * </ol>
 *
 * @param bundle
 *          the bundle to check.
 * @return {@code true} if the bundle needs to be stopped.
 */
boolean stopBundlePossible(final Bundle bundle)
{
  final BundleRevision bRevCur = bundle.adapt(BundleRevision.class);
  final boolean isFragment =
    bRevCur.getTypes() == BundleRevision.TYPE_FRAGMENT;

  if (isFragment) {
    return false;
  }

  final int state = bundle.getState();
  final boolean stoppable =
    (state & (Bundle.STARTING | Bundle.ACTIVE)) != 0;

  final BundleStartLevel bsl = bundle.adapt(BundleStartLevel.class);
  if (bsl == null) {
    return stoppable;
  }

  if (bsl.isPersistentlyStarted()) {
    return true;
  }

  return stoppable && bsl.getStartLevel() > getCurrentStartLevel();
}
 
Example 3
Source File: AbstractBundle.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
protected final BundleStartLevelDTO getBundleStartLevelDTO(){
	BundleStartLevelDTO dto = new BundleStartLevelDTO();
	dto.bundle = bundleId;
	
	BundleStartLevel bsl = adapt(BundleStartLevel.class);
	dto.startLevel = bsl.getStartLevel();
	dto.activationPolicyUsed = bsl.isActivationPolicyUsed();
	dto.persistentlyStarted = bsl.isPersistentlyStarted();
	return dto;
}
 
Example 4
Source File: LargeIconsDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public int compare(Long l1, Long l2)
{
  final Bundle b1 = Activator.getTargetBC_getBundle(l1.longValue());
  final Bundle b2 = Activator.getTargetBC_getBundle(l2.longValue());

  if (b1 == b2) {
    return 0;
  }
  if (b1 == null) {
    return -1;
  }
  if (b2 == null) {
    return 1;
  }
  final long bidDiff = b1.getBundleId() - b2.getBundleId();
  final int bidRes = bidDiff < 0 ? -1 : (bidDiff == 0 ? 0 : 1);

  final BundleStartLevel bsl1 = b1.adapt(BundleStartLevel.class);
  final BundleStartLevel bsl2 = b2.adapt(BundleStartLevel.class);
  if (bsl1 != null && bsl2 != null) {
    final int sl1 = bsl1.getStartLevel();
    final int sl2 = bsl2.getStartLevel();
    return sl1 == sl2 ? bidRes : sl1 - sl2;
  }
  return bidRes;
}
 
Example 5
Source File: StartLevelImpl.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public int getBundleStartLevel(Bundle bundle) {
	BundleStartLevel bsl = getBundleStartLevel0(bundle);
	return bsl.getStartLevel();
}
 
Example 6
Source File: BundleStartLevelPojo.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
public BundleStartLevelPojo(final BundleStartLevel sl) {
	this.startLevel = sl.getStartLevel();
	this.activationPolicyUsed = sl.isActivationPolicyUsed();
	this.persistentlyStarted = sl.isPersistentlyStarted();
}
 
Example 7
Source File: Desktop.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
void updateLevelItems()
{
  final FrameworkStartLevel fsl = getFrameworkStartLevel();
  if (fsl == null) {
    // No start level service present.
    return;
  }
  levelMax = Math.max(levelMax, fsl.getStartLevel());
  levelItems = new String[levelMax - levelMin + 1];

  final Bundle[] bundles = Activator.getTargetBC().getBundles();
  final StringBuffer sb = new StringBuffer();
  for (final Bundle bundle : bundles) {
    final BundleStartLevel bsl = bundle.adapt(BundleStartLevel.class);
    if (bsl != null) {
      final int ix = bsl.getStartLevel() - levelMin;
      if (0 <= ix && ix < levelItems.length) {
        sb.setLength(0);
        if (levelItems[ix] != null) {
          sb.append(levelItems[ix]);
        }
        if (sb.length() > 0) {
          sb.append(", ");
        }
        final String name = Util.getBundleName(bundle);
        sb.append(name);
        levelItems[ix] = sb.toString();
      }
    }
  }

  final int maxItemLen = 70;
  for (int level = levelMin; level <= levelMax; level++) {
    sb.setLength(0);
    final String levelBundles = levelItems[level - levelMin];
    sb.append("<html><b>");
    sb.append(level);
    sb.append("</b><font size=\"-2\" color=\"#666666\">");
    if (levelBundles != null) {
      sb.append("<font size=\"-2\">&nbsp;[");
      if (levelBundles.length() > maxItemLen) {
        sb.append(levelBundles.subSequence(0, maxItemLen));
        sb.append("...");
      } else {
        sb.append(levelBundles);
      }
      sb.append("]</font>");
    }
    sb.append("</html>");
    levelItems[level - levelMin] = sb.toString();
  }

  if (levelBox != null) {
    final DefaultComboBoxModel model = new DefaultComboBoxModel(levelItems);
    levelBox.setModel(model);
    // Avoid a lot of whitespace to the right of any "..."
    levelBox.setMaximumSize(levelBox.getPreferredSize());
  }
}
 
Example 8
Source File: Desktop.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
void updateBundleViewSelections()
{

  final Bundle[] bl = getSelectedBundles();

  if (bl.length == 0) {
    actionResolveBundles.setEnabled(false);
    actionStartBundles.setEnabled(false);
    actionStopBundles.setEnabled(false);
    actionUpdateBundles.setEnabled(false);
    actionRefreshBundles.setEnabled(true);
    actionUninstallBundles.setEnabled(false);
  } else {
    // since there are bundles selected update and uninstall are enabled
    actionUpdateBundles.setEnabled(true);
    actionUninstallBundles.setEnabled(true);

    boolean anyResolvable = false;
    boolean anyStartable = false;
    boolean anyStoppable = false;
    boolean anyRefreshable = false;

    for (final Bundle bundle : bl) {
      anyResolvable |= resolveBundlePossible(bundle);
      anyStartable |= startBundlePossible(bundle);
      anyStoppable |= stopBundlePossible(bundle);
      anyRefreshable |= refreshBundleNeeded(bundle);
    }
    actionResolveBundles.setEnabled(anyResolvable);
    actionStartBundles.setEnabled(anyStartable);
    actionStopBundles.setEnabled(anyStoppable);
    actionRefreshBundles.setEnabled(anyRefreshable);
  }

  toolBar.invalidate();
  menuBar.invalidate();

  if (null != startLevelMenu) {
    startLevelMenu.setEnabled(bl.length != 0);
  }

  if (levelMenuLabel != null) {
    levelMenuLabel.setText(Strings.get("startlevel.noSel"));
    noStartLevelSelected.setSelected(true);

    final Set<Integer> levels = new HashSet<Integer>();
    final Set<Long> bids = new HashSet<Long>();
    for (final Bundle element : bl) {
      final BundleStartLevel bsl = element.adapt(BundleStartLevel.class);
      if (bsl != null) {
        try {
          final Integer lvl = new Integer(bsl.getStartLevel());
          levels.add(lvl);
          bids.add(new Long(element.getBundleId()));
        } catch (final Exception e) {
        }
      }
    }
    levelMenuLabel.setText("Bundle " + bids);
    if (1 == levels.size()) {
      final Integer level = levels.iterator().next();
      final AbstractButton jrb = levelCheckBoxes.get(level);
      if (null != jrb) {
        jrb.setSelected(true);
      }
    }
  }
}
 
Example 9
Source File: TableDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Object getValueAt(int row, int column)
{
  final Bundle b = getBundle(row);

  switch (column) {
  case COL_LOCATION:
    return Util.shortLocation(b.getLocation());
  case COL_ID:
    // return Long.toString(b.getBundleId());
    return Long.valueOf(b.getBundleId());
  case COL_STATE:
    return Util.stateName(b.getState());
  case COL_STARTLEVEL: {
    final BundleStartLevel bsl = b.adapt(BundleStartLevel.class);

    if (null != bsl) {
      try {
        final int n = bsl.getStartLevel();
        return Integer.valueOf(n);
      } catch (final Exception e) {
        // not managed, indicate with -1
        return Integer.valueOf(-1);
      }
    } else {
      // No start level adaptation available, indicate with -2
      return Integer.valueOf(-2);
    }
  }
  case COL_DESC:
    return Util.getHeader(b, Constants.BUNDLE_DESCRIPTION);
  case COL_NAME:
    return Util.getHeader(b, Constants.BUNDLE_NAME);
  case COL_VENDOR:
    return Util.getHeader(b, Constants.BUNDLE_VENDOR);
  case COL_SYMBOLIC_NAME:
    return b.getSymbolicName();
  case COL_VERSION:
    return b.getVersion();
  default:
    return null;
  }
}