org.osgi.framework.Bundle#RESOLVED源码实例Demo

下面列出了org.osgi.framework.Bundle#RESOLVED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: packagedrone   文件: DefaultAddonRegistration.java
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 );
    }
}
 
源代码2 项目: knopflerfish.org   文件: Desktop.java
/**
 * 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();
}
 
源代码3 项目: cxf   文件: CXFExtensionBundleListener.java
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);
        }
    }
}
 
源代码4 项目: openhab-core   文件: XmlDocumentBundleTracker.java
@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();
}
 
源代码5 项目: netbeans   文件: OSGiMainLookup.java
public @Override boolean isEnabled() {
    switch (b.getState()) {
    case Bundle.RESOLVED:
    case Bundle.ACTIVE:
    case Bundle.STARTING:
    case Bundle.STOPPING:
        return true;
    default:
        return false;
    }
}
 
源代码6 项目: orion.server   文件: Activator.java
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);

			}
		}
	}
}
 
源代码7 项目: knopflerfish.org   文件: StartLevelController.java
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);
  }
}
 
源代码8 项目: orion.server   文件: ServerTestsActivator.java
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);
		}
	}
}
 
源代码9 项目: packagedrone   文件: TagLibTracker.java
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 ();
}
 
源代码10 项目: xtext-eclipse   文件: Activator.java
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+"]";
}
 
源代码11 项目: flowable-engine   文件: Extender.java
/**
 * 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);
    }
}
 
源代码12 项目: concierge   文件: BundleStateResource.java
@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);
	}
}
 
源代码13 项目: ignite   文件: ContainerSweepClassLoader.java
/**
 * 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;
}
 
源代码14 项目: concierge   文件: BundleImpl.java
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);
	}
}
 
源代码15 项目: knopflerfish.org   文件: SystemBundle.java
/**
 * 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;
    }
  }
}
 
源代码16 项目: smarthome   文件: ResourceBundleTracker.java
@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>();
}
 
源代码17 项目: nexus-public   文件: FeaturesWrapper.java
/**
 * 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);
    }
  }
}
 
源代码18 项目: flowable-engine   文件: Extender.java
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);
}
 
源代码19 项目: concierge   文件: Concierge.java
/**
 * 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;
}
 
源代码20 项目: concierge   文件: AbstractConciergeTestCase.java
/** Checks about Bundle RESOLVED or ACTIVE state. */
protected boolean isBundleResolved(final Bundle bundle) {
	return ((bundle.getState() == Bundle.RESOLVED)
			|| (bundle.getState() == Bundle.ACTIVE));
}