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);
}
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);
}
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);
}
}
Aggregations