Search in sources :

Example 6 with RegionFilter

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

the class WovenClassListener method addSharingPolicyUpdates.

private void addSharingPolicyUpdates(final DynamicImportPackageRequirement requirement, final BasicSubsystem scopedSubsystem, final Collection<BundleCapability> providers, Map<Region, RegionUpdaterInfo> updates) {
    final List<BasicSubsystem> subsystems = new ArrayList<BasicSubsystem>();
    final Map<Region, BasicSubsystem> regionToSubsystem = new HashMap<Region, BasicSubsystem>();
    regionToSubsystem(scopedSubsystem, regionToSubsystem);
    scopedSubsystem.getRegion().visitSubgraph(new RegionDigraphVisitor() {

        private final List<BasicSubsystem> visited = new ArrayList<BasicSubsystem>();

        @Override
        public void postEdgeTraverse(RegionFilter filter) {
        // Nothing.
        }

        @Override
        public boolean preEdgeTraverse(RegionFilter filter) {
            return true;
        }

        @Override
        public boolean visit(Region region) {
            BasicSubsystem subsystem = regionToSubsystem.get(region);
            if (subsystem == null || subsystem.isRoot()) {
                // sharing policy.
                return false;
            }
            if (!visited.isEmpty() && !subsystem.equals(scopedParent(visited.get(visited.size() - 1)))) {
                // We're only interested in walking up the scoped parent tree.
                return false;
            }
            visited.add(subsystem);
            if (!requirement.getPackageName().contains("*")) {
                for (BundleCapability provider : providers) {
                    BundleRevision br = provider.getResource();
                    if (region.contains(br.getBundle())) {
                        // satisfied.
                        return false;
                    }
                }
            }
            boolean allowed = false;
            Set<FilteredRegion> filters = region.getEdges();
            for (FilteredRegion filteredRegion : filters) {
                RegionFilter filter = filteredRegion.getFilter();
                if (filter.isAllowed(providers.iterator().next())) {
                    // The region already allows matching capabilities
                    // through so there is no need to update the sharing
                    // policy.
                    allowed = true;
                    break;
                }
            }
            if (!allowed) {
                // The subsystem region requires a sharing policy update.
                subsystems.add(subsystem);
            }
            // Visit the next region.
            return true;
        }
    });
    // Collect the information for the necessary sharing policy updates.
    for (BasicSubsystem subsystem : subsystems) {
        Region tail = subsystem.getRegion();
        Region head = scopedParent(subsystem).getRegion();
        RegionUpdaterInfo info = updates.get(tail);
        if (info == null) {
            info = new RegionUpdaterInfo(tail, head);
            updates.put(tail, info);
        }
        info.requirement(requirement);
    }
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RegionDigraphVisitor(org.eclipse.equinox.region.RegionDigraphVisitor) FilteredRegion(org.eclipse.equinox.region.RegionDigraph.FilteredRegion) RegionFilter(org.eclipse.equinox.region.RegionFilter) BundleRevision(org.osgi.framework.wiring.BundleRevision) Region(org.eclipse.equinox.region.Region) FilteredRegion(org.eclipse.equinox.region.RegionDigraph.FilteredRegion) BundleCapability(org.osgi.framework.wiring.BundleCapability)

Example 7 with RegionFilter

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

the class SubsystemResource method addSubsystemServiceImportToSharingPolicy.

private void addSubsystemServiceImportToSharingPolicy(RegionFilterBuilder builder, Region to) throws InvalidSyntaxException, BundleException, IOException, URISyntaxException {
    Region root = Activator.getInstance().getSubsystems().getRootSubsystem().getRegion();
    if (to.getName().equals(root.getName()))
        addSubsystemServiceImportToSharingPolicy(builder);
    else {
        to = root;
        builder = to.getRegionDigraph().createRegionFilterBuilder();
        addSubsystemServiceImportToSharingPolicy(builder);
        RegionFilter regionFilter = builder.build();
        getRegion().connectRegion(to, regionFilter);
    }
}
Also used : RegionFilter(org.eclipse.equinox.region.RegionFilter) Region(org.eclipse.equinox.region.Region)

Example 8 with RegionFilter

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

the class Aries1435Test method assertPackageFiltersInParentConnection.

private void assertPackageFiltersInParentConnection(Subsystem subsystem, Subsystem parent, int expectedEdges, int expectedFilters) {
    Region parentRegion = getRegion(parent);
    Region region = getRegion(subsystem);
    Set<FilteredRegion> edges = region.getEdges();
    assertEquals("Wrong number of edges", expectedEdges, edges.size());
    for (FilteredRegion edge : region.getEdges()) {
        if (!edge.getRegion().equals(parentRegion)) {
            continue;
        }
        RegionFilter filter = edge.getFilter();
        Map<String, Collection<String>> policy = filter.getSharingPolicy();
        Collection<String> packages = policy.get(PackageNamespace.PACKAGE_NAMESPACE);
        assertNotNull("Wrong number of packages", packages);
        assertEquals("Wrong number of packages", expectedFilters, packages.size());
        return;
    }
    fail("No connection to parent found");
}
Also used : FilteredRegion(org.eclipse.equinox.region.RegionDigraph.FilteredRegion) RegionFilter(org.eclipse.equinox.region.RegionFilter) Region(org.eclipse.equinox.region.Region) FilteredRegion(org.eclipse.equinox.region.RegionDigraph.FilteredRegion) Collection(java.util.Collection)

Aggregations

RegionFilter (org.eclipse.equinox.region.RegionFilter)8 Region (org.eclipse.equinox.region.Region)7 FilteredRegion (org.eclipse.equinox.region.RegionDigraph.FilteredRegion)3 RegionFilterBuilder (org.eclipse.equinox.region.RegionFilterBuilder)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 IOException (java.io.IOException)1 EnumSet (java.util.EnumSet)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)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 SubsystemContentHeader (org.apache.aries.subsystem.core.archive.SubsystemContentHeader)1 SubsystemImportServiceRequirement (org.apache.aries.subsystem.core.archive.SubsystemImportServiceRequirement)1 RegionDigraph (org.eclipse.equinox.region.RegionDigraph)1 RegionDigraphVisitor (org.eclipse.equinox.region.RegionDigraphVisitor)1 Bundle (org.osgi.framework.Bundle)1