use of org.osgi.framework.wiring.BundleCapability in project aries by apache.
the class BundleWiringData method getWiresCompositeData.
private CompositeData[] getWiresCompositeData(List<BundleWire> wires) throws OpenDataException {
CompositeData[] reqWiresData = new CompositeData[wires.size()];
for (int i = 0; i < wires.size(); i++) {
BundleWire requiredWire = wires.get(i);
Map<String, Object> wireItems = new HashMap<String, Object>();
BundleCapability capability = requiredWire.getCapability();
wireItems.put(BundleWiringStateMBean.PROVIDER_BUNDLE_ID, capability.getRevision().getBundle().getBundleId());
wireItems.put(BundleWiringStateMBean.PROVIDER_BUNDLE_REVISION_ID, revisionIDMap.get(capability.getRevision()));
wireItems.put(BundleWiringStateMBean.BUNDLE_CAPABILITY, getCapReqCompositeData(BundleWiringStateMBean.BUNDLE_CAPABILITY_TYPE, capability.getNamespace(), capability.getAttributes().entrySet(), capability.getDirectives().entrySet()));
BundleRequirement requirement = requiredWire.getRequirement();
wireItems.put(BundleWiringStateMBean.REQUIRER_BUNDLE_ID, requirement.getRevision().getBundle().getBundleId());
wireItems.put(BundleWiringStateMBean.REQUIRER_BUNDLE_REVISION_ID, revisionIDMap.get(requirement.getRevision()));
wireItems.put(BundleWiringStateMBean.BUNDLE_REQUIREMENT, getCapReqCompositeData(BundleWiringStateMBean.BUNDLE_REQUIREMENT_TYPE, requirement.getNamespace(), requirement.getAttributes().entrySet(), requirement.getDirectives().entrySet()));
CompositeData wireData = new CompositeDataSupport(BundleWiringStateMBean.BUNDLE_WIRE_TYPE, wireItems);
reqWiresData[i] = wireData;
}
return reqWiresData;
}
use of org.osgi.framework.wiring.BundleCapability in project aries by apache.
the class JndiExtensionTests method testDisableExtensionAndCDIContainerWaits.
public void testDisableExtensionAndCDIContainerWaits() throws Exception {
BundleTracker<Bundle> bt = new BundleTracker<>(bundle.getBundleContext(), Bundle.RESOLVED | Bundle.ACTIVE, new BundleTrackerCustomizer<Bundle>() {
@Override
public Bundle addingBundle(Bundle bundle, BundleEvent arg1) {
List<BundleCapability> capabilities = bundle.adapt(BundleWiring.class).getCapabilities(CdiConstants.CDI_EXTENSION_NAMESPACE);
if (capabilities.isEmpty()) {
return null;
}
for (Capability capability : capabilities) {
if (capability.getAttributes().containsValue("jndi")) {
return bundle;
}
}
return null;
}
@Override
public void modifiedBundle(Bundle bundle, BundleEvent arg1, Bundle arg2) {
}
@Override
public void removedBundle(Bundle bundle, BundleEvent arg1, Bundle arg2) {
}
});
bt.open();
assertFalse(bt.isEmpty());
Bundle extensionBundle = bt.getBundles()[0];
Collection<ServiceReference<CdiContainer>> serviceReferences = bundleContext.getServiceReferences(CdiContainer.class, "(&(objectClass=" + CdiContainer.class.getName() + ")(service.bundleid=" + cdiBundle.getBundleId() + "))");
assertNotNull(serviceReferences);
assertFalse(serviceReferences.isEmpty());
ServiceReference<CdiContainer> serviceReference = serviceReferences.iterator().next();
CdiEvent.Type state = (CdiEvent.Type) serviceReference.getProperty(CdiConstants.CDI_CONTAINER_STATE);
assertEquals(CdiEvent.Type.CREATED, state);
extensionBundle.stop();
state = (CdiEvent.Type) serviceReference.getProperty(CdiConstants.CDI_CONTAINER_STATE);
assertEquals(CdiEvent.Type.WAITING_FOR_EXTENSIONS, state);
extensionBundle.start();
state = (CdiEvent.Type) serviceReference.getProperty(CdiConstants.CDI_CONTAINER_STATE);
assertEquals(CdiEvent.Type.CREATED, state);
}
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 BundleWiringStateMBeanTest method testGetCurrentRevisionDeclaredCapabilities.
@Test
public void testGetCurrentRevisionDeclaredCapabilities() throws Exception {
BundleRevision br = (BundleRevision) bundleA.adapt(BundleRevision.class);
List<BundleCapability> capabilities = br.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
CompositeData[] jmxCapabilities = brsMBean.getCurrentRevisionDeclaredCapabilities(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(capabilities.size(), jmxCapabilities.length);
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 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