Search in sources :

Example 1 with ArrayMap

use of org.eclipse.osgi.framework.util.ArrayMap in project rt.equinox.framework by eclipse.

the class OrderedExecutor method addLogListener.

void addLogListener(LogListener listener, LogFilter filter) {
    listenersLock.writeLock().lock();
    try {
        ArrayMap<LogListener, Object[]> listenersCopy = new ArrayMap<>(listeners.getKeys(), listeners.getValues());
        Object[] listenerObjects = listenersCopy.get(listener);
        if (listenerObjects == null) {
            // Only create a task queue for non-SynchronousLogListeners
            OrderedTaskQueue taskQueue = (listener instanceof SynchronousLogListener) ? null : executor.createQueue();
            listenerObjects = new Object[] { filter, taskQueue };
        } else if (filter != listenerObjects[0]) {
            // update the filter
            listenerObjects[0] = filter;
        }
        listenersCopy.put(listener, listenerObjects);
        recalculateFilters(listenersCopy);
        listeners = listenersCopy;
    } finally {
        listenersLock.writeLock().unlock();
    }
}
Also used : SynchronousLogListener(org.eclipse.equinox.log.SynchronousLogListener) LogListener(org.osgi.service.log.LogListener) SynchronousLogListener(org.eclipse.equinox.log.SynchronousLogListener) OrderedTaskQueue(org.eclipse.osgi.internal.log.OrderedExecutor.OrderedTaskQueue) ArrayMap(org.eclipse.osgi.framework.util.ArrayMap)

Example 2 with ArrayMap

use of org.eclipse.osgi.framework.util.ArrayMap in project rt.equinox.framework by eclipse.

the class ResolverImpl method resolve.

public synchronized void resolve(BundleDescription[] reRefresh, Dictionary<Object, Object>[] platformProperties) {
    if (DEBUG)
        // $NON-NLS-1$
        ResolverImpl.log("*** BEGIN RESOLUTION ***");
    if (state == null)
        // $NON-NLS-1$
        throw new IllegalStateException("RESOLVER_NO_STATE");
    // set developmentMode each resolution
    developmentMode = platformProperties.length == 0 ? false : StateImpl.DEVELOPMENT_MODE.equals(platformProperties[0].get(StateImpl.OSGI_RESOLVER_MODE));
    // set uses timeout each resolution
    usesTimeout = getUsesTimeout(platformProperties);
    // set limit for constraints with multiple suppliers each resolution
    usesMultipleSuppliersLimit = getMultipleSuppliersLimit(platformProperties);
    hook = (state instanceof StateImpl) ? ((StateImpl) state).getResolverHook() : null;
    if (!initialized) {
        initialize();
    }
    try {
        reRefresh = addDevConstraints(reRefresh);
        // Unresolve all the supplied bundles and their dependents
        if (reRefresh != null)
            for (int i = 0; i < reRefresh.length; i++) {
                ResolverBundle rb = bundleMapping.get(reRefresh[i]);
                if (rb != null)
                    unresolveBundle(rb, false);
            }
        // reorder exports and bundles after unresolving the bundles
        resolverExports.reorder();
        resolverBundles.reorder();
        reorderGenerics();
        // always get the latest EEs
        getCurrentEEs(platformProperties);
        // $NON-NLS-1$//$NON-NLS-2$
        boolean resolveOptional = platformProperties.length == 0 ? false : "true".equals(platformProperties[0].get("osgi.resolveOptional"));
        ResolverBundle[] currentlyResolved = null;
        if (resolveOptional) {
            BundleDescription[] resolvedBundles = state.getResolvedBundles();
            currentlyResolved = new ResolverBundle[resolvedBundles.length];
            for (int i = 0; i < resolvedBundles.length; i++) currentlyResolved[i] = bundleMapping.get(resolvedBundles[i]);
        }
        // attempt to resolve all unresolved bundles
        Collection<ResolverBundle> hookDisabled = Collections.EMPTY_LIST;
        if (hook != null) {
            List<ResolverBundle> resolvableBundles = new ArrayList<>(unresolvedBundles);
            List<BundleRevision> resolvableRevisions = new ArrayList<>(resolvableBundles.size());
            for (ResolverBundle bundle : resolvableBundles) resolvableRevisions.add(bundle.getBundleDescription());
            ArrayMap<BundleRevision, ResolverBundle> resolvable = new ArrayMap<>(resolvableRevisions, resolvableBundles);
            int size = resolvableBundles.size();
            hook.filterResolvable(resolvable);
            if (resolvable.size() < size) {
                hookDisabled = new ArrayList<>(unresolvedBundles);
                hookDisabled.removeAll(resolvableBundles);
            }
        }
        usesCalculationTimeout = false;
        List<ResolverBundle> toResolve = new ArrayList<>(unresolvedBundles);
        // first resolve the system bundle to allow osgi.ee capabilities to be resolved
        List<ResolverBundle> unresolvedSystemBundles = new ArrayList<>(1);
        String systemBSN = getSystemBundle();
        for (Iterator<ResolverBundle> iToResolve = toResolve.iterator(); iToResolve.hasNext(); ) {
            ResolverBundle rb = iToResolve.next();
            String symbolicName = rb.getName();
            if (symbolicName != null && symbolicName.equals(systemBSN)) {
                unresolvedSystemBundles.add(rb);
                iToResolve.remove();
            }
        }
        if (!unresolvedSystemBundles.isEmpty())
            resolveBundles(unresolvedSystemBundles.toArray(new ResolverBundle[unresolvedSystemBundles.size()]), platformProperties, hookDisabled);
        // Now resolve the rest
        resolveBundles(toResolve.toArray(new ResolverBundle[toResolve.size()]), platformProperties, hookDisabled);
        Collection<ResolverBundle> optionalResolved = resolveOptional ? resolveOptionalConstraints(currentlyResolved) : Collections.EMPTY_LIST;
        ResolverHook current = hook;
        if (current != null) {
            hook = null;
            current.end();
        }
        // set the resolved status of the bundles in the State
        // Note this must be done after calling end above in case end throws errors
        stateResolveBundles(bundleMapping.values().toArray(new ResolverBundle[bundleMapping.size()]));
        for (ResolverBundle bundle : optionalResolved) {
            state.resolveBundle(bundle.getBundleDescription(), false, null, null, null, null, null, null, null, null);
            stateResolveBundle(bundle);
        }
        // reorder exports and bundles after resolving the bundles
        resolverExports.reorder();
        resolverBundles.reorder();
        reorderGenerics();
        if (resolveOptional)
            resolveOptionalConstraints(currentlyResolved);
        if (DEBUG)
            // $NON-NLS-1$
            ResolverImpl.log("*** END RESOLUTION ***");
    } finally {
        if (hook != null)
            // need to make sure end is always called
            hook.end();
        hook = null;
    }
}
Also used : ResolverHook(org.osgi.framework.hooks.resolver.ResolverHook) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) StateImpl(org.eclipse.osgi.internal.resolver.StateImpl) ArrayList(java.util.ArrayList) ArrayMap(org.eclipse.osgi.framework.util.ArrayMap) VersionConstraint(org.eclipse.osgi.service.resolver.VersionConstraint) BundleRevision(org.osgi.framework.wiring.BundleRevision)

Aggregations

ArrayMap (org.eclipse.osgi.framework.util.ArrayMap)2 ArrayList (java.util.ArrayList)1 SynchronousLogListener (org.eclipse.equinox.log.SynchronousLogListener)1 OrderedTaskQueue (org.eclipse.osgi.internal.log.OrderedExecutor.OrderedTaskQueue)1 StateImpl (org.eclipse.osgi.internal.resolver.StateImpl)1 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)1 VersionConstraint (org.eclipse.osgi.service.resolver.VersionConstraint)1 ResolverHook (org.osgi.framework.hooks.resolver.ResolverHook)1 BundleRevision (org.osgi.framework.wiring.BundleRevision)1 LogListener (org.osgi.service.log.LogListener)1