This is an automated email from the ASF dual-hosted git repository.

dgriffon pushed a commit to branch UNOMI-863-update-healthcheck-config
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit 1ac075c175dabed9431d29aa649b935a265739f6
Author: david.griffon <[email protected]>
AuthorDate: Wed Nov 6 17:48:01 2024 +0100

    UNOMI-863: set up OSGi DS to allow config update in the HeathCheck service.
---
 .../unomi/healthcheck/HealthCheckService.java      | 26 +++++++++-------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git 
a/extensions/healthcheck/src/main/java/org/apache/unomi/healthcheck/HealthCheckService.java
 
b/extensions/healthcheck/src/main/java/org/apache/unomi/healthcheck/HealthCheckService.java
index 54a288063..ed985eb0e 100644
--- 
a/extensions/healthcheck/src/main/java/org/apache/unomi/healthcheck/HealthCheckService.java
+++ 
b/extensions/healthcheck/src/main/java/org/apache/unomi/healthcheck/HealthCheckService.java
@@ -49,31 +49,21 @@ public class HealthCheckService {
     @Reference
     protected HttpService httpService;
 
-    @Reference(cardinality = ReferenceCardinality.MANDATORY, updated = 
"updated")
     private HealthCheckConfig config;
 
     public HealthCheckService() {
         LOGGER.info("Building healthcheck service...");
     }
 
-    public void setConfig(HealthCheckConfig config) {
-        this.config = config;
-    }
-
     @Activate
     public void activate() throws ServletException, NamespaceException {
-        if (config.isEnabled()) {
-            LOGGER.info("Activating healthcheck service...");
-            executor = Executors.newSingleThreadExecutor();
-            httpService.registerServlet("/health/check", new 
HealthCheckServlet(this), null,
-                    new HealthCheckHttpContext(config.get(CONFIG_AUTH_REALM)));
-            this.registered = true;
-        } else {
-            LOGGER.info("Healthcheck service is disabled");
-        }
+        LOGGER.info("Activating healthcheck service...");
+        executor = Executors.newSingleThreadExecutor();
     }
 
-    public void updated() throws ServletException, NamespaceException {
+    @Reference(service = HealthCheckConfig.class, policy = 
ReferencePolicy.DYNAMIC, updated = "setConfig")
+    private void setConfig(HealthCheckConfig config) throws ServletException, 
NamespaceException {
+        this.config = config;
         if (config.isEnabled()) {
             LOGGER.info("Updating healthcheck service...");
             if (registered) {
@@ -88,6 +78,10 @@ public class HealthCheckService {
         }
     }
 
+    private void unsetConfig(HealthCheckConfig config) {
+        this.config = null;
+    }
+
     @Deactivate
     public void deactivate() {
         LOGGER.info("Deactivating healthcheck service...");
@@ -112,7 +106,7 @@ public class HealthCheckService {
     }
 
     public List<HealthCheckResponse> check() throws RejectedExecutionException 
{
-        if (config.isEnabled()) {
+        if (config !=null && config.isEnabled()) {
             LOGGER.debug("Health check called");
             if (busy) {
                 throw new RejectedExecutionException("Health check already in 
progress");

Reply via email to