Search in sources :

Example 1 with Component

use of org.apache.felix.scr.Component in project karaf by apache.

the class ScrServiceMBeanImpl method componentState.

public int componentState(String componentName) {
    int state = -1;
    final Component component = findComponent(componentName);
    if (component != null)
        state = component.getState();
    else
        LOGGER.warn("No component found for name: " + componentName);
    return state;
}
Also used : JmxComponent(org.apache.karaf.scr.management.codec.JmxComponent) Component(org.apache.felix.scr.Component)

Example 2 with Component

use of org.apache.felix.scr.Component in project felix by apache.

the class ScrServiceImpl method getComponents.

/**
 * @see org.apache.felix.scr.ScrService#getComponents(java.lang.String)
 */
public Component[] getComponents(final String componentName) {
    List<Component> result = new ArrayList<Component>();
    final Collection<ComponentDescriptionDTO> descriptions = this.runtime.getComponentDescriptionDTOs();
    for (final ComponentDescriptionDTO descDTO : descriptions) {
        if (descDTO.name.equals(componentName)) {
            final Collection<ComponentConfigurationDTO> configs = this.runtime.getComponentConfigurationDTOs(descDTO);
            ComponentConfigurationDTO configDTO = null;
            if (!configs.isEmpty()) {
                configDTO = configs.iterator().next();
            }
            result.add(new ComponentWrapper(this.context, this.runtime, descDTO, configDTO));
        }
    }
    return result.isEmpty() ? null : result.toArray(new Component[result.size()]);
}
Also used : ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) ArrayList(java.util.ArrayList) Component(org.apache.felix.scr.Component) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)

Example 3 with Component

use of org.apache.felix.scr.Component in project felix by apache.

the class ScrServiceImpl method getComponents.

/**
 * @see org.apache.felix.scr.ScrService#getComponents(org.osgi.framework.Bundle)
 */
public Component[] getComponents(final Bundle bundle) {
    List<Component> result = new ArrayList<Component>();
    final Collection<ComponentDescriptionDTO> descriptions = (bundle == null ? this.runtime.getComponentDescriptionDTOs() : this.runtime.getComponentDescriptionDTOs(bundle));
    for (final ComponentDescriptionDTO descDTO : descriptions) {
        final Collection<ComponentConfigurationDTO> configs = this.runtime.getComponentConfigurationDTOs(descDTO);
        ComponentConfigurationDTO configDTO = null;
        if (!configs.isEmpty()) {
            configDTO = configs.iterator().next();
        }
        result.add(new ComponentWrapper(this.context, this.runtime, descDTO, configDTO));
    }
    return result.isEmpty() ? null : result.toArray(new Component[result.size()]);
}
Also used : ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) ArrayList(java.util.ArrayList) Component(org.apache.felix.scr.Component) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)

Example 4 with Component

use of org.apache.felix.scr.Component in project fabric8 by fabric8io.

the class ScrState method checkBundle.

@Override
protected Check checkBundle(Bundle bundle) {
    if (bundle.getHeaders().get("Service-Component") == null) {
        return null;
    }
    ScrService svc = tracker.getService();
    if (svc == null) {
        return new Check("scr-state", "No ScrService found");
    }
    Component[] components = svc.getComponents(bundle);
    if (components != null) {
        for (Component component : components) {
            int state = component.getState();
            if (state != Component.STATE_ACTIVE && state != Component.STATE_REGISTERED && state != Component.STATE_FACTORY) {
                return new Check("scr-state", "SCR bundle " + bundle.getBundleId() + " is in state " + getState(state));
            }
        }
    }
    return null;
}
Also used : Check(io.fabric8.karaf.checks.Check) ScrService(org.apache.felix.scr.ScrService) Component(org.apache.felix.scr.Component)

Aggregations

Component (org.apache.felix.scr.Component)4 ArrayList (java.util.ArrayList)2 ComponentConfigurationDTO (org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)2 ComponentDescriptionDTO (org.osgi.service.component.runtime.dto.ComponentDescriptionDTO)2 Check (io.fabric8.karaf.checks.Check)1 ScrService (org.apache.felix.scr.ScrService)1 JmxComponent (org.apache.karaf.scr.management.codec.JmxComponent)1