Java Code Examples for org.osgi.framework.wiring.BundleRevision#getTypes()

The following examples show how to use org.osgi.framework.wiring.BundleRevision#getTypes() . 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
void startBundle(final Bundle b)
{
  // Fragments can not be started
  final BundleRevision br = b.adapt(BundleRevision.class);
  if ((br.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
    return;
  }

  // Must not call start() from the EDT, since that will block the
  // EDT until the start()-call completes.
  new Thread("Desktop-StartBundle " + b.getBundleId()) {
    @Override
    public void run()
    {
      try {
        b.start(getStartOptions());
        updateBundleViewSelections();
      } catch (final Exception e) {
        showErr("Failed to start bundle " + Util.getBundleName(b) + ": " + e,
                e);
      }
    }
  }.start();
}
 
Example 3
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 4
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 needs to be refreshed.
 *
 * <ol>
 * <li>A bundle with no bundle revisions does not need a refreshed. The bundle
 * has been uninstalled and does not have any active wires since there are no
 * bundle revisions.
 * <li>A bundle with more than one bundle revision needs to be refreshed.
 * <li>A fragment bundle can always be refreshed, since the refresh operation
 * will attach it to any matching host that it has not yet been attached to.
 * </ol>
 *
 * @param bundle
 *          the bundle to check.
 * @return {@code true} if the bundle needs to be refreshed.
 */
boolean refreshBundleNeeded(final Bundle bundle)
{
  final List<BundleRevision> bRevs =
    bundle.adapt(BundleRevisions.class).getRevisions();

  if (bRevs.isEmpty()) {
    // Uninstalled bundle with no active bundle revision.
    return false;
  }

  final BundleRevision bRevCur = bRevs.get(0);
  final boolean isFragment =
    bRevCur.getTypes() == BundleRevision.TYPE_FRAGMENT;

  if (isFragment) {
    // A fragment may attach to new hosts as the result of a refresh.
    return true;
  }

  // Are there any old bundle revisions pending deletion?
  return bRevs.size() > 1;
}
 
Example 5
Source File: BundleManager.java    From vespa with Apache License 2.0 5 votes vote down vote up
private boolean isFragment(Bundle bundle) {
    BundleRevision bundleRevision = bundle.adapt(BundleRevision.class);
    if (bundleRevision == null)
        throw new NullPointerException("Null bundle revision means that bundle has probably been uninstalled: " +
                                       bundle.getSymbolicName() + ":" + bundle.getVersion());
    return (bundleRevision.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0;
}
 
Example 6
Source File: AbstractBundle.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
protected final BundleRevisionDTO getBundleRevisionDTO(BundleRevision revision){
	BundleRevisionDTO dto = new BundleRevisionDTO();
	dto.bundle = revision.getBundle().getBundleId();
	dto.id = revision.hashCode();
	dto.symbolicName = revision.getSymbolicName();
	dto.type = revision.getTypes();
	dto.version = getVersion().toString();
	
	// add requirement/capabilities
	List<Capability> caps = revision.getCapabilities(null);
	dto.capabilities = new ArrayList<CapabilityDTO>(caps.size());
	for(Capability c : caps){
		CapabilityDTO capDTO = new CapabilityDTO();
		capDTO.id = c.hashCode();
		capDTO.namespace = c.getNamespace();
		capDTO.resource = c.getResource().hashCode();
		capDTO.attributes = getDTOMap(c.getAttributes());
		capDTO.directives = new HashMap<String, String>(c.getDirectives());
		dto.capabilities.add(capDTO);
	}
	
	List<Requirement> reqs = revision.getRequirements(null);
	dto.requirements = new ArrayList<RequirementDTO>(reqs.size());
	for(Requirement r : reqs){
		RequirementDTO reqDTO = new RequirementDTO();
		reqDTO.id = r.hashCode();
		reqDTO.namespace = r.getNamespace();
		reqDTO.resource = r.getResource().hashCode();
		reqDTO.attributes = getDTOMap(r.getAttributes());
		reqDTO.directives = new HashMap<String, String>(r.getDirectives());
		dto.requirements.add(reqDTO);
	}
	return dto;
}
 
Example 7
Source File: Util.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static public String bundleInfo(Bundle b)
{
  final StringBuffer sb = new StringBuffer();
  final BundleRevision br = b.adapt(BundleRevision.class);
  final boolean isFragment = br != null &&
    ((br.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0);

  sb.append("<html>");
  sb.append(" Id: ");
  sb.append(b.getBundleId());
  if (isFragment) {
    sb.append(" (fragment)");
  }
  sb.append("<br>");

  sb.append(" Name: ");
  sb.append(Util.getBundleName(b));
  sb.append("<br>");

  sb.append(" State: ");
  sb.append(Util.stateName(b.getState()));
  sb.append("<br>");

  final BundleStartLevel bsl = b.adapt(BundleStartLevel.class);
  if (bsl != null) {
    sb.append(" Start level: ");
    try {
      sb.append(bsl.getStartLevel());
      if (bsl.isPersistentlyStarted()) {
        sb.append(", persistently started");
      }
    } catch (final IllegalArgumentException e) {
      sb.append("not managed");
    }
    sb.append("<br>");
  }

  sb.append("</html>");
  return sb.toString();
}
 
Example 8
Source File: JHTMLBundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get header text for selected bundle page.
 */
public static String getBundleSelectedHeader(Bundle b)
{
  final BundleRevision rev = b.adapt(BundleRevision.class);
  final boolean isFragment =
    rev != null
      ? (rev.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0
      : false;

  return "#" + b.getBundleId() + "  " + Util.getBundleName(b)
         + (isFragment ? "  (fragment)" : "");
}
 
Example 9
Source File: Desktop.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
void stopBundle(final Bundle b)
{
  // Fragments can not be stopped
  final BundleRevision br = b.adapt(BundleRevision.class);
  if ((br.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
    return;
  }

  // Special handling needed when stopping the desktop itself.
  final boolean stoppingSelf =
    b.getBundleId() == 0
        || b.getBundleId() == Activator.getTargetBC().getBundle()
            .getBundleId();

  int n = 0;
  if (stoppingSelf) {
    final Object[] options = { Strings.get("yes"), Strings.get("no") };
    n =
      JOptionPane.showOptionDialog(frame,
                                   Strings.fmt("fmt_q_stopdesktop",
                                               Util.getBundleName(b)),
                                   Strings.get("yes"),
                                   JOptionPane.YES_NO_OPTION,
                                   JOptionPane.QUESTION_MESSAGE, null,
                                   options, options[1]);
  }

  if (n == 0) {
    // Must not call stop() from the EDT, since that will block the
    // EDT untill the stop()-call completes.
    new Thread("Desktop-StopBundle " + b.getBundleId()) {
      @Override
      public void run()
      {
        try {
          b.stop(getStopOptions());
          updateBundleViewSelections();
        } catch (final Exception e) {
          showErr("Failed to stop bundle " + Util.getBundleName(b) + ": " + e,
                  e);
        }
      }
    }.start();
  }
}