use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO 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;
}
use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.
the class ScrCommand method getComponentsFromArg.
private Result getComponentsFromArg(final String componentIdentifier, final boolean nameMatch) {
final Pattern p = (componentIdentifier == null ? null : Pattern.compile(componentIdentifier));
final Result result = new Result();
for (final ComponentDescriptionDTO cmp : scrService.getComponentDescriptionDTOs()) {
if (componentIdentifier != null) {
if (p.matcher(cmp.name).matches()) {
result.components.add(cmp);
} else if (!nameMatch) {
boolean done = false;
for (final ComponentConfigurationDTO cfg : scrService.getComponentConfigurationDTOs(cmp)) {
if (p.matcher(String.valueOf(cfg.id)).matches()) {
result.components.add(cmp);
result.configuration = cfg;
done = true;
break;
}
}
if (done) {
break;
}
}
} else {
result.components.add(cmp);
}
}
if (componentIdentifier != null && result.components.isEmpty()) {
throw new IllegalArgumentException("No Component with name or configuration with ID matching " + componentIdentifier);
}
return result;
}
use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.
the class ScrCommand method list.
/* (non-Javadoc)
* @see org.apache.felix.scr.impl.ScrInfo#list(java.lang.String, java.io.PrintStream, java.io.PrintStream)
*/
@Override
public void list(final String bundleIdentifier, final PrintWriter out) {
final List<ComponentDescriptionDTO> descriptions = new ArrayList<ComponentDescriptionDTO>();
if (bundleIdentifier != null) {
Bundle bundle = null;
try {
final long bundleId = Long.parseLong(bundleIdentifier);
bundle = bundleContext.getBundle(bundleId);
} catch (final NumberFormatException nfe) {
// might be a bundle symbolic name
final Bundle[] bundles = bundleContext.getBundles();
for (int i = 0; i < bundles.length; i++) {
if (bundleIdentifier.equals(bundles[i].getSymbolicName())) {
bundle = bundles[i];
break;
}
}
}
if (bundle == null) {
throw new IllegalArgumentException("Missing bundle with ID " + bundleIdentifier);
}
if (isBundleActive(bundle)) {
descriptions.addAll(scrService.getComponentDescriptionDTOs(bundle));
if (descriptions.isEmpty()) {
out.println("Bundle " + bundleIdentifier + " declares no components");
return;
}
} else {
out.println("Bundle " + bundleIdentifier + " is not active");
return;
}
} else {
descriptions.addAll(scrService.getComponentDescriptionDTOs());
if (descriptions.isEmpty()) {
out.println("No components registered");
return;
}
}
Collections.sort(descriptions, DESCRIPTION_COMP);
out.println(" BundleId Component Name Default State");
out.println(" Component Id State PIDs (Factory PID)");
for (final ComponentDescriptionDTO desc : descriptions) {
out.println(String.format(" [%1$4d] %2$s %3$s", desc.bundle.id, desc.name, desc.defaultEnabled ? "enabled" : "disabled"));
final List<ComponentConfigurationDTO> configs = new ArrayList<ComponentConfigurationDTO>(this.scrService.getComponentConfigurationDTOs(desc));
Collections.sort(configs, CONFIGURATION_COMP);
for (final ComponentConfigurationDTO component : configs) {
final Object servicePid = component.properties.get(Constants.SERVICE_PID);
final String factoryPid = (String) component.properties.get("service.factoryPid");
final StringBuilder pid = new StringBuilder();
if (servicePid != null) {
pid.append(servicePid);
}
if (factoryPid != null) {
pid.append(" (");
pid.append(factoryPid);
pid.append(" )");
}
out.println(String.format(" [%1$4d] [%2$s] %3$s", component.id, toStateString(component.state), pid.toString()));
}
}
out.flush();
}
use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.
the class ScrCommand method info.
/**
* @see org.apache.felix.scr.impl.ScrInfo#info(java.lang.String, java.io.PrintStream, java.io.PrintStream)
*/
@Override
public void info(final String componentId, final PrintWriter out) {
final Result result = getComponentsFromArg(componentId, false);
if (result.components.isEmpty()) {
return;
}
Collections.sort(result.components, DESCRIPTION_COMP);
long bundleId = -1;
for (ComponentDescriptionDTO component : result.components) {
if (component.bundle.id != bundleId) {
if (bundleId != -1) {
out.println();
}
bundleId = component.bundle.id;
out.println(String.format("*** Bundle: %1$s (%2$d)", component.bundle.symbolicName, bundleId));
}
out.println("Component Description:");
out.print(" Name: ");
out.println(component.name);
out.print(" Implementation Class: ");
out.println(component.implementationClass);
out.print(" Default State: ");
out.println(component.defaultEnabled ? "enabled" : "disabled");
out.print(" Activation: ");
out.println(component.immediate ? "immediate" : "delayed");
// DS 1.1 new features
out.print(" Configuration Policy: ");
out.println(component.configurationPolicy);
out.print(" Activate Method: ");
out.print(component.activate);
out.println();
out.print(" Deactivate Method: ");
out.print(component.deactivate);
out.println();
out.print(" Modified Method: ");
if (component.modified != null) {
out.print(component.modified);
} else {
out.print("-");
}
out.println();
out.print(" Configuration Pid: ");
out.print(Arrays.asList(component.configurationPid));
out.println();
if (component.factory != null) {
out.print(" Factory: ");
out.println(component.factory);
}
String[] services = component.serviceInterfaces;
if (services != null && services.length > 0) {
out.println(" Services: ");
for (String service : services) {
out.print(" ");
out.println(service);
}
out.print(" Service Scope: ");
out.println(component.scope);
}
ReferenceDTO[] refs = component.references;
if (refs != null) {
for (ReferenceDTO ref : refs) {
out.print(" Reference: ");
out.println(ref.name);
out.print(" Interface Name: ");
out.println(ref.interfaceName);
if (ref.target != null) {
out.print(" Target Filter: ");
out.println(ref.target);
}
out.print(" Cardinality: ");
out.println(ref.cardinality);
out.print(" Policy: ");
out.println(ref.policy);
out.print(" Policy option: ");
out.println(ref.policyOption);
out.print(" Reference Scope: ");
out.println(ref.scope);
}
}
Map<String, Object> props = component.properties;
propertyInfo(props, out, " ", "Component Description");
if (result.configuration != null) {
info(result.configuration, out);
} else {
Collection<ComponentConfigurationDTO> componentConfigurationDTOs = scrService.getComponentConfigurationDTOs(component);
if (componentConfigurationDTOs.isEmpty()) {
out.println(" (No Component Configurations)");
} else {
for (final ComponentConfigurationDTO cc : componentConfigurationDTOs) {
info(cc, out);
}
}
}
out.println();
}
out.flush();
}
use of org.osgi.service.component.runtime.dto.ComponentConfigurationDTO in project felix by apache.
the class ComponentConstructorTest method test_constructor_singleRef.
@Test
public void test_constructor_singleRef() throws Exception {
final String componentname = "ConstructorComponent.refsingle";
ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.SATISFIED);
assertEquals(1, cc.description.init);
ConstructorComponent cmp = this.getServiceFromConfiguration(cc, ConstructorComponent.class);
final String msg = cmp.test();
assertNull(msg);
disableAndCheck(cc);
}
Aggregations