You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2014/02/08 16:21:13 UTC

[2/4] git commit: adding more logs and improving singleton constructor

adding more logs and improving singleton constructor


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

Branch: refs/heads/master
Commit: 29732ccb5c8e619cccbbdb8dcc2c71ca4285edaf
Parents: e980b79
Author: Nirmal Fernando <ni...@apache.org>
Authored: Sat Feb 8 20:48:33 2014 +0530
Committer: Nirmal Fernando <ni...@apache.org>
Committed: Sat Feb 8 20:48:33 2014 +0530

----------------------------------------------------------------------
 .../stratos/autoscaler/AutoscalerContext.java   | 29 ++++++----
 .../topology/AutoscalerTopologyReceiver.java    | 60 ++++++++++----------
 2 files changed, 48 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/29732ccb/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AutoscalerContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AutoscalerContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AutoscalerContext.java
index 7b4b8da..d04bdcc 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AutoscalerContext.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AutoscalerContext.java
@@ -30,16 +30,13 @@ public class AutoscalerContext {
     // Map<LBClusterId, LBClusterMonitor>
     private Map<String, LbClusterMonitor> lbMonitors;
 
-    public static AutoscalerContext getInstance() {
-        if (instance == null) {
-            synchronized (AutoscalerContext.class){
-                if (instance == null) {
-                    instance = new AutoscalerContext();
-                }
-            }
-        }
-        return instance;
-    }
+	private static class Holder {
+		private static final AutoscalerContext INSTANCE = new AutoscalerContext();
+	}
+
+	public static AutoscalerContext getInstance() {
+		return Holder.INSTANCE;
+	}
 
     public void addMonitor(ClusterMonitor monitor) {
         monitors.put(monitor.getClusterId(), monitor);
@@ -62,11 +59,19 @@ public class AutoscalerContext {
     }
 
     public ClusterMonitor removeMonitor(String clusterId) {
-    	log.info("Remove moniter clusterid" + clusterId);
+    	if(!moniterExist(clusterId)) {
+    		log.fatal("Cluster monitor not found for cluster id: "+clusterId);
+    		return null;
+    	}
+    	log.info("Removed monitor [cluster id]: " + clusterId);
         return monitors.remove(clusterId);
     }
     public LbClusterMonitor removeLbMonitor(String clusterId) {
-    	log.info("Remove moniter clusterid" + clusterId);
+    	if(!lbMoniterExist(clusterId)) {
+    		log.fatal("LB monitor not found for cluster id: "+clusterId);
+    		return null;
+    	}
+    	log.info("Removed LB monitor [cluster id]: " + clusterId);
         return lbMonitors.remove(clusterId);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/29732ccb/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyReceiver.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyReceiver.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyReceiver.java
index 59ccfb1..43d1b2e 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyReceiver.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyReceiver.java
@@ -141,35 +141,37 @@ public class AutoscalerTopologyReceiver implements Runnable {
 
         });
         
-        processorChain.addEventListener(new ClusterRemovedEventListener() {
-            @Override
-            protected void onEvent(Event event) {
-            try {
-                ClusterRemovedEvent e = (ClusterRemovedEvent) event;
-                TopologyManager.acquireReadLock();
-                String serviceName = e.getServiceName();
-                String clusterId = e.getClusterId();
-                AbstractMonitor monitor;
-
-                if(e.isLbCluster()){
-                    monitor = AutoscalerContext.getInstance().removeLbMonitor(clusterId);
-
-                } else {
-                    monitor = AutoscalerContext.getInstance().removeMonitor(clusterId);
-                }
-
-//                runTerminateAllRule(monitor);
-                monitor.destroy();
-                if(log.isDebugEnabled()) {
-                    log.debug(String.format("Cluster monitor has been removed successfully: [cluster] %s ", clusterId));
-                }
-            }
-            finally {
-                TopologyManager.releaseReadLock();
-            }
-            }
-
-        });
+		processorChain.addEventListener(new ClusterRemovedEventListener() {
+			@Override
+			protected void onEvent(Event event) {
+				try {
+					ClusterRemovedEvent e = (ClusterRemovedEvent) event;
+					TopologyManager.acquireReadLock();
+					String serviceName = e.getServiceName();
+					String clusterId = e.getClusterId();
+					AbstractMonitor monitor;
+
+					if (e.isLbCluster()) {
+						monitor = AutoscalerContext.getInstance()
+								.removeLbMonitor(clusterId);
+
+					} else {
+						monitor = AutoscalerContext.getInstance()
+								.removeMonitor(clusterId);
+					}
+
+					// runTerminateAllRule(monitor);
+					if (monitor != null) {
+						monitor.destroy();
+						log.info(String.format("Cluster monitor has been removed successfully: [cluster] %s ",
+										clusterId));
+					} 
+				} finally {
+					TopologyManager.releaseReadLock();
+				}
+			}
+
+		});
         
         processorChain.addEventListener(new MemberStartedEventListener() {
             @Override