Search in sources :

Example 81 with BundleCapability

use of org.osgi.framework.wiring.BundleCapability in project aries by apache.

the class BundleWiringStateMBeanTest method testGetRevisionsDeclaredCapabilities.

@Test
public void testGetRevisionsDeclaredCapabilities() throws Exception {
    BundleRevisions revisions = (BundleRevisions) bundleA.adapt(BundleRevisions.class);
    Assert.assertEquals("Precondition", 1, revisions.getRevisions().size());
    TabularData jmxCapabilitiesTable = brsMBean.getRevisionsDeclaredCapabilities(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
    Assert.assertEquals(1, jmxCapabilitiesTable.size());
    List<BundleCapability> capabilities = ((BundleRevision) revisions.getRevisions().iterator().next()).getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
    CompositeData jmxRevCapabilities = (CompositeData) jmxCapabilitiesTable.values().iterator().next();
    CompositeData[] jmxCapabilities = (CompositeData[]) jmxRevCapabilities.get(BundleWiringStateMBean.CAPABILITIES);
    Map<Map<String, Object>, Map<String, String>> expectedCapabilities = capabilitiesToMap(capabilities);
    Map<Map<String, Object>, Map<String, String>> actualCapabilities = jmxCapReqToMap(jmxCapabilities);
    Assert.assertEquals(expectedCapabilities, actualCapabilities);
}
Also used : CompositeData(javax.management.openmbean.CompositeData) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleCapability(org.osgi.framework.wiring.BundleCapability) HashMap(java.util.HashMap) Map(java.util.Map) BundleRevisions(org.osgi.framework.wiring.BundleRevisions) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Example 82 with BundleCapability

use of org.osgi.framework.wiring.BundleCapability in project aries by apache.

the class SubsystemResolverHook method filterMatches.

public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) {
    // Filter out candidates that don't come from preferred providers when
    // there is at least one preferred provider.
    // (1) Find the subsystem(s) containing requirement.getResource() as a
    // constituent.
    Collection<BasicSubsystem> requirers = subsystems.getSubsystemsReferencing(requirement.getResource());
    // (2) For each candidate, ask each subsystem if the candidate or any of
    // the candidate's containing subsystems is a preferred provider. If at
    // least one preferred provider exists, filter out all other candidates
    // that are not also preferred providers.
    Collection<BundleCapability> preferredProviders = new ArrayList<BundleCapability>(candidates.size());
    for (BundleCapability candidate : candidates) for (BasicSubsystem subsystem : requirers) {
        PreferredProviderHeader header = subsystem.getSubsystemManifest().getPreferredProviderHeader();
        if (header != null && (header.contains(candidate.getResource()) || isResourceConstituentOfPreferredSubsystem(candidate.getResource(), subsystem)))
            preferredProviders.add(candidate);
    }
    if (!preferredProviders.isEmpty())
        candidates.retainAll(preferredProviders);
}
Also used : ArrayList(java.util.ArrayList) BundleCapability(org.osgi.framework.wiring.BundleCapability) PreferredProviderHeader(org.apache.aries.subsystem.core.archive.PreferredProviderHeader)

Example 83 with BundleCapability

use of org.osgi.framework.wiring.BundleCapability 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)

Aggregations

BundleCapability (org.osgi.framework.wiring.BundleCapability)83 ArrayList (java.util.ArrayList)30 BundleRevision (org.osgi.framework.wiring.BundleRevision)26 HashMap (java.util.HashMap)24 Bundle (org.osgi.framework.Bundle)24 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)21 BundleWiring (org.osgi.framework.wiring.BundleWiring)19 BundleWire (org.osgi.framework.wiring.BundleWire)18 List (java.util.List)15 Version (org.osgi.framework.Version)12 BundleException (org.osgi.framework.BundleException)11 ResolverHook (org.osgi.framework.hooks.resolver.ResolverHook)11 Collection (java.util.Collection)10 Test (org.junit.Test)10 HashSet (java.util.HashSet)9 Set (java.util.Set)8 ResolverHookFactory (org.osgi.framework.hooks.resolver.ResolverHookFactory)8 LinkedHashMap (java.util.LinkedHashMap)6 Module (org.eclipse.osgi.container.Module)6 CompositeData (javax.management.openmbean.CompositeData)5