From f1013b884b903859d83d8b3beb3c1318e5015722 Mon Sep 17 00:00:00 2001 From: IndikaKuma Date: Fri, 31 Jul 2020 13:05:56 +0200 Subject: [PATCH] Fix an issue with cancel/enable monitoring --- .../java/nl/jads/sodalite/api/RefactoringService.java | 2 +- .../sodalite/scheduler/MonitoringDataCollector.java | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/rule-based/src/main/java/nl/jads/sodalite/api/RefactoringService.java b/rule-based/src/main/java/nl/jads/sodalite/api/RefactoringService.java index 3b77603..a465f58 100644 --- a/rule-based/src/main/java/nl/jads/sodalite/api/RefactoringService.java +++ b/rule-based/src/main/java/nl/jads/sodalite/api/RefactoringService.java @@ -144,7 +144,7 @@ public Response enableDisableMonitoring(@DefaultValue("disabled") @QueryParam("s return Response.status(500).entity(e.getMessage()).build(); } } else { - monitoringDataCollector.shutdown(); + monitoringDataCollector.cancelTask(); return Response.status(200).entity("Monitoring Disabled/Stopped").build(); } diff --git a/rule-based/src/main/java/nl/jads/sodalite/scheduler/MonitoringDataCollector.java b/rule-based/src/main/java/nl/jads/sodalite/scheduler/MonitoringDataCollector.java index 5265518..544ea9e 100644 --- a/rule-based/src/main/java/nl/jads/sodalite/scheduler/MonitoringDataCollector.java +++ b/rule-based/src/main/java/nl/jads/sodalite/scheduler/MonitoringDataCollector.java @@ -2,19 +2,27 @@ import java.util.TimerTask; import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; public class MonitoringDataCollector { private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); private TimerTask repeatedTask = new MonitoringTimerTask(); + private Future future; public void start() throws InterruptedException { long delay = 1000L; long period = 1000L; System.out.println("Monitoring Data Collector Started"); - executor.scheduleAtFixedRate(repeatedTask, delay, period, TimeUnit.MILLISECONDS); + //get reference to the future + future = executor.scheduleAtFixedRate(repeatedTask, delay, period, TimeUnit.MILLISECONDS); + } + + public void cancelTask() { + System.out.println("Canceling Monitoring Task"); + future.cancel(false); } public void shutdown() {