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

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

源代码1 项目: netbeans   文件: Activator.java
public @Override void bundleChanged(BundleEvent event) {
        Bundle bundle = event.getBundle();
        switch (event.getType()) {
        case BundleEvent.STARTED:
//            System.err.println("started " + bundle.getSymbolicName());
            Dictionary<?,?> headers = bundle.getHeaders();
            load(queue.offer(bundle, provides(headers), requires(headers), needs(headers)));
            break;
        case BundleEvent.STOPPED:
//            System.err.println("stopped " + bundle.getSymbolicName());
            if (framework.getState() == Bundle.STOPPING) {
//                System.err.println("fwork stopping during " + bundle.getSymbolicName());
//                ActiveQueue.stop();
            } else {
                unload(queue.retract(bundle));
            }
            break;
        }
    }
 
源代码2 项目: wisdom   文件: BundleStates.java
/**
 * Gets the OSGi state from the string form.
 *
 * @param state the state as String
 * @return the OSGi bundle state
 */
public static int from(String state) {
    switch (state.toUpperCase()) {
        case ACTIVE:
            return Bundle.ACTIVE;
        case INSTALLED:
            return Bundle.INSTALLED;
        case RESOLVED:
            return Bundle.RESOLVED;
        case STARTING:
            return Bundle.STARTING;
        case STOPPING:
            return Bundle.STOPPING;
        case UNINSTALLED:
            return Bundle.UNINSTALLED;
        default:
            return -1; // Unknown.
    }
}
 
源代码3 项目: 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 );
    }
}
 
源代码4 项目: wisdom   文件: BundleStates.java
/**
 * Gets the String form of the given OSGi bundle state.
 *
 * @param state the state
 * @return the string form.
 */
public static String from(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 "UNKNOWN (" + Integer.toString(state) + ")";
    }
}
 
源代码5 项目: concierge   文件: AbstractConciergeTestCase.java
/** Returns bundle state as readable string. */
protected String getBundleStateAsString(final int state) {
	switch (state) {
	case Bundle.INSTALLED:
		return "INSTALLED";
	case Bundle.RESOLVED:
		return "RESOLVED";
	case Bundle.ACTIVE:
		return "ACTIVE";
	case Bundle.STARTING:
		return "STARTING";
	case Bundle.STOPPING:
		return "STOPPING";
	case Bundle.UNINSTALLED:
		return "UNINSTALLED";
	default:
		return "UNKNOWN state: " + state;
	}
}
 
源代码6 项目: knopflerfish.org   文件: Util.java
/**
 * Get bundle state as a constant length string. Show state left adjusted as
 * 12 character string.
 *
 * @param bundle
 *          the bundle
 * @return The bundles state
 */
public static String showState(Bundle bundle)
{
  switch (bundle.getState()) {
  case Bundle.INSTALLED:
    return "installed   ";
  case Bundle.RESOLVED:
    return "resolved    ";
  case Bundle.STARTING:
    return "starting    ";
  case Bundle.ACTIVE:
    return "active      ";
  case Bundle.STOPPING:
    return "stopping    ";
  case Bundle.UNINSTALLED:
    return "uninstalled ";
  default:
    return "ILLEGAL <" + bundle.getState() + "> ";
  }
}
 
源代码7 项目: smarthome   文件: 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 Object addingBundle(Bundle bundle, BundleEvent event) {
            return withLock(lockOpenState.readLock(),
                    () -> openState == OpenState.OPENED && isBundleRelevant(bundle) ? bundle : null);
        }
    };
    relevantBundlesTracker.open();

    super.open();
}
 
源代码8 项目: knopflerfish.org   文件: Util.java
public static String stateName(int state)
{
  switch (state) {
  case Bundle.ACTIVE:
    return "active";
  case Bundle.INSTALLED:
    return "installed";
  case Bundle.UNINSTALLED:
    return "uninstalled";
  case Bundle.RESOLVED:
    return "resolved";
  case Bundle.STARTING:
    return "starting";
  case Bundle.STOPPING:
    return "stopping";
  default:
    return "unknown " + state;
  }
}
 
源代码9 项目: knopflerfish.org   文件: Spin.java
public static Color getColor(int state) {
  switch(state) {
  case Bundle.INSTALLED:
    return installedColor;
  case Bundle.ACTIVE:
    return activeColor;
  case Bundle.RESOLVED:
    return resolvedColor;
  case Bundle.UNINSTALLED:
    return uninstalledColor;
  case Bundle.STARTING:
    return startingColor;
  case Bundle.STOPPING:
    return stoppingColor;
  }

  return Color.black;
}
 
源代码10 项目: 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;
    }
}
 
源代码11 项目: 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+"]";
}
 
源代码12 项目: 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);
        }
    }
}
 
源代码13 项目: openhab-core   文件: 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<>();
}
 
源代码14 项目: 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();
}
 
源代码15 项目: 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);
  }
}
 
源代码16 项目: knopflerfish.org   文件: BundleImpl.java
boolean triggersActivationCls(String name) {
  if (Bundle.STOPPING != fwCtx.systemBundle.getState() && state == Bundle.STARTING
      && operation != ACTIVATING) {
    String pkg = "";
    final int pos = name.lastIndexOf('.');
    if (pos != -1) {
      pkg = name.substring(0, pos);
    }
    return current().isPkgActivationTrigger(pkg);
  }
  return false;
}
 
源代码17 项目: tomee   文件: ServiceManagerExtender.java
@Override
public void init() throws Exception {
    if (started != null && started.equals(Boolean.TRUE)) {
        throw new IllegalStateException("ServiceManager is already initialized");
    }
    final DiscoveryRegistry registry = new DiscoveryRegistry();
    SystemInstance.get().setComponent(DiscoveryRegistry.class, registry);

    started = Boolean.FALSE;
    stopped = false;
    final ServerServiceTracker t = new ServerServiceTracker();
    tracker = new BundleTracker(bundleContext, Bundle.ACTIVE | Bundle.STOPPING, t);
    tracker.open();
}
 
源代码18 项目: concierge   文件: BundleImpl.java
public BundleImpl(final Concierge framework,
		final BundleContext installingContext, final String location,
		final long bundleId, final InputStream stream)
				throws BundleException {
	this.framework = framework;
	this.location = location;
	this.bundleId = bundleId;
	this.startlevel = framework.initStartlevel;
	this.lastModified = System.currentTimeMillis();

	if (framework.SECURITY_ENABLED) {
		try {
			final PermissionCollection permissions = new Permissions();
			permissions.add(new FilePermission(
					framework.STORAGE_LOCATION + bundleId,
					"read,write,execute,delete"));
			domain = new ProtectionDomain(
					new CodeSource(
							new URL("file:" + framework.STORAGE_LOCATION
									+ bundleId),
							(java.security.cert.Certificate[]) null),
					permissions);
		} catch (final Exception e) {
			e.printStackTrace();
			throw new BundleException("Exception while installing bundle",
					BundleException.STATECHANGE_ERROR, e);
		}
	}

	this.storageLocation = framework.STORAGE_LOCATION + bundleId
			+ File.separatorChar;

	currentRevision = readAndProcessInputStream(stream);
	symbolicName = currentRevision.getSymbolicName();
	version = currentRevision.getVersion();
	revisions.add(0, currentRevision);

	// check is same version is already installed
	framework.checkForCollision(CollisionHook.INSTALLING,
			installingContext.getBundle(), currentRevision);

	install();
	
	// if we are not during startup (in case of restart) or shutdown, update the metadata
	if ((framework.state != Bundle.STARTING || !framework.restart)
			&& framework.state != Bundle.STOPPING) {
		updateMetadata();
	} 
}
 
源代码19 项目: concierge   文件: BundleImpl.java
/**
 * update the bundle from an input stream.
 * 
 * @param stream
 *            the stream.
 * @throws BundleException
 *             if something goes wrong.
 * @see org.osgi.framework.Bundle#update(java.io.InputStream)
 * @category Bundle
 */
public synchronized void update(final InputStream stream)
		throws BundleException {
	lastModified = System.currentTimeMillis();

	try {
		if (framework.SECURITY_ENABLED) {
			// TODO: check AdminPermission(this, LIFECYCLE)
		}

		if (state == UNINSTALLED) {
			throw new IllegalStateException(
					"Cannot update uninstalled bundle " + toString());
		}
		
		final Revision updatedRevision = readAndProcessInputStream(stream);

		boolean wasActive = false;
		if (state == ACTIVE) {
			// so we have to restart it after update
			wasActive = true;
			stop();
		}

		if (currentRevision.isFragment()) {
			state = INSTALLED;
			framework.removeFragment(currentRevision);
			framework.notifyBundleListeners(BundleEvent.UPDATED, this);
		} else {
			updateLastModified();

			if (currentRevision != null) {
				// do not close here, e.g. old wirings should still be
				// available
				currentRevision.cleanup(false);
			}
		}

		framework.checkForCollision(CollisionHook.UPDATING, this,
				updatedRevision);

		framework.symbolicName_bundles
				.remove(currentRevision.getSymbolicName(), this);
		currentRevision = updatedRevision;
		symbolicName = currentRevision.getSymbolicName();
		version = currentRevision.getVersion();
		revisions.add(0, updatedRevision);
		framework.symbolicName_bundles
				.insert(currentRevision.getSymbolicName(), this);

		if (!currentRevision.isFragment()) {
			currentRevision.resolve(false);
		}

		framework.notifyBundleListeners(BundleEvent.UPDATED, this);

		if (wasActive) {
			try {
				start();
			} catch (final BundleException be) {
				// TODO: to log
			}
		}
		if ((framework.state != Bundle.STARTING || !framework.restart)
				&& framework.state != Bundle.STOPPING) {
			updateMetadata();
		}
	} finally {
		try {
			stream.close();
		} catch (final IOException e) {
			// ignore
		}
	}
}
 
源代码20 项目: nexus-public   文件: NexusBundleTracker.java
@Override
protected boolean evictBundle(final Bundle bundle) {
  // force eviction while extender is closing; otherwise only allow it while the framework is stable
  return closing || (super.evictBundle(bundle) && (systemBundle.getState() & Bundle.STOPPING) == 0);
}