This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-hc-annotations.git
commit 3854405768a74fc5a4403bc3a426cbecf3e52e64 Author: Bertrand Delacretaz <bdelacre...@apache.org> AuthorDate: Thu Jul 31 08:35:49 2014 +0000 SLING-3624 - MBean name and async cron expression added, contributed by Georg Henzler, thanks! git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1614826 13f79535-47bb-0310-9956-ffa450edef68 --- .../sling/hc/annotations/SlingHealthCheck.java | 30 +++++++---- .../hc/annotations/SlingHealthCheckProcessor.java | 61 ++++++++++------------ 2 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheck.java b/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheck.java index dcba01f..9c7abd5 100644 --- a/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheck.java +++ b/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheck.java @@ -27,6 +27,27 @@ import org.apache.felix.scr.annotations.ConfigurationPolicy; @Target(ElementType.TYPE) @Retention(RetentionPolicy.CLASS) public @interface SlingHealthCheck { + + /** Defines the name of the health check. <p> + * This attribute is converted to values for the <code>hc.name</code> property. */ + String name() default ""; + + /** One ore more tags. + * <p> + * This attribute is converted to values for the <code>hc.tags</code> property. */ + String[] tags() default {}; + + /** The JMX mbean name (optional, the mbean is only registered if attribute present). + * <p> + * This attribute is converted to values for the <code>hc.mbean.name</code> property. */ + String mbeanName() default ""; + + /** Cron expression for asynchronous execution (optional, default is synchronous execution). + * <p> + * This attribute is converted to values for the <code>hc.async.cronExpression</code> property. */ + String asyncCronExpression() default ""; + + // handling of service and component properties (optional) /** Whether to generate a default SCR component tag. If set to false, a {@link org.apache.felix.scr.annotations.Component} annotation can be added manually * with defined whatever configuration needed. */ @@ -35,9 +56,6 @@ public @interface SlingHealthCheck { /** Whether to generate a default SCR service tag with "interface=org.apache.sling.hc.api.HealthCheck". If set to false, a * {@link org.apache.felix.scr.annotations.Service} annotation can be added manually with defined whatever configuration needed. */ boolean generateService() default true; - - /** Defines the name of the health check. */ - String name(); /** Defines the Component name also used as the PID for the Configuration Admin Service. Default value: Fully qualified name of the Java class. */ String componentName() default ""; @@ -59,10 +77,4 @@ public @interface SlingHealthCheck { /** This is generally used as a description for the object described by the meta type. This name may be localized by prepending a % sign to the name. Default * value: %<name>.description */ String description() default ""; - - /** One ore more tags. - * <p> - * This attribute is converted to values for the <code>hc.tags</code> property. */ - String[] tags() default {}; - } diff --git a/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheckProcessor.java b/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheckProcessor.java index 84562e4..fe388ba 100644 --- a/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheckProcessor.java +++ b/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheckProcessor.java @@ -57,14 +57,18 @@ public class SlingHealthCheckProcessor implements AnnotationProcessor { // generate ComponentDescription if required if (generateComponent) { + String nameOfAnnotatedClass = classDescription.getDescribedClass().getName(); + final ComponentDescription cd = new ComponentDescription(cad); - cd.setName(cad.getStringValue("componentName", classDescription.getDescribedClass().getName())); + cd.setName(cad.getStringValue("componentName", nameOfAnnotatedClass)); cd.setConfigurationPolicy(ComponentConfigurationPolicy.valueOf(cad.getEnumValue("configurationPolicy", ComponentConfigurationPolicy.OPTIONAL.name()))); cd.setSetMetatypeFactoryPid(cad.getBooleanValue("configurationFactory", false)); - cd.setLabel(cad.getStringValue("label", null)); - cd.setDescription(cad.getStringValue("description", null)); + 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); @@ -79,48 +83,41 @@ public class SlingHealthCheckProcessor implements AnnotationProcessor { classDescription.add(sd); } - // generate PropertyDescriptions - generateStringArrPropertyDescriptor(cad, classDescription, metatype, "tags", HealthCheck.TAGS); - generateStringPropertyDescriptor(cad, classDescription, metatype, "name", HealthCheck.NAME); + // generate HC PropertyDescriptions + generateStringPropertyDescriptor(cad, classDescription, metatype, "name", HealthCheck.NAME, "Name", "Name", false); + generateStringPropertyDescriptor(cad, classDescription, metatype, "tags", HealthCheck.TAGS, "Tags", "Tags", true); + generateStringPropertyDescriptor(cad, classDescription, metatype, "mbeanName", HealthCheck.MBEAN_NAME, "MBean", "MBean name (leave empty for not using JMX)", false); + generateStringPropertyDescriptor(cad, classDescription, metatype, "asyncCronExpression", "hc.async.cronExpression" /* use constant once API is released */ , "Cron expression", "Cron expression for asynchronous execution (leave empty for synchronous execution)", false); } /** Generates a property descriptor of type {@link PropertyType#String[]} */ - private void generateStringArrPropertyDescriptor(final ClassAnnotation cad, final ClassDescription classDescription, - final boolean metatype, final String annotationName, final String propertyDescriptorName) { - - final String[] values = (String[]) cad.getValue(annotationName); - if (values == null) { - return; - } - - final PropertyDescription pd = new PropertyDescription(cad); - pd.setName(propertyDescriptorName); - pd.setMultiValue(values); - pd.setType(PropertyType.String); - pd.setUnbounded(PropertyUnbounded.ARRAY); - pd.setCardinality(Integer.MAX_VALUE); - if (metatype) { - pd.setPrivate(true); - } - classDescription.add(pd); - } - - - /** Generates a property descriptor of type {@link PropertyType#String} */ private void generateStringPropertyDescriptor(final ClassAnnotation cad, final ClassDescription classDescription, - final boolean metatype, final String annotationName, final String propertyDescriptorName) { + final boolean metatype, final String propertyName, final String propertyDescriptorName, String label, String description, boolean isArray) { - final String hcName = (String) cad.getValue(annotationName); final PropertyDescription pd = new PropertyDescription(cad); pd.setName(propertyDescriptorName); - pd.setValue(hcName); + pd.setLabel(label); + pd.setDescription(description); pd.setType(PropertyType.String); - if (metatype) { + + if(isArray) { + final String[] values = (String[]) cad.getValue(propertyName); + pd.setMultiValue(values); + pd.setUnbounded(PropertyUnbounded.ARRAY); + pd.setCardinality(Integer.MAX_VALUE); + } else { + final String propertyVal = (String) cad.getValue(propertyName); + pd.setValue(propertyVal); + pd.setUnbounded(PropertyUnbounded.DEFAULT); + } + + if (!metatype) { pd.setPrivate(true); } classDescription.add(pd); } + @Override public int getRanking() { -- To stop receiving notification emails like this one, please contact "commits@sling.apache.org" <commits@sling.apache.org>.