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 eaf35a96b5a04b491e922990ffd9a74bdf204461 Author: Georg Henzler <[email protected]> AuthorDate: Mon Oct 17 22:30:50 2016 +0000 SLING-6126 Introduce HC service property hc.resultCacheTtlInMs for per-HC TTL configuration. Thanks Evgeniy Fitsner for your contribution. git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1765377 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 2 +- .../sling/hc/annotations/SlingHealthCheck.java | 10 +++++++ .../hc/annotations/SlingHealthCheckProcessor.java | 31 +++++++++++----------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index a169bb4..6012892 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.hc.core</artifactId> - <version>1.1.0</version> + <version>1.2.4</version> <scope>provided</scope> </dependency> </dependencies> 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 f5619f4..4e3bf28 100644 --- a/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheck.java +++ b/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheck.java @@ -47,6 +47,14 @@ public @interface SlingHealthCheck { * This attribute is converted to values for the <code>hc.async.cronExpression</code> property. */ String asyncCronExpression() default ""; + /** + * Overrides the global result TTL as configured in + * {@link org.apache.sling.hc.core.impl.executor.HealthCheckExecutorImpl} for this individual check. + * <p> + * The value of this property must be of type {@link Long} and is configured in ms. + */ + long resultCacheTtlInMs() default -1; + // 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 @@ -80,4 +88,6 @@ 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 ""; + + } 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 f9caaf4..060135e 100644 --- a/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheckProcessor.java +++ b/src/main/java/org/apache/sling/hc/annotations/SlingHealthCheckProcessor.java @@ -38,10 +38,10 @@ public class SlingHealthCheckProcessor implements AnnotationProcessor { @Override public void process(final ScannedClass scannedClass, final ClassDescription classDescription) throws SCRDescriptorException, SCRDescriptorFailureException { - final List<ClassAnnotation> servlets = scannedClass.getClassAnnotations(SlingHealthCheck.class.getName()); - scannedClass.processed(servlets); + final List<ClassAnnotation> healthChecks = scannedClass.getClassAnnotations(SlingHealthCheck.class.getName()); + scannedClass.processed(healthChecks); - for (final ClassAnnotation cad : servlets) { + for (final ClassAnnotation cad : healthChecks) { processHealthCheck(cad, classDescription); } } @@ -86,22 +86,22 @@ public class SlingHealthCheckProcessor implements AnnotationProcessor { } // 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); + 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); } - /** Generates a property descriptor of type {@link PropertyType#String[]} */ - private void generateStringPropertyDescriptor(final ClassAnnotation cad, final ClassDescription classDescription, - final boolean metatype, final String propertyName, final String propertyDescriptorName, String label, String description, boolean isArray) { - + /** Generates a property descriptor of type {@link PropertyType} */ + private void generatePropertyDescriptor(final ClassAnnotation cad, final ClassDescription classDescription, + final boolean metatype, final String propertyName, final String propertyDescriptorName, PropertyType propertyType, String label, String description, boolean isArray) { final PropertyDescription pd = new PropertyDescription(cad); pd.setName(propertyDescriptorName); pd.setLabel(label); pd.setDescription(description); - pd.setType(PropertyType.String); + pd.setType(propertyType); if(isArray) { final String[] values = (String[]) cad.getValue(propertyName); @@ -109,8 +109,10 @@ public class SlingHealthCheckProcessor implements AnnotationProcessor { pd.setUnbounded(PropertyUnbounded.ARRAY); pd.setCardinality(Integer.MAX_VALUE); } else { - final String propertyVal = (String) cad.getValue(propertyName); - pd.setValue(propertyVal); + final Object propertyVal = cad.getValue(propertyName); + String pdValue = (propertyVal instanceof String) ? (String) propertyVal : + propertyVal!=null ? propertyVal.toString() : null; + pd.setValue(pdValue); pd.setUnbounded(PropertyUnbounded.DEFAULT); } @@ -119,7 +121,6 @@ public class SlingHealthCheckProcessor implements AnnotationProcessor { } classDescription.add(pd); } - @Override public int getRanking() { -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
