stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From saj...@apache.org
Subject [08/11] git commit: using executor instead of nornal threads
Date Mon, 06 Oct 2014 17:22:00 GMT
using executor instead of nornal threads


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/909c705b
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/909c705b
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/909c705b

Branch: refs/heads/master
Commit: 909c705bc34a26459b4d8c2982742e0301ccf979
Parents: d98fbcb
Author: R-Rajkumar <rraju1990@gmail.com>
Authored: Mon Oct 6 11:11:08 2014 +0530
Committer: R-Rajkumar <rraju1990@gmail.com>
Committed: Mon Oct 6 11:11:08 2014 +0530

----------------------------------------------------------------------
 .../topology/AutoscalerTopologyEventReceiver.java     |  8 ++++----
 .../autoscaler/monitor/AbstractClusterMonitor.java    | 14 ++++++++++++++
 .../monitor/KubernetesServiceClusterMonitor.java      |  7 +------
 .../autoscaler/monitor/VMLbClusterMonitor.java        |  7 +------
 .../autoscaler/monitor/VMServiceClusterMonitor.java   |  7 +------
 5 files changed, 21 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/909c705b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
index e857eaf..de058ec 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
@@ -342,10 +342,10 @@ public class AutoscalerTopologyEventReceiver implements Runnable {
                 log.error(msg);
                 throw new RuntimeException(msg);
             }
-            //TODO  private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
-            //		scheduler.scheduleAtFixedRate(monitor, 0, getMonitorInterval(), TimeUnit.MILLISECONDS);
-            Thread th = new Thread(monitor);
-            th.start();
+
+//            Thread th = new Thread(monitor);
+//            th.start();
+            monitor.startScheduler();
             AutoscalerContext.getInstance().addClusterMonitor(monitor);
             if (log.isInfoEnabled()) {
                 log.info(String.format("Cluster monitor has been added successfully: [cluster]
%s",

http://git-wip-us.apache.org/repos/asf/stratos/blob/909c705b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java
index 6061c3b..e44bd72 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/AbstractClusterMonitor.java
@@ -18,6 +18,10 @@
  */
 package org.apache.stratos.autoscaler.monitor;
 
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator;
 import org.apache.stratos.messaging.domain.topology.ClusterStatus;
 import org.apache.stratos.messaging.event.health.stat.AverageLoadAverageEvent;
@@ -62,6 +66,8 @@ public abstract class AbstractClusterMonitor implements Runnable {
     private boolean isDestroyed;
 
     private AutoscalerRuleEvaluator autoscalerRuleEvaluator;
+    
+    private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
 
     protected AbstractClusterMonitor(String clusterId, String serviceId,
                                      AutoscalerRuleEvaluator autoscalerRuleEvaluator) {
@@ -75,6 +81,14 @@ public abstract class AbstractClusterMonitor implements Runnable {
     }
 
     protected abstract void readConfigurations();
+    
+    public void startScheduler() {
+    	scheduler.scheduleAtFixedRate(this, 0, getMonitorIntervalMilliseconds(), TimeUnit.MILLISECONDS);
+    }
+    
+    protected void stopScheduler() {
+    	scheduler.shutdownNow();
+    }
 
     protected abstract void monitor();
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/909c705b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/KubernetesServiceClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/KubernetesServiceClusterMonitor.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/KubernetesServiceClusterMonitor.java
index 3c81ba3..93580d9 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/KubernetesServiceClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/KubernetesServiceClusterMonitor.java
@@ -59,7 +59,6 @@ public final class KubernetesServiceClusterMonitor extends KubernetesClusterMoni
     @Override
     public void run() {
 
-        while (!isDestroyed()) {
             if (log.isDebugEnabled()) {
                 log.debug("KubernetesServiceClusterMonitor is running.. " + this.toString());
             }
@@ -76,11 +75,6 @@ public final class KubernetesServiceClusterMonitor extends KubernetesClusterMoni
                 log.error("KubernetesServiceClusterMonitor : Monitor failed." + this.toString(),
                           e);
             }
-            try {
-                Thread.sleep(getMonitorIntervalMilliseconds());
-            } catch (InterruptedException ignore) {
-            }
-        }
     }
 
     @Override
@@ -148,6 +142,7 @@ public final class KubernetesServiceClusterMonitor extends KubernetesClusterMoni
         getMinCheckKnowledgeSession().dispose();
         getScaleCheckKnowledgeSession().dispose();
         setDestroyed(true);
+        stopScheduler();
         if (log.isDebugEnabled()) {
             log.debug("KubernetesServiceClusterMonitor Drools session has been disposed.
" + this.toString());
         }

http://git-wip-us.apache.org/repos/asf/stratos/blob/909c705b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMLbClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMLbClusterMonitor.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMLbClusterMonitor.java
index a0c66f0..f950f9d 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMLbClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMLbClusterMonitor.java
@@ -57,7 +57,6 @@ public class VMLbClusterMonitor extends VMClusterMonitor {
     @Override
     public void run() {
 
-        while (!isDestroyed()) {
             if (log.isDebugEnabled()) {
                 log.debug("VMLbClusterMonitor is running.. " + this.toString());
             }
@@ -73,11 +72,6 @@ public class VMLbClusterMonitor extends VMClusterMonitor {
             } catch (Exception e) {
                 log.error("VMLbClusterMonitor : Monitor failed. " + this.toString(), e);
             }
-            try {
-                Thread.sleep(getMonitorIntervalMilliseconds());
-            } catch (InterruptedException ignore) {
-            }
-        }
     }
 
     @Override
@@ -116,6 +110,7 @@ public class VMLbClusterMonitor extends VMClusterMonitor {
         getMinCheckKnowledgeSession().dispose();
         getMinCheckKnowledgeSession().dispose();
         setDestroyed(true);
+        stopScheduler();
         if (log.isDebugEnabled()) {
             log.debug("VMLbClusterMonitor Drools session has been disposed. " + this.toString());
         }

http://git-wip-us.apache.org/repos/asf/stratos/blob/909c705b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMServiceClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMServiceClusterMonitor.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMServiceClusterMonitor.java
index 0452e32..d8c9e69 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMServiceClusterMonitor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/VMServiceClusterMonitor.java
@@ -67,7 +67,6 @@ public class VMServiceClusterMonitor extends VMClusterMonitor {
         } catch (InterruptedException ignore) {
         }
 
-        while (!isDestroyed()) {
             if (log.isDebugEnabled()) {
                 log.debug("VMServiceClusterMonitor is running.. " + this.toString());
             }
@@ -83,11 +82,6 @@ public class VMServiceClusterMonitor extends VMClusterMonitor {
             } catch (Exception e) {
                 log.error("VMServiceClusterMonitor : Monitor failed." + this.toString(),
e);
             }
-            try {
-                Thread.sleep(getMonitorIntervalMilliseconds());
-            } catch (InterruptedException ignore) {
-            }
-        }
     }
 
     @Override
@@ -199,6 +193,7 @@ public class VMServiceClusterMonitor extends VMClusterMonitor {
         getMinCheckKnowledgeSession().dispose();
         getScaleCheckKnowledgeSession().dispose();
         setDestroyed(true);
+        stopScheduler();
         if (log.isDebugEnabled()) {
             log.debug("VMServiceClusterMonitor Drools session has been disposed. " + this.toString());
         }


Mime
View raw message