Search in sources :

Example 1 with RegionFilterBuilder

use of org.eclipse.equinox.region.RegionFilterBuilder in project fabric8 by jboss-fuse.

the class SubsystemResolver method getFlatDigraph.

public RegionDigraph getFlatDigraph() throws BundleException, InvalidSyntaxException {
    if (flatDigraph == null) {
        flatDigraph = new StandardRegionDigraph(null, null);
        Map<String, String> flats = getFlatSubsystemsMap();
        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) Collection(java.util.Collection) RegionFilterBuilder(org.eclipse.equinox.region.RegionFilterBuilder) HashMap(java.util.HashMap) DictionaryAsMap(org.apache.felix.utils.collections.DictionaryAsMap) Map(java.util.Map) StandardRegionDigraph(org.eclipse.equinox.internal.region.StandardRegionDigraph)

Example 2 with RegionFilterBuilder

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

the class SubsystemResource method setImportIsolationPolicy.

private void setImportIsolationPolicy() throws BundleException, IOException, InvalidSyntaxException, URISyntaxException {
    if (isRoot() || !isScoped())
        return;
    Region region = getRegion();
    Region from = region;
    RegionFilterBuilder builder = from.getRegionDigraph().createRegionFilterBuilder();
    Region to = getParents().iterator().next().getRegion();
    addSubsystemServiceImportToSharingPolicy(builder, to);
    // TODO Is this check really necessary? Looks like it was done at the beginning of this method.
    if (isScoped()) {
        // Both applications and composites have Import-Package headers that require processing.
        // In the case of applications, the header is generated.
        Header<?> header = getSubsystemManifest().getImportPackageHeader();
        setImportIsolationPolicy(builder, (ImportPackageHeader) header);
        // Both applications and composites have Require-Capability headers that require processing.
        // In the case of applications, the header is generated.
        header = getSubsystemManifest().getRequireCapabilityHeader();
        setImportIsolationPolicy(builder, (RequireCapabilityHeader) header);
        // Both applications and composites have Subsystem-ImportService headers that require processing.
        // In the case of applications, the header is generated.
        header = getSubsystemManifest().getSubsystemImportServiceHeader();
        setImportIsolationPolicy(builder, (SubsystemImportServiceHeader) header);
        header = getSubsystemManifest().getRequireBundleHeader();
        setImportIsolationPolicy(builder, (RequireBundleHeader) header);
        // Always add access to osgi.ee and osgi.native namespaces
        setImplicitAccessToNativeAndEECapabilities(builder);
    }
    RegionFilter regionFilter = builder.build();
    from.connectRegion(to, regionFilter);
}
Also used : RegionFilter(org.eclipse.equinox.region.RegionFilter) Region(org.eclipse.equinox.region.Region) RegionFilterBuilder(org.eclipse.equinox.region.RegionFilterBuilder)

Example 3 with RegionFilterBuilder

use of org.eclipse.equinox.region.RegionFilterBuilder 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 4 with RegionFilterBuilder

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

the class SubsystemResource method setImportIsolationPolicy.

private void setImportIsolationPolicy(Map<Resource, List<Wire>> resolution) throws Exception {
    if (!isApplication()) {
        return;
    }
    SubsystemContentHeader contentHeader = getSubsystemManifest().getSubsystemContentHeader();
    // Prepare the regions and filter builder to set the sharing policy.
    Region from = getRegion();
    Region to = ((BasicSubsystem) getParents().iterator().next()).getRegion();
    RegionFilterBuilder builder = from.getRegionDigraph().createRegionFilterBuilder();
    // Always provide visibility to this subsystem's service registration.
    addSubsystemServiceImportToSharingPolicy(builder, to);
    for (Resource resource : resolution.keySet()) {
        if (!contentHeader.contains(resource)) {
            continue;
        }
        // If the resource is content but the wire provider is not,
        // the sharing policy must be updated.
        List<Wire> wires = resolution.get(resource);
        for (Wire wire : wires) {
            Resource provider = wire.getProvider();
            // visible.
            if (contentHeader.contains(provider)) {
                continue;
            }
            // requirements become part of the sharing policy.
            if (!(wire.getCapability() instanceof DependencyCalculator.MissingCapability) && Constants.ResourceTypeSynthesized.equals(ResourceHelper.getTypeAttribute(provider))) {
                continue;
            }
            // The requirement must be added to the sharing policy.
            Requirement requirement = wire.getRequirement();
            List<String> namespaces = new ArrayList<String>(2);
            namespaces.add(requirement.getNamespace());
            if (ServiceNamespace.SERVICE_NAMESPACE.equals(namespaces.get(0))) {
                // Both service capabilities and services must be visible.
                namespaces.add(RegionFilter.VISIBLE_SERVICE_NAMESPACE);
            }
            String filter = requirement.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE);
            if (filter == null) {
                for (String namespace : namespaces) builder.allowAll(namespace);
            } else {
                for (String namespace : namespaces) builder.allow(namespace, filter);
            }
        }
    }
    // Always add access to osgi.ee and osgi.native namespaces
    setImplicitAccessToNativeAndEECapabilities(builder);
    // Now set the sharing policy, if the regions are different.
    RegionFilter regionFilter = builder.build();
    from.connectRegion(to, regionFilter);
}
Also used : Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) Wire(org.osgi.resource.Wire) SubsystemContentHeader(org.apache.aries.subsystem.core.archive.SubsystemContentHeader) RequireBundleRequirement(org.apache.aries.subsystem.core.archive.RequireBundleRequirement) Requirement(org.osgi.resource.Requirement) RequireCapabilityRequirement(org.apache.aries.subsystem.core.archive.RequireCapabilityRequirement) ImportPackageRequirement(org.apache.aries.subsystem.core.archive.ImportPackageRequirement) SubsystemImportServiceRequirement(org.apache.aries.subsystem.core.archive.SubsystemImportServiceRequirement) RegionFilter(org.eclipse.equinox.region.RegionFilter) Region(org.eclipse.equinox.region.Region) RegionFilterBuilder(org.eclipse.equinox.region.RegionFilterBuilder)

Example 5 with RegionFilterBuilder

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

the class SubsystemResolver method getFlatDigraph.

@Override
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) Collection(java.util.Collection) RegionFilterBuilder(org.eclipse.equinox.region.RegionFilterBuilder) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DictionaryAsMap(org.apache.felix.utils.collections.DictionaryAsMap) StandardRegionDigraph(org.eclipse.equinox.internal.region.StandardRegionDigraph)

Aggregations

RegionFilterBuilder (org.eclipse.equinox.region.RegionFilterBuilder)9 Region (org.eclipse.equinox.region.Region)8 HashMap (java.util.HashMap)5 Map (java.util.Map)5 RegionDigraph (org.eclipse.equinox.region.RegionDigraph)4 Collection (java.util.Collection)3 StandardRegionDigraph (org.eclipse.equinox.internal.region.StandardRegionDigraph)3 RegionFilter (org.eclipse.equinox.region.RegionFilter)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 DictionaryAsMap (org.apache.felix.utils.collections.DictionaryAsMap)2 BundleException (org.osgi.framework.BundleException)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ImportPackageRequirement (org.apache.aries.subsystem.core.archive.ImportPackageRequirement)1 RequireBundleRequirement (org.apache.aries.subsystem.core.archive.RequireBundleRequirement)1 RequireCapabilityRequirement (org.apache.aries.subsystem.core.archive.RequireCapabilityRequirement)1