SLING-4417 allow to configure immediate flag in the healthcheck annotation and use that in some examples

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1732260 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/hc/samples/impl/AsyncHealthCheckSample.java b/src/main/java/org/apache/sling/hc/samples/impl/AsyncHealthCheckSample.java
index acee4f9..41fa248 100644
--- a/src/main/java/org/apache/sling/hc/samples/impl/AsyncHealthCheckSample.java
+++ b/src/main/java/org/apache/sling/hc/samples/impl/AsyncHealthCheckSample.java
@@ -42,9 +42,7 @@
 
     private final Logger log = LoggerFactory.getLogger(AsyncHealthCheckSample.class);
     
-    // static because for factories, not always the same instance is returned for 
-    // the same service reference
-    private static final AtomicInteger counter = new AtomicInteger();
+    private final AtomicInteger counter = new AtomicInteger();
     
     public static final int PERIOD_SECONDS = 5;
     
diff --git a/src/main/java/org/apache/sling/hc/samples/impl/SlowHealthCheckSample.java b/src/main/java/org/apache/sling/hc/samples/impl/SlowHealthCheckSample.java
index 740a62b..b2a2492 100644
--- a/src/main/java/org/apache/sling/hc/samples/impl/SlowHealthCheckSample.java
+++ b/src/main/java/org/apache/sling/hc/samples/impl/SlowHealthCheckSample.java
@@ -21,14 +21,11 @@
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.ConfigurationPolicy;
 import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Properties;
 import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.PropertyUnbounded;
-import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.apache.sling.hc.annotations.SlingHealthCheck;
 import org.apache.sling.hc.api.HealthCheck;
 import org.apache.sling.hc.api.Result;
 import org.apache.sling.hc.util.FormattingResultLog;
@@ -39,22 +36,8 @@
  *  used to demonstrate execution timeouts and caching.
  */
 
-// Need to make the component immediate to make sure a single 
-// instance is used, otherwise the lazy DS activation policy
-// might cause a different instance to be used for every
-// execution. In this sample this is just done to allow the
-// counter to persist as long as this service's bundle is active.
-@Component(
-        configurationFactory=true,
-        policy=ConfigurationPolicy.REQUIRE,
-        metatype=true,
-        immediate=true)
-@Properties({
-    @Property(name=HealthCheck.NAME),
-    @Property(name=HealthCheck.TAGS, unbounded=PropertyUnbounded.ARRAY),
-    @Property(name=HealthCheck.MBEAN_NAME)
-})
-@Service(value=HealthCheck.class)
+// The annotation make the component immediate by default now
+@SlingHealthCheck(configurationFactory = true, configurationPolicy = ConfigurationPolicy.REQUIRE)
 public class SlowHealthCheckSample implements HealthCheck{
 
     private final Logger log = LoggerFactory.getLogger(getClass());