org.osgi.framework.hooks.bundle.CollisionHook Java Examples

The following examples show how to use org.osgi.framework.hooks.bundle.CollisionHook. 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: BundleHooks.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
void filterCollisions(int mode,
                      Bundle b,
                      Collection<Bundle> bundles) {
  final List<ServiceRegistrationImpl<?>> srl = fwCtx.services.get(CollisionHook.class.getName());
  if (srl != null) {
    final RemoveOnlyCollection<Bundle> filtered
      = new RemoveOnlyCollection<Bundle>(bundles);

    for (final ServiceRegistrationImpl<?> serviceRegistrationImpl : srl) {
      final ServiceReferenceImpl<?> sr = serviceRegistrationImpl.reference;
      final CollisionHook ch = (CollisionHook) sr.getService();
      if (ch != null) {
        try {
          ch.filterCollisions(mode, b, filtered);
        } catch (final Exception e) {
          fwCtx.frameworkError(b,
              new BundleException("Failed to call Bundle CollisionHook #" +
                                  sr.getProperty(Constants.SERVICE_ID), e));
        }
      }
    }
  }
}
 
Example #2
Source File: BundleCollisionHook.java    From vespa with Apache License 2.0 5 votes vote down vote up
public void start(BundleContext context) {
    if (registration != null) {
        throw new IllegalStateException();
    }
    String[] serviceClasses = {CollisionHook.class.getName(), EventHook.class.getName(), FindHook.class.getName()};
    registration = context.registerService(serviceClasses, this, null);
}
 
Example #3
Source File: BundleImpl.java    From concierge with 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 #4
Source File: BundleImpl.java    From concierge with 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
		}
	}
}