You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by sh...@apache.org on 2021/10/11 08:43:10 UTC

[unomi] branch master updated: remove timer when stopping groovy extensions (#352)

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

shuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/unomi.git


The following commit(s) were added to refs/heads/master by this push:
     new d9d8ec2  remove timer when stopping groovy extensions (#352)
d9d8ec2 is described below

commit d9d8ec2e5c63e79effe8a1f712ddff86373d2144
Author: jsinovassin <58...@users.noreply.github.com>
AuthorDate: Mon Oct 11 10:43:03 2021 +0200

    remove timer when stopping groovy extensions (#352)
---
 .../actions/services/impl/GroovyActionsServiceImpl.java       | 11 ++++++++++-
 .../src/main/resources/OSGI-INF/blueprint/blueprint.xml       |  2 +-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/services/impl/GroovyActionsServiceImpl.java b/extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/services/impl/GroovyActionsServiceImpl.java
index bf4842f..fc2f62c 100644
--- a/extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/services/impl/GroovyActionsServiceImpl.java
+++ b/extensions/groovy-actions/services/src/main/java/org/apache/unomi/groovy/actions/services/impl/GroovyActionsServiceImpl.java
@@ -45,6 +45,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.TimerTask;
+import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -64,6 +65,8 @@ public class GroovyActionsServiceImpl implements GroovyActionsService {
 
     private Map<String, GroovyCodeSource> groovyCodeSourceMap;
 
+    private ScheduledFuture<?> scheduledFuture;
+
     private static final Logger logger = LoggerFactory.getLogger(GroovyActionsServiceImpl.class.getName());
 
     private static final String BASE_SCRIPT_NAME = "BaseScript";
@@ -128,6 +131,11 @@ public class GroovyActionsServiceImpl implements GroovyActionsService {
         logger.info("Groovy action service initialized.");
     }
 
+    public void onDestroy(){
+        logger.debug("onDestroy Method called");
+        scheduledFuture.cancel(true);
+    }
+
     /**
      * Load the Base script.
      * It's a script which provides utility functions that we can use in other groovy script
@@ -257,6 +265,7 @@ public class GroovyActionsServiceImpl implements GroovyActionsService {
                 refreshGroovyActions();
             }
         };
-        schedulerService.getScheduleExecutorService().scheduleWithFixedDelay(task, 0, groovyActionsRefreshInterval, TimeUnit.MILLISECONDS);
+        scheduledFuture = schedulerService.getScheduleExecutorService().scheduleWithFixedDelay(task, 0, groovyActionsRefreshInterval,
+                TimeUnit.MILLISECONDS);
     }
 }
diff --git a/extensions/groovy-actions/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/extensions/groovy-actions/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index 1f9bd40..433cd54 100644
--- a/extensions/groovy-actions/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/extensions/groovy-actions/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -34,7 +34,7 @@
     <reference id="actionExecutorDispatcher" interface="org.apache.unomi.services.actions.ActionExecutorDispatcher"/>
 
     <bean id="groovyActionsServiceImpl" class="org.apache.unomi.groovy.actions.services.impl.GroovyActionsServiceImpl"
-          init-method="postConstruct">
+          init-method="postConstruct" destroy-method="onDestroy">
         <property name="bundleContext" ref="blueprintBundleContext"/>
         <property name="definitionsService" ref="definitionsService"/>
         <property name="persistenceService" ref="persistenceService"/>