Search in sources :

Example 1 with UnsatisfiedReferenceDTO

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

use of org.osgi.service.component.runtime.dto.UnsatisfiedReferenceDTO in project karaf by apache.

the class ScrBundleStateService method getDiag.

@Override
public String getDiag(Bundle bundle) {
    StringBuilder sb = new StringBuilder();
    for (ComponentDescriptionDTO desc : scr.getComponentDescriptionDTOs(bundle)) {
        for (ComponentConfigurationDTO cfg : scr.getComponentConfigurationDTOs(desc)) {
            if (cfg.state != ComponentConfigurationDTO.ACTIVE && cfg.state != ComponentConfigurationDTO.SATISFIED) {
                sb.append(cfg.description.name).append(" (").append(cfg.id).append(")\n");
                if ((cfg.state & ComponentConfigurationDTO.UNSATISFIED_CONFIGURATION) != 0) {
                    sb.append("  missing configurations: ");
                    boolean first = true;
                    for (String s : cfg.description.configurationPid) {
                        if (!first) {
                            sb.append(", ");
                        }
                        sb.append(s);
                        first = false;
                    }
                    sb.append("\n");
                }
                if ((cfg.state & ComponentConfigurationDTO.UNSATISFIED_REFERENCE) != 0) {
                    sb.append("  missing references: ");
                    boolean first = true;
                    for (UnsatisfiedReferenceDTO ur : cfg.unsatisfiedReferences) {
                        if (!first) {
                            sb.append(", ");
                        }
                        sb.append(ur.name);
                        first = false;
                    }
                    sb.append("\n");
                }
            }
        }
    }
    return sb.toString();
}
Also used : ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO) UnsatisfiedReferenceDTO(org.osgi.service.component.runtime.dto.UnsatisfiedReferenceDTO)

Aggregations

ComponentConfigurationDTO (org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)2 ComponentDescriptionDTO (org.osgi.service.component.runtime.dto.ComponentDescriptionDTO)2 UnsatisfiedReferenceDTO (org.osgi.service.component.runtime.dto.UnsatisfiedReferenceDTO)2 TreeMap (java.util.TreeMap)1 ServiceReferenceDTO (org.osgi.framework.dto.ServiceReferenceDTO)1 ReferenceDTO (org.osgi.service.component.runtime.dto.ReferenceDTO)1 SatisfiedReferenceDTO (org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO)1