Java Code Examples for org.osgi.framework.Bundle#RESOLVED
The following examples show how to use
org.osgi.framework.Bundle#RESOLVED .
These examples are extracted from open source projects.
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 Project: packagedrone File: DefaultAddonRegistration.java License: Eclipse Public License 1.0 | 6 votes |
private String makeState ( final int state ) { switch ( state ) { case Bundle.ACTIVE: return "ACTIVE"; case Bundle.INSTALLED: return "INSTALLED"; case Bundle.RESOLVED: return "RESOLVED"; case Bundle.STARTING: return "STARTING"; case Bundle.STOPPING: return "STOPPING"; case Bundle.UNINSTALLED: return "UNINSTALLED"; default: return Integer.toString ( state ); } }
Example 2
Source Project: knopflerfish.org File: Desktop.java License: 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 3
Source Project: cxf File: CXFExtensionBundleListener.java License: Apache License 2.0 | 5 votes |
public void registerExistingBundles(BundleContext context) throws IOException { for (Bundle bundle : context.getBundles()) { if ((bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.STARTING || bundle.getState() == Bundle.ACTIVE || bundle.getState() == Bundle.STOPPING) && bundle.getBundleId() != context.getBundle().getBundleId()) { register(bundle); } } }
Example 4
Source Project: openhab-core File: XmlDocumentBundleTracker.java License: Eclipse Public License 2.0 | 5 votes |
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) public final synchronized void open() { final OpenState openState = withLock(lockOpenState.writeLock(), () -> { if (this.openState == OpenState.CREATED) { this.openState = OpenState.OPENED; } return this.openState; }); if (openState != OpenState.OPENED) { logger.warn("Open XML document bundle tracker forbidden (state: {})", openState); return; } relevantBundlesTracker = new BundleTracker(context, Bundle.RESOLVED | Bundle.STARTING | Bundle.STOPPING | Bundle.ACTIVE, null) { @Override public @Nullable Object addingBundle(@NonNullByDefault({}) Bundle bundle, @NonNullByDefault({}) BundleEvent event) { return withLock(lockOpenState.readLock(), () -> openState == OpenState.OPENED && isBundleRelevant(bundle) ? bundle : null); } }; relevantBundlesTracker.open(); super.open(); }
Example 5
Source Project: netbeans File: OSGiMainLookup.java License: Apache License 2.0 | 5 votes |
public @Override boolean isEnabled() { switch (b.getState()) { case Bundle.RESOLVED: case Bundle.ACTIVE: case Bundle.STARTING: case Bundle.STOPPING: return true; default: return false; } }
Example 6
Source Project: orion.server File: Activator.java License: Eclipse Public License 1.0 | 5 votes |
private void ensureBundleStarted(String symbolicName) { Bundle bundle = getBundle(symbolicName); if (bundle != null) { if (bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.STARTING) { try { bundle.start(Bundle.START_TRANSIENT); } catch (BundleException e) { Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.core"); //$NON-NLS-1$ logger.error("Could not start bundle " + symbolicName, e); } } } }
Example 7
Source Project: knopflerfish.org File: StartLevelController.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
void syncStartLevel(BundleImpl bs) { try { if (fwCtx.debug.startlevel) { fwCtx.debug.println("syncstartlevel: " + bs); } synchronized (lock) { synchronized (fwCtx.resolver) { if (bs.getStartLevel() <= currentLevel) { final BundleGeneration current = bs.current(); if ((bs.getState() & (Bundle.INSTALLED|Bundle.RESOLVED|Bundle.STOPPING)) != 0 && current.archive.getAutostartSetting()!=-1) { if (fwCtx.debug.startlevel) { fwCtx.debug.println("startlevel: start " + bs); } int startOptions = Bundle.START_TRANSIENT; if (isBundleActivationPolicyUsed(current.archive)) { startOptions |= Bundle.START_ACTIVATION_POLICY; } bs.start(startOptions); } } else { if ((bs.getState() & (Bundle.ACTIVE|Bundle.STARTING)) != 0) { if (fwCtx.debug.startlevel) { fwCtx.debug.println("startlevel: stop " + bs); } bs.stop(Bundle.STOP_TRANSIENT); } } } } } catch (final Throwable t) { fwCtx.frameworkError(bs, t); } }
Example 8
Source Project: orion.server File: ServerTestsActivator.java License: Eclipse Public License 1.0 | 5 votes |
static private void ensureBundleStarted(String name) throws BundleException { Bundle bundle = getBundle(name); if (bundle != null) { if (bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.STARTING) { bundle.start(Bundle.START_TRANSIENT); } } }
Example 9
Source Project: packagedrone File: TagLibTracker.java License: Eclipse Public License 1.0 | 5 votes |
public TagLibTracker ( final BundleContext context, String mappedPrefix ) { this.systemTlds.add ( "org.apache.taglibs.standard-impl" ); if ( mappedPrefix == null ) { mappedPrefix = "/WEB-INF/"; } this.mappedPrefix = mappedPrefix; this.bundleTracker = new BundleTracker<> ( context, Bundle.RESOLVED | Bundle.ACTIVE, this.customizer ); this.bundleTracker.open (); }
Example 10
Source Project: xtext-eclipse File: Activator.java License: Eclipse Public License 2.0 | 5 votes |
private String getBundleInfo (Bundle bundle) { String state = null; switch (bundle.getState()) { case Bundle.UNINSTALLED: state = "UNINSTALLED"; break; case Bundle.INSTALLED: state = "INSTALLED"; break; case Bundle.RESOLVED: state = "RESOLVED"; break; case Bundle.STARTING: state = "STARTING"; break; case Bundle.STOPPING: state = "STOPPING"; break; case Bundle.ACTIVE: state = "ACTIVE"; break; } return bundle.getSymbolicName() + " " + bundle.getVersion() + " ["+state+"]"; }
Example 11
Source Project: flowable-engine File: Extender.java License: Apache License 2.0 | 5 votes |
/** * this method checks the initial bundle that are installed/active before bundle tracker is opened. * * @param b the bundle to check */ private void checkInitialBundle(Bundle b) { // If the bundle is active, check it if (b.getState() == Bundle.RESOLVED || b.getState() == Bundle.STARTING || b.getState() == Bundle.ACTIVE) { checkBundle(b); } }
Example 12
Source Project: concierge File: BundleStateResource.java License: Eclipse Public License 1.0 | 5 votes |
@Override public Representation put(final Representation value, final Variant variant) { try { final Bundle bundle = getBundleFromKeys(RestService.BUNDLE_ID_KEY); if (bundle == null) { setStatus(Status.CLIENT_ERROR_NOT_FOUND); return null; } final BundleStatePojo targetState = fromRepresentation(value, value.getMediaType()); if (bundle.getState() == Bundle.UNINSTALLED) { return ERROR(Status.CLIENT_ERROR_PRECONDITION_FAILED, "target state " + targetState.getState() + " not reachable from the current state"); } else if (targetState.getState() == Bundle.ACTIVE) { bundle.start(targetState.getOptions()); return getRepresentation( new BundleStatePojo(bundle.getState()), variant); } else if (targetState.getState() == Bundle.RESOLVED) { bundle.stop(targetState.getOptions()); return getRepresentation( new BundleStatePojo(bundle.getState()), variant); } else { return ERROR(Status.CLIENT_ERROR_BAD_REQUEST, "target state " + targetState.getState() + " not supported"); } } catch (final Exception e) { return ERROR(e, variant); } }
Example 13
Source Project: ignite File: ContainerSweepClassLoader.java License: Apache License 2.0 | 5 votes |
/** * Sweeps the OSGi container to find the first {@link Bundle} that can load the class. * * @param name The classname. * @return The loaded class. */ protected Class<?> sweepContainer(String name) { Class<?> cls = null; Bundle[] bundles = bundle.getBundleContext().getBundles(); int bundleIdx = 0; for (; bundleIdx < bundles.length; bundleIdx++) { Bundle b = bundles[bundleIdx]; // Skip bundles that haven't reached RESOLVED state; skip fragments. if (b.getState() <= Bundle.RESOLVED || b.getHeaders().get(Constants.FRAGMENT_HOST) != null) continue; try { cls = b.loadClass(name); break; } catch (ClassNotFoundException ignored) { // No-op. } } if (cls == null) nonResolvable.add(name); else resolved.put(name, bundles[bundleIdx]); return cls; }
Example 14
Source Project: concierge File: BundleImpl.java License: Eclipse Public License 1.0 | 5 votes |
void triggerActivation() { try { activate0(); } catch (final BundleException be) { // see spec 4.4.6.2 lazy activation policy state = Bundle.STOPPING; framework.notifyBundleListeners(BundleEvent.STOPPING, this); state = Bundle.RESOLVED; framework.notifyBundleListeners(BundleEvent.STOPPED, this); } }
Example 15
Source Project: knopflerfish.org File: SystemBundle.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * This method start a thread that stop this Framework, stopping all started * bundles. * * <p> * If the framework is not started, this method does nothing. If the framework * is started, this method will: * <ol> * <li>Set the state of the FrameworkContext to <i>inactive</i>.</li> * <li>Suspended all started bundles as described in the * {@link Bundle#stop(int)} method except that the persistent state of the * bundle will continue to be started. Reports any exceptions that occur * during stopping using <code>FrameworkErrorEvents</code>.</li> * <li>Disable event handling.</li> * </ol> * </p> * */ void shutdown(final boolean restart) { synchronized (lock) { boolean wasActive = false; switch (state) { case Bundle.INSTALLED: case Bundle.RESOLVED: shutdownDone(false); break; case Bundle.ACTIVE: wasActive = true; // Fall through case Bundle.STARTING: if (shutdownThread == null) { try { final boolean wa = wasActive; shutdownThread = new Thread(fwCtx.threadGroup, "Framework shutdown") { @Override public void run() { shutdown0(restart, wa); } }; shutdownThread.setDaemon(false); shutdownThread.start(); } catch (final Exception e) { systemShuttingdownDone(new FrameworkEvent(FrameworkEvent.ERROR, this, e)); } } break; case Bundle.STOPPING: // Shutdown already inprogress break; } } }
Example 16
Source Project: smarthome File: ResourceBundleTracker.java License: Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public ResourceBundleTracker(BundleContext bundleContext, LocaleProvider localeProvider) { super(bundleContext, Bundle.RESOLVED | Bundle.STARTING | Bundle.STOPPING | Bundle.ACTIVE, null); this.localeProvider = localeProvider; pkgAdmin = (PackageAdmin) bundleContext .getService(bundleContext.getServiceReference(PackageAdmin.class.getName())); this.bundleLanguageResourceMap = new LinkedHashMap<Bundle, LanguageResourceBundleManager>(); }
Example 17
Source Project: nexus-public File: FeaturesWrapper.java License: Eclipse Public License 1.0 | 5 votes |
/** * Start the installed bundle. */ private void startBundle(final Bundle bundle) { // ignore if bundle is already in the starting state or later if ((bundle.getState() & (Bundle.INSTALLED | Bundle.RESOLVED)) != 0) { try { log.debug("Starting {}/{}", bundle.getSymbolicName(), bundle.getVersion()); bundle.start(); log.debug("Started {}/{}", bundle.getSymbolicName(), bundle.getVersion()); } catch (BundleException e) { log.warn("Problem starting {}", bundle.getLocation(), e); } } }
Example 18
Source Project: flowable-engine File: Extender.java License: Apache License 2.0 | 4 votes |
public Extender(BundleContext context) { Extender.context = context; this.engineServiceTracker = new ServiceTracker(context, ProcessEngine.class.getName(), this); this.bundleTracker = new BundleTracker(context, Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE, this); }
Example 19
Source Project: concierge File: Concierge.java License: Eclipse Public License 1.0 | 4 votes |
/** * set the current startlevel but does not update the metadata. * * @param targetLevel * the startlevel. * */ protected void setLevel(final Bundle[] bundleArray, final int targetLevel, final boolean all) { if (startlevel == targetLevel) { return; } final boolean up = targetLevel > startlevel; final int levels = up ? targetLevel - startlevel : startlevel - targetLevel; final MultiMap<Integer, AbstractBundle> startLevels = new MultiMap<Integer, AbstractBundle>( 0); // prepare startlevels for (int i = 0; i < bundleArray.length; i++) { final AbstractBundle bundle = (AbstractBundle) bundleArray[i]; if (bundle == Concierge.this || bundle.state == Bundle.UNINSTALLED || up && bundle.autostart == AUTOSTART_STOPPED || !up && bundle.state == Bundle.RESOLVED) { continue; } final int offset; if (up) { offset = bundle.startlevel - startlevel - 1; } else { offset = startlevel - bundle.startlevel; } if (offset >= 0 && offset < levels) { startLevels.insert(new Integer(offset), bundle); } } for (int i = 0; i < levels; i++) { if (up) { startlevel++; } else { startlevel--; } final List<AbstractBundle> list = startLevels.get(new Integer(i)); if (list == null) { continue; } final BundleImpl[] toProcess = list .toArray(new BundleImpl[list.size()]); for (int j = 0; j < toProcess.length; j++) { try { if (up) { // transient is implicit toProcess[j] .activate(toProcess[j].isActivationPolicyUsed() ? Bundle.START_ACTIVATION_POLICY : 0); } else { if (toProcess[toProcess.length - j - 1] .getState() == Bundle.UNINSTALLED) { continue; } // transient is implicit toProcess[toProcess.length - j - 1].stopBundle(); } } catch (final BundleException be) { if (be.getNestedException() != null) { be.getNestedException().printStackTrace(); } be.printStackTrace(); notifyFrameworkListeners(FrameworkEvent.ERROR, up ? toProcess[j] : toProcess[toProcess.length - j - 1], be); } catch (final Throwable t) { t.printStackTrace(); notifyFrameworkListeners(FrameworkEvent.ERROR, up ? toProcess[j] : toProcess[toProcess.length - j - 1], t); } } } startlevel = targetLevel; }
Example 20
Source Project: concierge File: AbstractConciergeTestCase.java License: Eclipse Public License 1.0 | 4 votes |
/** Checks about Bundle RESOLVED or ACTIVE state. */ protected boolean isBundleResolved(final Bundle bundle) { return ((bundle.getState() == Bundle.RESOLVED) || (bundle.getState() == Bundle.ACTIVE)); }