@Override public BundleState getState(Bundle bundle) { if (bundle.getState() == Bundle.ACTIVE) { for (ComponentDescriptionDTO desc : scr.getComponentDescriptionDTOs(bundle)) { for (ComponentConfigurationDTO cfg : scr.getComponentConfigurationDTOs(desc)) { if (cfg.state != ComponentConfigurationDTO.ACTIVE && cfg.state != ComponentConfigurationDTO.SATISFIED) { return BundleState.Waiting; } } } } return BundleState.Unknown; } }
@Override public void disable(String componentName) { for (Bundle bundle : bundleContext.getBundles()) { ComponentDescriptionDTO dto = scr.getComponentDescriptionDTO(bundle, componentName); if (dto != null && scr.isComponentEnabled(dto)) { log.info("Component {} disabled by configuration.", dto.implementationClass); scr.disableComponent(dto); } } }
private void enableComponent(String name) { ComponentDescriptionDTO component = getComponent(name); if (component != null && !scrService.isComponentEnabled(component)) { log.info("Enabling component {}", name); try { scrService.enableComponent(component).timeout(TIMEOUT); } catch (Exception e) { throw new IllegalStateException("Unable to start component " + name, e); } } }
private boolean isFullyStarted(Bundle bundle) { for (ComponentDescriptionDTO component : scrService.getComponentDescriptionDTOs(bundle)) { if (scrService.isComponentEnabled(component)) { for (ComponentConfigurationDTO config : scrService.getComponentConfigurationDTOs(component)) { if (config.state != ComponentConfigurationDTO.ACTIVE) { return false; } } } } return true; }
private ComponentDescriptionDTO getComponent(String name) { for (ComponentDescriptionDTO component : scrService.getComponentDescriptionDTOs()) { if (component.name.equals(name)) { return component; } } return null; }
protected ComponentConfigurationDTO getComponentId(final String componentIdPar) { try { final long componentId = Long.parseLong(componentIdPar); for(final ComponentDescriptionDTO desc : this.descriptions) { for(final ComponentConfigurationDTO cfg : runtime.getComponentConfigurationDTOs(desc)) { if ( cfg.id == componentId ) { return cfg; } } } } catch (NumberFormatException nfe) { // don't care } return null; }
private void disableComponent(String name) { ComponentDescriptionDTO component = getComponent(name); if (component != null && scrService.isComponentEnabled(component)) { log.info("Disabling component {}", name); try { scrService.disableComponent(component).timeout(TIMEOUT); } catch (Exception e) { throw new IllegalStateException("Unable to start component " + name, e); } } } }
wait(this.runtime.enableComponent(reqInfo.component.description)); reqInfo = new RequestInfo(request, false); found = true; wait(this.runtime.disableComponent(reqInfo.component.description)); found = true;
@Override public void disable() { scr.disableComponent(config.description); } }
public boolean isComponentEnabled(long bundleId, String componentName) { return scrService.isComponentEnabled(findComponent(bundleId, componentName)); }
public void enableComponent(long bundleId, String componentName) { scrService.enableComponent(findComponent(bundleId, componentName)); }
private ComponentDescriptionDTO findComponent(long bundleId, String componentName) { Bundle bundle = context.getBundle(bundleId); if (bundle != null) { return scrService.getComponentDescriptionDTO(bundle, componentName); } else { throw new IllegalArgumentException("No component found for name: " + componentName); } }
final List<ComponentConfigurationDTO> configurations = new ArrayList<>(); final Collection<ComponentDescriptionDTO> descs = scrService.getComponentDescriptionDTOs(); for(final ComponentDescriptionDTO d : descs) if ( !scrService.isComponentEnabled(d) ) final Collection<ComponentConfigurationDTO> configs = scrService.getComponentConfigurationDTOs(d); if ( configs.isEmpty() )
private List<ComponentDescriptionDTO> findComponents(String name) { String lowerName = name.toLowerCase(); List<ComponentDescriptionDTO> matches = new LinkedList<>(); for (ComponentDescriptionDTO dto : scr.getComponentDescriptionDTOs()) { if (dto.name.equalsIgnoreCase(name)) { // Exact match, return only this component. return Collections.singletonList(dto); } if (dto.name.toLowerCase().contains(lowerName)) matches.add(dto); } return matches; }
private Component toComponent(ComponentDescriptionDTO dto) { Collection<ComponentConfigurationDTO> configs = scr.getComponentConfigurationDTOs(dto); if (configs.isEmpty()) { return null; } return new ComponentImpl(configs.iterator().next()); }
@Descriptor("Disable an enabled component") public boolean disable(@Descriptor("Name of the component") final String name) { boolean changed = false; for (ComponentDescriptionDTO comp : findComponents(name)) { if (scr.isComponentEnabled(comp)) { scr.disableComponent(comp); changed = true; } } return changed; }
@Override public void enable() { scr.disableComponent(config.description); }
@Override public BundleState getState(Bundle bundle) { if (bundle.getState() == Bundle.ACTIVE) { for (ComponentDescriptionDTO desc : scr.getComponentDescriptionDTOs(bundle)) { for (ComponentConfigurationDTO cfg : scr.getComponentConfigurationDTOs(desc)) { if (cfg.state != ComponentConfigurationDTO.ACTIVE && cfg.state != ComponentConfigurationDTO.SATISFIED) { return BundleState.Waiting; } } } } return BundleState.Unknown; } }
final List<ComponentConfigurationDTO> configurations = new ArrayList<ComponentConfigurationDTO>(); final Collection<ComponentDescriptionDTO> descs = scrService.getComponentDescriptionDTOs(bundle); for(final ComponentDescriptionDTO d : descs) if ( !scrService.isComponentEnabled(d)) final Collection<ComponentConfigurationDTO> configs = scrService.getComponentConfigurationDTOs(d); if ( configs.isEmpty() )
private List<ComponentDescriptionDTO> getComponentDescriptions(ServiceComponentRuntime scr, String interfaceName, Bundle[] allBundlesArrays) { return scr.getComponentDescriptionDTOs(allBundlesArrays).stream() .filter(description -> Stream.of(description.serviceInterfaces).anyMatch(s -> s.equals(interfaceName))) .collect(toList()); }