Search in sources :

Example 16 with BundleCapability

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;
}
Also used : HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) BundleCapability(org.osgi.framework.wiring.BundleCapability) BundleWire(org.osgi.framework.wiring.BundleWire) BundleRequirement(org.osgi.framework.wiring.BundleRequirement)

Example 17 with BundleCapability

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);
}
Also used : BundleCapability(org.osgi.framework.wiring.BundleCapability) Capability(org.osgi.resource.Capability) Bundle(org.osgi.framework.Bundle) BundleTracker(org.osgi.util.tracker.BundleTracker) ServiceReference(org.osgi.framework.ServiceReference) BundleEvent(org.osgi.framework.BundleEvent) List(java.util.List) CdiEvent(org.osgi.service.cdi.CdiEvent) CdiContainer(org.osgi.service.cdi.CdiContainer)

Example 18 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 19 with BundleCapability

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);
}
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) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Example 20 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)27 Bundle (org.osgi.framework.Bundle)11 BundleRevision (org.osgi.framework.wiring.BundleRevision)10 BundleWiring (org.osgi.framework.wiring.BundleWiring)9 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)7 CompositeData (javax.management.openmbean.CompositeData)6 BundleWire (org.osgi.framework.wiring.BundleWire)6 List (java.util.List)4 Map (java.util.Map)4 Region (org.eclipse.equinox.region.Region)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2 TreeMap (java.util.TreeMap)2 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)2 VersionRange (org.apache.felix.utils.version.VersionRange)2 PackageVersion (org.apache.karaf.packages.core.PackageVersion)2