Search in sources :

Example 1 with ServiceReferenceDTO

use of org.osgi.framework.dto.ServiceReferenceDTO in project karaf by apache.

the class DetailsAction method doScrAction.

@SuppressWarnings("rawtypes")
@Override
protected Object doScrAction(ServiceComponentRuntime serviceComponentRuntime) throws Exception {
    if (logger.isDebugEnabled()) {
        logger.debug("Executing the Details Action");
    }
    System.out.println(SimpleAnsi.INTENSITY_BOLD + "Component Details" + SimpleAnsi.INTENSITY_NORMAL);
    for (ComponentDescriptionDTO component : serviceComponentRuntime.getComponentDescriptionDTOs()) {
        for (ComponentConfigurationDTO config : serviceComponentRuntime.getComponentConfigurationDTOs(component)) {
            if (name.equals(component.name)) {
                printDetail("  Name                : ", component.name);
                printDetail("  State               : ", ScrUtils.getState(config.state));
                Map<String, Object> map = new TreeMap<>(component.properties);
                if (!map.isEmpty()) {
                    System.out.println(SimpleAnsi.INTENSITY_BOLD + "  Properties          : " + SimpleAnsi.INTENSITY_NORMAL);
                    for (Object key : map.keySet()) {
                        Object value = map.get(key);
                        printDetail("    ", key + "=" + value);
                    }
                }
                ReferenceDTO[] references = component.references;
                System.out.println(SimpleAnsi.INTENSITY_BOLD + "References" + SimpleAnsi.INTENSITY_NORMAL);
                for (ReferenceDTO reference : ScrUtils.emptyIfNull(ReferenceDTO.class, references)) {
                    ServiceReferenceDTO[] boundServices = null;
                    boolean satisfied = true;
                    for (SatisfiedReferenceDTO satRef : config.satisfiedReferences) {
                        if (satRef.name.equals(reference.name)) {
                            boundServices = satRef.boundServices;
                            satisfied = true;
                        }
                    }
                    for (UnsatisfiedReferenceDTO satRef : config.unsatisfiedReferences) {
                        if (satRef.name.equals(reference.name)) {
                            boundServices = satRef.targetServices;
                            satisfied = false;
                        }
                    }
                    printDetail("  Reference           : ", reference.name);
                    printDetail("    State             : ", satisfied ? "satisfied" : "unsatisfied");
                    printDetail("    Cardinality       : ", reference.cardinality);
                    printDetail("    Policy            : ", reference.policy);
                    printDetail("    PolicyOption      : ", reference.policyOption);
                    // list bound services
                    for (ServiceReferenceDTO serviceReference : ScrUtils.emptyIfNull(ServiceReferenceDTO.class, boundServices)) {
                        final StringBuffer b = new StringBuffer();
                        b.append("Bound Service ID ");
                        b.append(serviceReference.properties.get(Constants.SERVICE_ID));
                        String componentName = (String) serviceReference.properties.get(ComponentConstants.COMPONENT_NAME);
                        if (componentName == null) {
                            componentName = (String) serviceReference.properties.get(Constants.SERVICE_PID);
                            if (componentName == null) {
                                componentName = (String) serviceReference.properties.get(Constants.SERVICE_DESCRIPTION);
                            }
                        }
                        if (componentName != null) {
                            b.append(" (");
                            b.append(componentName);
                            b.append(")");
                        }
                        printDetail("    Service Reference : ", b.toString());
                    }
                    if (ScrUtils.emptyIfNull(ServiceReferenceDTO.class, boundServices).length == 0) {
                        printDetail("    Service Reference : ", "No Services bound");
                    }
                }
            }
        }
    }
    return null;
}
Also used : ReferenceDTO(org.osgi.service.component.runtime.dto.ReferenceDTO) ServiceReferenceDTO(org.osgi.framework.dto.ServiceReferenceDTO) SatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO) UnsatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.UnsatisfiedReferenceDTO) SatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO) ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) TreeMap(java.util.TreeMap) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO) ServiceReferenceDTO(org.osgi.framework.dto.ServiceReferenceDTO) UnsatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.UnsatisfiedReferenceDTO)

Example 2 with ServiceReferenceDTO

use of org.osgi.framework.dto.ServiceReferenceDTO in project bnd by bndtools.

the class AgentServer method getServiceReferences.

private List<ServiceReferenceDTO> getServiceReferences() throws Exception {
    ServiceReference<?>[] refs = context.getAllServiceReferences(null, null);
    if (refs == null)
        return Collections.emptyList();
    ArrayList<ServiceReferenceDTO> list = new ArrayList<ServiceReferenceDTO>(refs.length);
    for (ServiceReference<?> r : refs) {
        ServiceReferenceDTO ref = new ServiceReferenceDTO();
        ref.bundle = r.getBundle().getBundleId();
        ref.id = (Long) r.getProperty(Constants.SERVICE_ID);
        ref.properties = getProperties(r);
        Bundle[] usingBundles = r.getUsingBundles();
        if (usingBundles == null)
            ref.usingBundles = EMPTY;
        else {
            ref.usingBundles = new long[usingBundles.length];
            for (int i = 0; i < usingBundles.length; i++) {
                ref.usingBundles[i] = usingBundles[i].getBundleId();
            }
        }
        list.add(ref);
    }
    return list;
}
Also used : ServiceReferenceDTO(org.osgi.framework.dto.ServiceReferenceDTO) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) ServiceReference(org.osgi.framework.ServiceReference)

Example 3 with ServiceReferenceDTO

use of org.osgi.framework.dto.ServiceReferenceDTO in project rt.equinox.framework by eclipse.

the class EquinoxBundle method adapt0.

@SuppressWarnings("unchecked")
private <A> A adapt0(Class<A> adapterType) {
    if (AccessControlContext.class.equals(adapterType)) {
        Generation current = (Generation) module.getCurrentRevision().getRevisionInfo();
        ProtectionDomain domain = current.getDomain();
        return (A) (domain == null ? null : new AccessControlContext(new ProtectionDomain[] { domain }));
    }
    if (BundleContext.class.equals(adapterType)) {
        try {
            return (A) getBundleContext();
        } catch (SecurityException e) {
            return null;
        }
    }
    if (BundleRevision.class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        return (A) module.getCurrentRevision();
    }
    if (BundleRevisions.class.equals(adapterType)) {
        return (A) module.getRevisions();
    }
    if (BundleStartLevel.class.equals(adapterType)) {
        return (A) module;
    }
    if (BundleWiring.class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        ModuleRevision revision = module.getCurrentRevision();
        if (revision == null) {
            return null;
        }
        return (A) revision.getWiring();
    }
    if (BundleDTO.class.equals(adapterType)) {
        // Unfortunately we need to lock here to make sure the BSN and version
        // are consistent in case of updates
        readLock();
        try {
            return (A) DTOBuilder.newBundleDTO(this);
        } finally {
            readUnlock();
        }
    }
    if (BundleStartLevelDTO.class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        return (A) DTOBuilder.newBundleStartLevelDTO(this, module);
    }
    if (BundleRevisionDTO.class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        return (A) DTOBuilder.newBundleRevisionDTO(module.getCurrentRevision());
    }
    if (BundleRevisionDTO[].class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        // proper locking for us.
        return (A) DTOBuilder.newArrayBundleRevisionDTO(module.getRevisions());
    }
    if (BundleWiringDTO.class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        readLock();
        try {
            return (A) DTOBuilder.newBundleWiringDTO(module.getCurrentRevision());
        } finally {
            readUnlock();
        }
    }
    if (BundleWiringDTO[].class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        readLock();
        try {
            return (A) DTOBuilder.newArrayBundleWiringDTO(module.getRevisions());
        } finally {
            readUnlock();
        }
    }
    if (ServiceReferenceDTO[].class.equals(adapterType)) {
        if (module.getState().equals(State.UNINSTALLED)) {
            return null;
        }
        BundleContextImpl current = getBundleContextImpl();
        ServiceReference<?>[] references = (current == null) ? null : equinoxContainer.getServiceRegistry().getRegisteredServices(current);
        return (A) DTOBuilder.newArrayServiceReferenceDTO(references);
    }
    if (getBundleId() == 0) {
        if (Framework.class.equals(adapterType)) {
            return (A) this;
        }
        if (FrameworkStartLevel.class.equals(adapterType)) {
            return (A) module.getContainer().getFrameworkStartLevel();
        }
        if (FrameworkWiring.class.equals(adapterType)) {
            return (A) module.getContainer().getFrameworkWiring();
        }
        if (FrameworkDTO.class.equals(adapterType)) {
            BundleContextImpl current = getBundleContextImpl();
            Map<String, String> configuration = equinoxContainer.getConfiguration().getConfiguration();
            readLock();
            try {
                return (A) DTOBuilder.newFrameworkDTO(current, configuration);
            } finally {
                readUnlock();
            }
        }
        if (FrameworkStartLevelDTO.class.equals(adapterType)) {
            return (A) DTOBuilder.newFrameworkStartLevelDTO(module.getContainer().getFrameworkStartLevel());
        }
        if (FrameworkWiringDTO.class.equals(adapterType)) {
            readLock();
            try {
                Set<BundleWiring> allWirings = new HashSet<>();
                for (Module m : module.getContainer().getModules()) {
                    for (BundleRevision revision : m.getRevisions().getRevisions()) {
                        BundleWiring wiring = revision.getWiring();
                        if (wiring != null) {
                            allWirings.add(wiring);
                        }
                    }
                }
                for (ModuleRevision revision : module.getContainer().getRemovalPending()) {
                    BundleWiring wiring = revision.getWiring();
                    if (wiring != null) {
                        allWirings.add(wiring);
                    }
                }
                return (A) DTOBuilder.newFrameworkWiringDTO(allWirings);
            } finally {
                readUnlock();
            }
        }
    }
    // Equinox extras
    if (Module.class.equals(adapterType)) {
        return (A) module;
    }
    if (ProtectionDomain.class.equals(adapterType)) {
        Generation current = (Generation) module.getCurrentRevision().getRevisionInfo();
        return (A) current.getDomain();
    }
    return null;
}
Also used : ProtectionDomain(java.security.ProtectionDomain) BundleRevisionDTO(org.osgi.framework.wiring.dto.BundleRevisionDTO) BundleWiring(org.osgi.framework.wiring.BundleWiring) ServiceReference(org.osgi.framework.ServiceReference) ServiceReferenceDTO(org.osgi.framework.dto.ServiceReferenceDTO) Generation(org.eclipse.osgi.storage.BundleInfo.Generation) AccessControlContext(java.security.AccessControlContext) BundleWiringDTO(org.osgi.framework.wiring.dto.BundleWiringDTO) BundleRevision(org.osgi.framework.wiring.BundleRevision) SystemModule(org.eclipse.osgi.container.SystemModule) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) HashSet(java.util.HashSet)

Aggregations

ServiceReferenceDTO (org.osgi.framework.dto.ServiceReferenceDTO)3 ServiceReference (org.osgi.framework.ServiceReference)2 AccessControlContext (java.security.AccessControlContext)1 ProtectionDomain (java.security.ProtectionDomain)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 Module (org.eclipse.osgi.container.Module)1 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)1 SystemModule (org.eclipse.osgi.container.SystemModule)1 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)1 Bundle (org.osgi.framework.Bundle)1 BundleRevision (org.osgi.framework.wiring.BundleRevision)1 BundleWiring (org.osgi.framework.wiring.BundleWiring)1 BundleRevisionDTO (org.osgi.framework.wiring.dto.BundleRevisionDTO)1 BundleWiringDTO (org.osgi.framework.wiring.dto.BundleWiringDTO)1 ComponentConfigurationDTO (org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)1 ComponentDescriptionDTO (org.osgi.service.component.runtime.dto.ComponentDescriptionDTO)1 ReferenceDTO (org.osgi.service.component.runtime.dto.ReferenceDTO)1 SatisfiedReferenceDTO (org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO)1