use of org.apache.felix.scrplugin.description.ComponentDescription in project sling by apache.
the class SlingHealthCheckProcessor method processHealthCheck.
/** Processes the given healthcheck annotation.
*
* @param cad the annotation
* @param classDescription the class description */
private void processHealthCheck(final ClassAnnotation cad, final ClassDescription classDescription) {
final boolean generateComponent = cad.getBooleanValue("generateComponent", true);
final boolean metatype = cad.getBooleanValue("metatype", true);
final boolean immediate = cad.getBooleanValue("immediate", false);
// generate ComponentDescription if required
if (generateComponent) {
String nameOfAnnotatedClass = classDescription.getDescribedClass().getName();
final ComponentDescription cd = new ComponentDescription(cad);
cd.setName(cad.getStringValue("componentName", nameOfAnnotatedClass));
cd.setConfigurationPolicy(ComponentConfigurationPolicy.valueOf(cad.getEnumValue("configurationPolicy", ComponentConfigurationPolicy.OPTIONAL.name())));
cd.setSetMetatypeFactoryPid(cad.getBooleanValue("configurationFactory", false));
String nameFromAnnotation = (String) cad.getValue("name");
String defaultLabel = "Sling Health Check: " + (nameFromAnnotation != null ? nameFromAnnotation : nameOfAnnotatedClass);
cd.setLabel(cad.getStringValue("label", defaultLabel));
cd.setDescription(cad.getStringValue("description", "Health Check Configuration"));
cd.setCreateMetatype(metatype);
cd.setImmediate(immediate);
classDescription.add(cd);
}
// generate ServiceDescription if required
final boolean generateService = cad.getBooleanValue("generateService", true);
if (generateService) {
final ServiceDescription sd = new ServiceDescription(cad);
sd.addInterface(HealthCheck.class.getName());
classDescription.add(sd);
}
// generate HC PropertyDescriptions
generatePropertyDescriptor(cad, classDescription, metatype, "name", HealthCheck.NAME, PropertyType.String, "Name", "Name of the Health Check", false);
generatePropertyDescriptor(cad, classDescription, metatype, "tags", HealthCheck.TAGS, PropertyType.String, "Tags", "List of tags", true);
generatePropertyDescriptor(cad, classDescription, metatype, "mbeanName", HealthCheck.MBEAN_NAME, PropertyType.String, "MBean", "MBean name (leave empty for not using JMX)", false);
generatePropertyDescriptor(cad, classDescription, metatype, "asyncCronExpression", HealthCheck.ASYNC_CRON_EXPRESSION, PropertyType.String, "Cron expression", "Cron expression for asynchronous execution (leave empty for synchronous execution)", false);
generatePropertyDescriptor(cad, classDescription, metatype, "resultCacheTtlInMs", "hc.resultCacheTtlInMs", /* use constant once API is released */
PropertyType.Long, "Result Cache TTL", "TTL for results. The value -1 (default) uses the global configuration in health check executor. Redeployment of a HC always invalidates its cached result.", false);
}
Aggregations