org.osgi.framework.startlevel.FrameworkStartLevel Java Examples
The following examples show how to use
org.osgi.framework.startlevel.FrameworkStartLevel.
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: SystemBundle.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override @SuppressWarnings("unchecked") public <A> A adapt(Class<A> type) { secure.checkAdaptPerm(this, type); Object res = null; if (FrameworkWiring.class.equals(type)) { res = fwWiring; } else if (FrameworkStartLevel.class.equals(type)) { if (fwCtx.startLevelController != null) { res = fwCtx.startLevelController.frameworkStartLevel(); } } else if (Framework.class.equals(type)) { res = this; } else if (FrameworkStartLevelDTO.class.equals(type)) { if (fwCtx.startLevelController != null) { res = fwCtx.startLevelController.frameworkStartLevel().getDTO(); } } else if (FrameworkDTO.class.equals(type)) { res = getFrameworkDTO(); } else { // TODO filter which adaptation we can do?! res = adaptSecure(type); } return (A) res; }
Example #2
Source File: Desktop.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
JMenu makeBundleMenu() { return new JMenu(Strings.get("menu_bundles")) { private static final long serialVersionUID = 1L; { add(new JMenuItem(actionStopBundles)); add(makeStopOptionsMenu()); addSeparator(); add(new JMenuItem(actionStartBundles)); add(makeStartOptionsMenu()); addSeparator(); add(new JMenuItem(actionResolveBundles)); add(new JMenuItem(actionUpdateBundles)); add(new JMenuItem(actionRefreshBundles)); add(new JMenuItem(actionUninstallBundles)); final FrameworkStartLevel fsl = getFrameworkStartLevel(); if (fsl != null) { add(startLevelMenu = makeStartLevelMenu()); } } }; }
Example #3
Source File: FrameworkStartLevelResource.java From concierge with Eclipse Public License 1.0 | 6 votes |
@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 #4
Source File: FrameworkCommandGroup.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #5
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 #6
Source File: KfApk.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 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 #7
Source File: Config.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Ask the start level service for the default start level of bundles * * @return the initial start level. */ private int getFrameworkInitialStartLevel() { int startLevel; // final FrameworkStartLevel fsl = Activator.bc.getBundle(0).adapt(FrameworkStartLevel.class); if (null != fsl) { startLevel = fsl.getInitialBundleStartLevel(); } else { startLevel = 1; // Fallback to the default initial bundle start level } return startLevel; }
Example #8
Source File: Config.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Ask the start level service for the default start level of bundles * * @return the initial start level. */ private int getFrameworkInitialStartLevel() { int startLevel; // final FrameworkStartLevel fsl = Activator.bc.getBundle(0).adapt(FrameworkStartLevel.class); if (null != fsl) { startLevel = fsl.getInitialBundleStartLevel(); } else { startLevel = 1; // Fallback to the default initial bundle start level } return startLevel; }
Example #9
Source File: Desktop.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
void updateStartLevel() { final FrameworkStartLevel fsl = getFrameworkStartLevel(); if (fsl == null) { return; } updateLevelItems(); if (levelBox != null) { levelBox.setSelectedIndex(fsl.getStartLevel() - levelMin); } updateBundleViewSelections(); }
Example #10
Source File: Desktop.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 #11
Source File: Activator.java From neoscada with Eclipse Public License 1.0 | 5 votes |
@Override public void start ( final BundleContext bundleContext ) throws Exception { this.context = bundleContext; final ServiceReference<FrameworkStartLevel> frameworkStartLevel = this.context.getServiceReference ( FrameworkStartLevel.class ); if ( frameworkStartLevel != null ) { final FrameworkStartLevel service = this.context.getService ( frameworkStartLevel ); if ( service != null ) { try { this.defaultStartLevel = service.getInitialBundleStartLevel (); } finally { this.context.ungetService ( frameworkStartLevel ); } } } loadStartLevels (); for ( final Map.Entry<String, Integer> entry : this.bundleStartList.entrySet () ) { setStartLevel ( entry.getKey (), entry.getValue () ); } }
Example #12
Source File: NexusContextListener.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * 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 #13
Source File: FrameworkStartLevelPojo.java From concierge with Eclipse Public License 1.0 | 4 votes |
public FrameworkStartLevelPojo(final FrameworkStartLevel fsl) { this.startLevel = fsl.getStartLevel(); this.initialBundleStartLevel = fsl.getInitialBundleStartLevel(); }
Example #14
Source File: FrameworkTrayIcon.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
public FrameworkTrayIcon() throws UnsupportedOperationException { final StringBuffer toolTipText = new StringBuffer("Knopflerfish OSGi"); final String servicePlatformId = Activator.bc.getProperty("org.osgi.provisioning.spid"); if (null != servicePlatformId && 0 < servicePlatformId.length()) { toolTipText.append(" (").append(servicePlatformId).append(")"); } try { trayIconClass = Class.forName("java.awt.TrayIcon"); final Constructor<?> con = trayIconClass.getDeclaredConstructor(new Class[] { Image.class, String.class }); trayIcon = con.newInstance(new Object[] { Toolkit .getDefaultToolkit() .getImage(FrameworkTrayIcon.class .getResource(getIconForOS())), toolTipText.toString() }); final Method m = trayIconClass.getDeclaredMethod("setPopupMenu", new Class[] { PopupMenu.class }); m.invoke(trayIcon, new Object[] { makeMenu() }); frameworkStartLevel = Activator.bc.getBundle(0L).adapt(FrameworkStartLevel.class); updateStartLevelItems(); Activator.bc.addFrameworkListener(new FrameworkListener() { public void frameworkEvent(FrameworkEvent ev) { if (FrameworkEvent.STARTLEVEL_CHANGED == ev.getType() || FrameworkEvent.STARTED == ev.getType()) { updateStartLevelItems(); } } }); } catch (final Exception e) { Activator.log.error("Failed to create FrameworkTrayIcon: " + e, e); throw new UnsupportedOperationException(e.getMessage()); } }
Example #15
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 #16
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 #17
Source File: AbstractOSGiResource.java From concierge with Eclipse Public License 1.0 | 4 votes |
protected FrameworkStartLevel getFrameworkStartLevel() { return getBundleContext().getBundle(0).adapt(FrameworkStartLevel.class); }
Example #18
Source File: FrameworkNodeImpl.java From concierge with Eclipse Public License 1.0 | 4 votes |
public void setFrameworkStartLevel(FrameworkStartLevelDTO startLevel) { Bundle fw = context.getBundle(0); FrameworkStartLevel fwsl = fw.adapt(FrameworkStartLevel.class); fwsl.setInitialBundleStartLevel(startLevel.initialBundleStartLevel); fwsl.setStartLevel(startLevel.startLevel); }
Example #19
Source File: Desktop.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
FrameworkStartLevel getFrameworkStartLevel() { final Bundle systemBundle = Activator.getTargetBC_getBundle(0L); final FrameworkStartLevel fsl = systemBundle.adapt(FrameworkStartLevel.class); return fsl; }
Example #20
Source File: Desktop.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
int getCurrentStartLevel() { final FrameworkStartLevel fsl = getFrameworkStartLevel(); return fsl != null ? fsl.getStartLevel() : 1; }
Example #21
Source File: StartLevelImpl.java From concierge with Eclipse Public License 1.0 | 4 votes |
private FrameworkStartLevel getFrameworkStartLevel0(){ Bundle bundle = context.getBundle(0); return bundle.adapt(FrameworkStartLevel.class); }
Example #22
Source File: StartLevelImpl.java From concierge with Eclipse Public License 1.0 | 4 votes |
@Override public void setInitialBundleStartLevel(int startlevel) { FrameworkStartLevel fsl = getFrameworkStartLevel0(); fsl.setInitialBundleStartLevel(startlevel); }
Example #23
Source File: StartLevelImpl.java From concierge with Eclipse Public License 1.0 | 4 votes |
@Override public int getInitialBundleStartLevel() { FrameworkStartLevel fsl = getFrameworkStartLevel0(); return fsl.getInitialBundleStartLevel(); }
Example #24
Source File: StartLevelImpl.java From concierge with Eclipse Public License 1.0 | 4 votes |
@Override public void setStartLevel(int startlevel) { FrameworkStartLevel fsl = getFrameworkStartLevel0(); fsl.setStartLevel(startlevel); }
Example #25
Source File: StartLevelImpl.java From concierge with Eclipse Public License 1.0 | 4 votes |
@Override public int getStartLevel() { FrameworkStartLevel fsl = getFrameworkStartLevel0(); return fsl.getStartLevel(); }