Search in sources :

Example 1 with RegionDigraph

use of org.eclipse.equinox.region.RegionDigraph in project aries by apache.

the class Activator method removedService.

@Override
public synchronized void removedService(ServiceReference<Object> reference, Object service) {
    if (service instanceof Coordinator) {
        if (service.equals(coordinator)) {
            Coordinator coordinator = findAlternateServiceFor(Coordinator.class);
            if (coordinator == null)
                deactivate();
            this.coordinator = coordinator;
        }
    } else if (service instanceof RegionDigraph) {
        if (service.equals(regionDigraph)) {
            RegionDigraph regionDigraph = findAlternateServiceFor(RegionDigraph.class);
            if (regionDigraph == null)
                deactivate();
            this.regionDigraph = regionDigraph;
        }
    } else if (service instanceof Resolver) {
        if (service.equals(resolver)) {
            Resolver resolver = findAlternateServiceFor(Resolver.class);
            if (resolver == null)
                deactivate();
            this.resolver = resolver;
        }
    } else if (service instanceof IDirectoryFinder)
        finders.remove(service);
    else {
        if (service.equals(modelledResourceManager)) {
            try {
                Class clazz = getClass().getClassLoader().loadClass(MODELLED_RESOURCE_MANAGER);
                Object manager = findAlternateServiceFor(clazz);
                if (manager == null) {
                    modelledResourceManager = null;
                    serviceModeller = null;
                } else {
                    modelledResourceManager = service;
                    serviceModeller = new ApplicationServiceModeller(service);
                }
            } catch (ClassNotFoundException e) {
            // ignore
            } catch (NoClassDefFoundError e) {
            // ignore
            }
        }
    }
}
Also used : RegionDigraph(org.eclipse.equinox.region.RegionDigraph) Resolver(org.osgi.service.resolver.Resolver) IDirectoryFinder(org.apache.aries.util.filesystem.IDirectoryFinder) Coordinator(org.osgi.service.coordinator.Coordinator)

Example 2 with RegionDigraph

use of org.eclipse.equinox.region.RegionDigraph in project aries by apache.

the class RegionUpdater method addRequirements.

public void addRequirements(Collection<? extends Requirement> requirements) throws BundleException, InvalidSyntaxException {
    for (int i = 0; i < MAX_ATTEMPTS_DEFAULT; i++) {
        RegionDigraph copy = copyDigraph();
        Region tail = copyTail(copy);
        Region head = copyHead(copy);
        Set<Long> bundleIds = copyBundleIds(tail);
        Map<String, RegionFilterBuilder> heads = copyHeadRegions(tail, copy);
        Map<String, RegionFilterBuilder> tails = copyTailRegions(tail, copy);
        copy.removeRegion(tail);
        tail = copy.createRegion(tail.getName());
        addBundleIds(bundleIds, tail);
        RegionFilterBuilder builder = heads.get(head.getName());
        if (builder == null) {
            // See ARIES-1429.
            throw new IllegalStateException(new StringBuilder(tail.getName()).append(" not connected to ").append(head.getName()).toString());
        }
        if (requirements == null) {
            heads.put(head.getName(), null);
        } else {
            addRequirements(requirements, builder);
        }
        addHeadRegions(heads, tail, copy);
        addTailRegions(tails, tail, copy);
        // Replace the current digraph.
        try {
            digraph.replace(copy);
        } catch (BundleException e) {
            // Something modified digraph since the copy was made.
            if (i < MAX_ATTEMPTS_DEFAULT)
                // There are more attempts to make.
                continue;
            // Number of attempts has been exhausted.
            throw e;
        }
        // Success! No need to continue looping.
        break;
    }
}
Also used : RegionDigraph(org.eclipse.equinox.region.RegionDigraph) FilteredRegion(org.eclipse.equinox.region.RegionDigraph.FilteredRegion) Region(org.eclipse.equinox.region.Region) BundleException(org.osgi.framework.BundleException) RegionFilterBuilder(org.eclipse.equinox.region.RegionFilterBuilder)

Example 3 with RegionDigraph

use of org.eclipse.equinox.region.RegionDigraph in project aries by apache.

the class SubsystemResource method createRegion.

private Region createRegion(long id) throws BundleException {
    if (!isScoped())
        return getParents().iterator().next().getRegion();
    Activator activator = Activator.getInstance();
    RegionDigraph digraph = activator.getRegionDigraph();
    if (getParents().isEmpty())
        // the subsystems implementation bundle was installed.
        return digraph.getRegion(activator.getBundleContext().getBundle());
    String name = getSubsystemManifest().getSubsystemSymbolicNameHeader().getSymbolicName() + ';' + getSubsystemManifest().getSubsystemVersionHeader().getVersion() + ';' + getSubsystemManifest().getSubsystemTypeHeader().getType() + ';' + Long.toString(id);
    Region region = digraph.getRegion(name);
    // install, but there's no access to the coordination here.
    if (region == null)
        return digraph.createRegion(name);
    return region;
}
Also used : RegionDigraph(org.eclipse.equinox.region.RegionDigraph) Region(org.eclipse.equinox.region.Region)

Example 4 with RegionDigraph

use of org.eclipse.equinox.region.RegionDigraph in project aries by apache.

the class SubsystemTest method removeConnectionWithParent.

protected void removeConnectionWithParent(Subsystem subsystem) throws BundleException {
    Region tail = getRegion(subsystem);
    RegionDigraph digraph = tail.getRegionDigraph();
    RegionDigraph copy = digraph.copy();
    Region tailCopy = copy.getRegion(tail.getName());
    Set<Long> ids = tail.getBundleIds();
    copy.removeRegion(tailCopy);
    tailCopy = copy.createRegion(tailCopy.getName());
    for (long id : ids) {
        tailCopy.addBundle(id);
    }
    digraph.replace(copy);
}
Also used : RegionDigraph(org.eclipse.equinox.region.RegionDigraph) Region(org.eclipse.equinox.region.Region)

Example 5 with RegionDigraph

use of org.eclipse.equinox.region.RegionDigraph in project karaf by apache.

the class SubsystemResolver method getFlatDigraph.

public RegionDigraph getFlatDigraph() throws BundleException, InvalidSyntaxException {
    if (flatDigraph == null) {
        flatDigraph = new StandardRegionDigraph(null, null);
        Map<String, String> flats = getFlatSubsystemsMap();
        if (digraph != null) {
            for (Region r : digraph.getRegions()) {
                if (r.getName().equals(flats.get(r.getName()))) {
                    flatDigraph.createRegion(r.getName());
                }
            }
            for (Region r : digraph.getRegions()) {
                for (RegionDigraph.FilteredRegion fr : digraph.getEdges(r)) {
                    String rt = flats.get(r.getName());
                    String rh = flats.get(fr.getRegion().getName());
                    if (!rh.equals(rt)) {
                        Region tail = flatDigraph.getRegion(rt);
                        Region head = flatDigraph.getRegion(rh);
                        RegionFilterBuilder rfb = flatDigraph.createRegionFilterBuilder();
                        for (Map.Entry<String, Collection<String>> entry : fr.getFilter().getSharingPolicy().entrySet()) {
                            // Discard osgi.identity namespace
                            if (!IDENTITY_NAMESPACE.equals(entry.getKey())) {
                                for (String f : entry.getValue()) {
                                    rfb.allow(entry.getKey(), f);
                                }
                            }
                        }
                        flatDigraph.connect(tail, rfb.build(), head);
                    }
                }
            }
        }
    }
    return flatDigraph;
}
Also used : StandardRegionDigraph(org.eclipse.equinox.internal.region.StandardRegionDigraph) RegionDigraph(org.eclipse.equinox.region.RegionDigraph) Region(org.eclipse.equinox.region.Region) RegionFilterBuilder(org.eclipse.equinox.region.RegionFilterBuilder) DictionaryAsMap(org.apache.felix.utils.collections.DictionaryAsMap) StandardRegionDigraph(org.eclipse.equinox.internal.region.StandardRegionDigraph)

Aggregations

RegionDigraph (org.eclipse.equinox.region.RegionDigraph)16 Region (org.eclipse.equinox.region.Region)14 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Set (java.util.Set)4 Bundle (org.osgi.framework.Bundle)4 Subsystem (org.osgi.service.subsystem.Subsystem)4 MapUtils.addToMapSet (org.apache.karaf.features.internal.util.MapUtils.addToMapSet)3 StandardRegionDigraph (org.eclipse.equinox.internal.region.StandardRegionDigraph)3 RegionFilterBuilder (org.eclipse.equinox.region.RegionFilterBuilder)3 BundleException (org.osgi.framework.BundleException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 LinkedHashMap (java.util.LinkedHashMap)2 AriesSubsystem (org.apache.aries.subsystem.AriesSubsystem)2 BasicSubsystem (org.apache.aries.subsystem.core.internal.BasicSubsystem)2 Feature (org.apache.karaf.features.Feature)2 Test (org.junit.Test)2