org.osgi.framework.startlevel.BundleStartLevel Java Examples
The following examples show how to use
org.osgi.framework.startlevel.BundleStartLevel.
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: FrameworkCommandGroup.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Sort an array of bundle objects based on their start level All entries * with no start level is placed at the end of the array. * * @param b * array of bundles to be sorted, modified with result */ protected void sortBundlesStartLevel(Bundle[] b) { int x = b.length; for (final int l = x; x > 0;) { x = 0; int p = Integer.MAX_VALUE; p = b[0].adapt(BundleStartLevel.class).getStartLevel(); for (int i = 1; i < l; i++) { int n = Integer.MAX_VALUE; n = b[i].adapt(BundleStartLevel.class).getStartLevel(); if (p > n) { x = i - 1; final Bundle t = b[x]; b[x] = b[i]; b[i] = t; } else { p = n; } } } }
Example #2
Source File: Activator.java From neoscada with Eclipse Public License 1.0 | 6 votes |
private void setStartLevel ( final String symbolicName, final int startLevel ) throws BundleException { final Bundle bundle = findBundle ( symbolicName ); if ( bundle == null ) { return; } final BundleStartLevel bundleStartLevel = bundle.adapt ( BundleStartLevel.class ); if ( bundleStartLevel == null ) { return; } bundleStartLevel.setStartLevel ( startLevel < 0 ? this.defaultStartLevel : startLevel ); bundle.start (); }
Example #3
Source File: Desktop.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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 |
/** * 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 #5
Source File: BundleStartLevelResource.java From concierge with Eclipse Public License 1.0 | 6 votes |
@Override public Representation put(final Representation value, final Variant variant) { try { final Bundle bundle = getBundleFromKeys(RestService.BUNDLE_ID_KEY); if (bundle == null) { return ERROR(Status.CLIENT_ERROR_NOT_FOUND); } final BundleStartLevelPojo sl = fromRepresentation(value, value.getMediaType()); final BundleStartLevel bsl = bundle.adapt(BundleStartLevel.class); bsl.setStartLevel(sl.getStartLevel()); return getRepresentation(new BundleStartLevelPojo(bsl), variant); } catch (final Exception e) { return ERROR(e, variant); } }
Example #6
Source File: FrameworkCommandGroup.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public int cmdBundlelevel(Dictionary<String, ?> opts, Reader in, PrintWriter out, Session session) { final FrameworkStartLevel fsl = bc.getBundle(0) .adapt(FrameworkStartLevel.class); int level = -1; try { level = Integer.parseInt((String) opts.get("level")); final String[] bls = (String[]) opts.get("bundle"); final Bundle[] bl = getBundles(bls, false, false); if (bls == null || bls.length == 0) { fsl.setInitialBundleStartLevel(level); out.println("initial bundle start level set to " + level); } else { for (int i = 0; i < bl.length; i++) { if (bl[i] != null) { System.out.println("set " + i + " " + bl[i] + " " + level); bl[i].adapt(BundleStartLevel.class).setStartLevel(level); } } } return 0; } catch (final Exception e) { out.println("Failed to set bundle startlevel=" + level); e.printStackTrace(out); return -1; } }
Example #7
Source File: FeaturesWrapper.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Install the specified bundle, using a direct 'reference:' URL where possible. */ private Bundle installBundle(final BundleInfo info) { try { // find the most direct URL to the bundle JAR String location = locationResolver.resolve(info.getLocation()); if (context.getBundle(location) == null) { // not yet installed, go ahead and install it log.debug("Installing {}", location); Bundle bundle = context.installBundle(location); log.debug("Installed {}/{} from {}", bundle.getSymbolicName(), bundle.getVersion(), location); if (info.getStartLevel() > 0) { bundle.adapt(BundleStartLevel.class).setStartLevel(info.getStartLevel()); } // fragments cannot be started, so remove them from the final result if (info.isStart() && bundle.getHeaders().get(FRAGMENT_HOST) == null) { return bundle; } } } catch (BundleException e) { // ignore duplicates with different locations if (e.getType() != DUPLICATE_BUNDLE_ERROR) { log.warn("Problem installing {}", info.getLocation(), e); } } return null; // we only return bundles that need to be started }
Example #8
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 5 votes |
/** * @see org.osgi.framework.Bundle#adapt(java.lang.Class) * @category Framework * @category SystemBundle */ @SuppressWarnings("unchecked") public <A> A adapt(final Class<A> type) { if (type == BundleStartLevel.class) { return (A) systemBundleStartLevel; } if (type == BundleWiring.class) { return (A) wirings.get(this); } if(type == FrameworkStartLevelDTO.class){ FrameworkStartLevelDTO fsl = new FrameworkStartLevelDTO(); fsl.initialBundleStartLevel = initStartlevel; fsl.startLevel = startlevel; return (A) fsl; } if(type == FrameworkDTO.class){ FrameworkDTO dto = new FrameworkDTO(); dto.bundles = new ArrayList<BundleDTO>(); for(Bundle b : bundles){ dto.bundles.add(b.adapt(BundleDTO.class)); } dto.services = new ArrayList<ServiceReferenceDTO>(); for(ServiceReference ref : serviceRegistry.getAllValues()){ dto.services.add(getServiceReferenceDTO(ref)); } dto.properties = new HashMap<String, Object>(); for(Object k : properties.keySet()){ String key = (String) k; dto.properties.put(key, getDTOValue(properties.getProperty(key))); } return (A) dto; } return super.adapt(type); }
Example #9
Source File: AbstractBundle.java From concierge with Eclipse Public License 1.0 | 5 votes |
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 #10
Source File: Desktop.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
JMenu makeStartLevelMenu() { return new JMenu(Strings.get("menu_startlevel")) { private static final long serialVersionUID = 1L; { setToolTipText(Strings.get("startlevel.descr")); final ButtonGroup group = new ButtonGroup(); group.add(noStartLevelSelected); add(levelMenuLabel = new JMenuItem(Strings.get("startlevel.noSel"))); add(new JSeparator()); for (int i = levelMin; i <= levelMax; i++) { final AbstractButton jrb = new JRadioButtonMenuItem(Integer.toString(i)); group.add(jrb); add(jrb); jrb.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { final Bundle[] bl = getSelectedBundles(); final int level = Integer.parseInt(jrb.getText()); for (final Bundle element : bl) { final BundleStartLevel bsl = element.adapt(BundleStartLevel.class); if (null != bsl) { bsl.setStartLevel(level); } updateBundleViewSelections(); } } }); levelCheckBoxes.put(new Integer(i), jrb); } } }; }
Example #11
Source File: BundleStartLevelResource.java From concierge with Eclipse Public License 1.0 | 5 votes |
@Override public Representation get(final Variant variant) { try { final Bundle bundle = getBundleFromKeys(RestService.BUNDLE_ID_KEY); if (bundle == null) { return ERROR(Status.CLIENT_ERROR_NOT_FOUND); } final BundleStartLevel bsl = bundle.adapt(BundleStartLevel.class); final BundleStartLevelPojo sl = new BundleStartLevelPojo(bsl); return getRepresentation(sl, variant); } catch (final Exception e) { return ERROR(e, variant); } }
Example #12
Source File: FrameworkNodeImpl.java From concierge with Eclipse Public License 1.0 | 5 votes |
public void setBundleStartLevel(long id, int startLevel) { Bundle b = context.getBundle(id); if(b == null) return; BundleStartLevel bsl = b.adapt(BundleStartLevel.class); bsl.setStartLevel(startLevel); }
Example #13
Source File: Util.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 #14
Source File: LargeIconsDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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 #15
Source File: BundleUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * @param array */ private static IStatus startBundles(Collection<Bundle> bundles) { final BundleContext context = JavaLanguageServerPlugin.getBundleContext(); MultiStatus status = new MultiStatus(context.getBundle().getSymbolicName(), IStatus.OK, "Starting added bundles", null); for (Bundle bundle : bundles) { if (bundle.getState() == Bundle.UNINSTALLED) { status.add(new Status(IStatus.ERROR, context.getBundle().getSymbolicName(), "Could not start: " + bundle.getSymbolicName() + '(' + bundle.getLocation() + ':' + bundle.getBundleId() + ')' + ". It's state is uninstalled.")); continue; } if (bundle.getState() == Bundle.STARTING) { continue; } if (bundle.getBundleId() == 0) { continue; } try { // set to the default value for osgi.bundles.defaultStartLevel bundle.adapt(BundleStartLevel.class).setStartLevel(4); bundle.start(Bundle.START_ACTIVATION_POLICY); JavaLanguageServerPlugin.logInfo("Started " + bundle.getLocation()); } catch (BundleException e) { status.add(new Status(IStatus.ERROR, context.getBundle().getSymbolicName(), "Bundle startup failed " + bundle.getLocation(), e)); } } return status; }
Example #16
Source File: Desktop.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
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 #17
Source File: Desktop.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
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\"> ["); 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 #18
Source File: TableDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
@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; } }
Example #19
Source File: Desktop.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
void setFWStartLevel() { final int level = levelBox.getSelectedIndex() + levelMin; final FrameworkStartLevel fsl = getFrameworkStartLevel(); if (fsl != null) { if (fsl.getStartLevel() == level) { return; } } int myLevel = level; try { myLevel = Activator.getTargetBC().getBundle().adapt(BundleStartLevel.class) .getStartLevel(); } catch (final IllegalArgumentException ignored) { } boolean bOK = true; if (level < myLevel) { bOK = false; final Object[] options = { Strings.get("yes"), Strings.get("cancel") }; final int n = JOptionPane.showOptionDialog(frame, Strings.get("q_stopdesktop"), Strings.get("msg_stopdesktop"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); if (n == 0) { bOK = true; } } if (bOK) { setStartLevel(level); } else { if (fsl != null) { levelBox.setSelectedIndex(fsl.getStartLevel() - levelMin); } } }
Example #20
Source File: FrameworkCommandGroup.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
public String showState(Bundle bundle) { final StringBuffer sb = new StringBuffer(); try { final StringBuffer s = new StringBuffer (String.valueOf(bundle.adapt(BundleStartLevel.class).getStartLevel())); while (s.length() < 2) { s.insert(0, " "); } sb.append(s.toString()); } catch (final Exception ignored) { sb.append("--"); } sb.append("/"); switch (bundle.getState()) { case Bundle.INSTALLED: sb.append("installed"); break; case Bundle.RESOLVED: sb.append("resolved"); break; case Bundle.STARTING: sb.append("starting"); break; case Bundle.ACTIVE: sb.append("active"); break; case Bundle.STOPPING: sb.append("stopping"); break; case Bundle.UNINSTALLED: sb.append("uninstalled"); break; default: sb.append("ILLEGAL <" + bundle.getState() + "> "); break; } while (sb.length() < 13) { sb.append(" "); } return sb.toString(); }
Example #21
Source File: XargsFileLauncherXargsTest.java From concierge with Eclipse Public License 1.0 | 4 votes |
private BundleStartLevel asBSL(Bundle b) { return b.adapt(BundleStartLevel.class); }
Example #22
Source File: BundleStartLevelPojo.java From concierge with Eclipse Public License 1.0 | 4 votes |
public BundleStartLevelPojo(final BundleStartLevel sl) { this.startLevel = sl.getStartLevel(); this.activationPolicyUsed = sl.isActivationPolicyUsed(); this.persistentlyStarted = sl.isPersistentlyStarted(); }
Example #23
Source File: StartLevelImpl.java From concierge with Eclipse Public License 1.0 | 4 votes |
private BundleStartLevel getBundleStartLevel0(Bundle bundle){ return bundle.adapt(BundleStartLevel.class); }
Example #24
Source File: StartLevelImpl.java From concierge with Eclipse Public License 1.0 | 4 votes |
@Override public boolean isBundleActivationPolicyUsed(Bundle bundle) { BundleStartLevel bsl = getBundleStartLevel0(bundle); return bsl.isActivationPolicyUsed(); }
Example #25
Source File: StartLevelImpl.java From concierge with Eclipse Public License 1.0 | 4 votes |
@Override public boolean isBundlePersistentlyStarted(Bundle bundle) { BundleStartLevel bsl = getBundleStartLevel0(bundle); return bsl.isPersistentlyStarted(); }
Example #26
Source File: StartLevelImpl.java From concierge with Eclipse Public License 1.0 | 4 votes |
@Override public void setBundleStartLevel(Bundle bundle, int startlevel) { BundleStartLevel bsl = getBundleStartLevel0(bundle); bsl.setStartLevel(startlevel); }
Example #27
Source File: StartLevelImpl.java From concierge with Eclipse Public License 1.0 | 4 votes |
@Override public int getBundleStartLevel(Bundle bundle) { BundleStartLevel bsl = getBundleStartLevel0(bundle); return bsl.getStartLevel(); }