Search in sources :

Example 1 with SatisfiedReferenceDTO

use of org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO 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 SatisfiedReferenceDTO

use of org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO in project felix by apache.

the class ScrCommand method info.

private void info(ComponentConfigurationDTO cc, PrintWriter out) {
    out.println("  Component Configuration:");
    out.print("    ComponentId: ");
    out.println(cc.id);
    out.print("    State: ");
    out.println(toStateString(cc.state));
    for (SatisfiedReferenceDTO ref : cc.satisfiedReferences) {
        out.print("    SatisfiedReference: ");
        out.println(ref.name);
        out.print("      Target: ");
        out.println(ref.target);
        ServiceReferenceDTO[] serviceRefs = ref.boundServices;
        if (serviceRefs.length > 0) {
            out.print("      Bound to:");
            for (ServiceReferenceDTO sr : serviceRefs) {
                out.print("        ");
                out.println(sr.id);
                propertyInfo(sr.properties, out, "      ", "Reference");
            }
        } else {
            out.println("      (unbound)");
        }
    }
    for (UnsatisfiedReferenceDTO ref : cc.unsatisfiedReferences) {
        out.print("    UnsatisfiedReference: ");
        out.println(ref.name);
        out.print("      Target: ");
        out.println(ref.target);
        ServiceReferenceDTO[] serviceRefs = ref.targetServices;
        if (serviceRefs.length > 0) {
            out.print("      Target services:");
            for (ServiceReferenceDTO sr : serviceRefs) {
                out.print("        ");
                out.println(sr.id);
            }
        } else {
            out.println("      (no target services)");
        }
    }
    propertyInfo(cc.properties, out, "    ", "Component Configuration");
}
Also used : ServiceReferenceDTO(org.osgi.framework.dto.ServiceReferenceDTO) SatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO) UnsatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.UnsatisfiedReferenceDTO)

Example 3 with SatisfiedReferenceDTO

use of org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO in project felix by apache.

the class ComponentConfigurationPrinter method listReferences.

private static final void listReferences(PrintWriter pw, final ComponentDescriptionDTO description, final ComponentConfigurationDTO configuration) {
    for (final ReferenceDTO dto : description.references) {
        final SatisfiedReferenceDTO satisfiedRef = configuration == null ? null : findReference(configuration, dto.name);
        pw.print("  Reference=");
        pw.print(dto.name);
        if (configuration != null) {
            pw.print(", ");
            pw.print(satisfiedRef != null ? "Satisfied" : "Unsatisfied");
        }
        pw.println();
        pw.println("    Service Name: " + dto.interfaceName);
        if (dto.target != null) {
            pw.println("  Target Filter: " + dto.target);
        }
        pw.println("    Cardinality: " + dto.cardinality);
        pw.println("    Policy: " + dto.policy);
        pw.println("    Policy Option: " + dto.policyOption);
        // list bound services
        if (satisfiedRef != null) {
            for (final ServiceReferenceDTO sref : satisfiedRef.boundServices) {
                pw.print("    Bound Service: ID ");
                pw.print(sref.properties.get(Constants.SERVICE_ID));
                String name = (String) sref.properties.get(ComponentConstants.COMPONENT_NAME);
                if (name == null) {
                    name = (String) sref.properties.get(Constants.SERVICE_PID);
                    if (name == null) {
                        name = (String) sref.properties.get(Constants.SERVICE_DESCRIPTION);
                    }
                }
                if (name != null) {
                    pw.print(" (");
                    pw.print(name);
                    pw.print(")");
                }
                pw.println();
            }
        } else {
            pw.println("    No Services bound");
        }
    }
}
Also used : ServiceReferenceDTO(org.osgi.framework.dto.ServiceReferenceDTO) ReferenceDTO(org.osgi.service.component.runtime.dto.ReferenceDTO) ServiceReferenceDTO(org.osgi.framework.dto.ServiceReferenceDTO) SatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO) SatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO)

Example 4 with SatisfiedReferenceDTO

use of org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO in project felix by apache.

the class ServiceComponentRuntimeImpl method satisfiedRefManagersToDTO.

private SatisfiedReferenceDTO[] satisfiedRefManagersToDTO(List<? extends ReferenceManager<?, ?>> referenceManagers) {
    List<SatisfiedReferenceDTO> dtos = new ArrayList<SatisfiedReferenceDTO>();
    for (ReferenceManager<?, ?> ref : referenceManagers) {
        if (ref.isSatisfied()) {
            SatisfiedReferenceDTO dto = new SatisfiedReferenceDTO();
            dto.name = ref.getName();
            dto.target = ref.getTarget();
            List<ServiceReference<?>> serviceRefs = ref.getServiceReferences();
            ServiceReferenceDTO[] srDTOs = new ServiceReferenceDTO[serviceRefs.size()];
            int j = 0;
            for (ServiceReference<?> serviceRef : serviceRefs) {
                ServiceReferenceDTO srefDTO = serviceReferenceToDTO(serviceRef);
                if (srefDTO != null)
                    srDTOs[j++] = srefDTO;
            }
            dto.boundServices = srDTOs;
            dtos.add(dto);
        }
    }
    return dtos.toArray(new SatisfiedReferenceDTO[dtos.size()]);
}
Also used : ServiceReferenceDTO(org.osgi.framework.dto.ServiceReferenceDTO) SatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO) ArrayList(java.util.ArrayList) ServiceReference(org.osgi.framework.ServiceReference)

Example 5 with SatisfiedReferenceDTO

use of org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO in project felix by apache.

the class ComponentCommands method printServiceReferences.

String printServiceReferences(SatisfiedReferenceDTO[] satisfiedReferences, UnsatisfiedReferenceDTO[] unsatisfiedReferences, ReferenceDTO[] references) {
    StringBuilder builder = new StringBuilder();
    final Map<String, ReferenceDTO> refDtoMap = new HashMap<>();
    if (references != null) {
        for (ReferenceDTO refDto : references) refDtoMap.put(refDto.name, refDto);
    }
    int refCount = (satisfiedReferences != null ? satisfiedReferences.length : 0) + (unsatisfiedReferences != null ? unsatisfiedReferences.length : 0);
    builder.append("(total ").append(Integer.toString(refCount)).append(")");
    if (unsatisfiedReferences != null) {
        for (UnsatisfiedReferenceDTO refDto : unsatisfiedReferences) printServiceReference(refDtoMap.get(refDto.name), "UNSATISFIED", null, builder);
    }
    if (satisfiedReferences != null) {
        for (SatisfiedReferenceDTO refDto : satisfiedReferences) printServiceReference(refDtoMap.get(refDto.name), "SATISFIED", refDto.boundServices != null ? refDto.boundServices : new ServiceReferenceDTO[0], builder);
    }
    return builder.toString();
}
Also used : ReferenceDTO(org.osgi.service.component.runtime.dto.ReferenceDTO) SatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO) UnsatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.UnsatisfiedReferenceDTO) ServiceReferenceDTO(org.osgi.framework.dto.ServiceReferenceDTO) SatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) UnsatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.UnsatisfiedReferenceDTO)

Aggregations

SatisfiedReferenceDTO (org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO)6 ServiceReferenceDTO (org.osgi.framework.dto.ServiceReferenceDTO)5 ReferenceDTO (org.osgi.service.component.runtime.dto.ReferenceDTO)4 UnsatisfiedReferenceDTO (org.osgi.service.component.runtime.dto.UnsatisfiedReferenceDTO)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 TreeMap (java.util.TreeMap)1 ServiceReference (org.osgi.framework.ServiceReference)1 ComponentConfigurationDTO (org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)1 ComponentDescriptionDTO (org.osgi.service.component.runtime.dto.ComponentDescriptionDTO)1