Java Code Examples for org.osgi.framework.Bundle#STOPPING

The following examples show how to use org.osgi.framework.Bundle#STOPPING . 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: netbeans   File: Activator.java    License: Apache License 2.0 6 votes vote down vote up
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;
        }
    }
 
Example 2
Source Project: wisdom   File: BundleStates.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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.
    }
}
 
Example 3
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 4
Source Project: wisdom   File: BundleStates.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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) + ")";
    }
}
 
Example 5
/** 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;
	}
}
 
Example 6
/**
 * 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() + "> ";
  }
}
 
Example 7
@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();
}
 
Example 8
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;
  }
}
 
Example 9
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;
}
 
Example 10
Source Project: netbeans   File: OSGiMainLookup.java    License: Apache License 2.0 5 votes vote down vote up
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 11
Source Project: xtext-eclipse   File: Activator.java    License: Eclipse Public License 2.0 5 votes vote down vote up
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 12
Source Project: cxf   File: CXFExtensionBundleListener.java    License: Apache License 2.0 5 votes vote down vote up
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 13
@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<>();
}
 
Example 14
@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 15
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 16
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;
}
 
Example 17
Source Project: tomee   File: ServiceManagerExtender.java    License: Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 18
Source Project: concierge   File: BundleImpl.java    License: Eclipse Public License 1.0 4 votes vote down vote up
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();
	} 
}
 
Example 19
Source Project: concierge   File: BundleImpl.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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
		}
	}
}
 
Example 20
@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);
}