stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From im...@apache.org
Subject stratos git commit: Removing mock statistics read/write locks
Date Thu, 11 Dec 2014 19:30:29 GMT
Repository: stratos
Updated Branches:
  refs/heads/4.1.0-test 500c4af3b -> fcc30c217


Removing mock statistics read/write locks


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

Branch: refs/heads/4.1.0-test
Commit: fcc30c2178df05fb190a69c7af8c43831c534701
Parents: 500c4af
Author: Imesh Gunaratne <imesh@apache.org>
Authored: Fri Dec 12 01:00:20 2014 +0530
Committer: Imesh Gunaratne <imesh@apache.org>
Committed: Fri Dec 12 01:00:20 2014 +0530

----------------------------------------------------------------------
 .../mock/statistics/MockHealthStatistics.java   | 43 ++-----------
 .../generator/MockHealthStatisticsUpdater.java  |  4 --
 .../publisher/MockHealthStatisticsNotifier.java | 64 +++++++++-----------
 3 files changed, 35 insertions(+), 76 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/fcc30c21/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatistics.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatistics.java
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatistics.java
index 50e6564..9ac4d8a 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatistics.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/MockHealthStatistics.java
@@ -35,11 +35,9 @@ public class MockHealthStatistics {
 
     private static volatile MockHealthStatistics instance;
 
-    private Map<String, ReentrantReadWriteLock> lockMap;
     private Map<String, Map<String, Integer>> statisticsMap;
 
     private MockHealthStatistics() {
-        lockMap = new ConcurrentHashMap<String, ReentrantReadWriteLock>();
         statisticsMap = new ConcurrentHashMap<String, Map<String, Integer>>();
     }
 
@@ -54,44 +52,15 @@ public class MockHealthStatistics {
         return instance;
     }
 
-    public void acquireReadLock(String cartridgeType) {
-        ReentrantReadWriteLock lock = getLock(cartridgeType);
-        lock.readLock().lock();
-    }
-
-    public void acquireWriteLock(String cartridgeType) {
-        ReentrantReadWriteLock lock = getLock(cartridgeType);
-        lock.writeLock().lock();
-    }
-
-    public void releaseReadLock(String cartridgeType) {
-        ReentrantReadWriteLock lock = getLock(cartridgeType);
-        lock.readLock().unlock();
-    }
-
-    public void releaseWriteLock(String cartridgeType) {
-        ReentrantReadWriteLock lock = getLock(cartridgeType);
-        lock.writeLock().unlock();
-    }
-
-    private ReentrantReadWriteLock getLock(String cartridgeType) {
-        ReentrantReadWriteLock lock = lockMap.get(cartridgeType);
-        if(lock == null) {
-            synchronized (MockHealthStatistics.class) {
-                if(lock == null) {
-                    lock = new ReentrantReadWriteLock();
-                    lockMap.put(cartridgeType, lock);
-                }
-            }
-        }
-        return lock;
-    }
-
     public void addStatistics(String cartridgeType, MockAutoscalingFactor autoscalingFactor,
Integer value) {
         Map<String, Integer> factorValueMap = statisticsMap.get(cartridgeType);
         if(factorValueMap == null) {
-            factorValueMap = new ConcurrentHashMap<String, Integer>();
-            statisticsMap.put(cartridgeType, factorValueMap);
+            synchronized (MockHealthStatistics.class) {
+                if(factorValueMap == null) {
+                    factorValueMap = new ConcurrentHashMap<String, Integer>();
+                    statisticsMap.put(cartridgeType, factorValueMap);
+                }
+            }
         }
         factorValueMap.put(autoscalingFactor.toString(), value);
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/fcc30c21/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsUpdater.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsUpdater.java
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsUpdater.java
index fd697a2..dd2aec8 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsUpdater.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/generator/MockHealthStatisticsUpdater.java
@@ -40,8 +40,6 @@ public class MockHealthStatisticsUpdater implements Runnable {
     @Override
     public void run() {
         try {
-            MockHealthStatistics.getInstance().acquireWriteLock(statisticsPattern.getCartridgeType());
-
             int nextSample = statisticsPattern.getNextSample();
             MockHealthStatistics.getInstance().addStatistics(statisticsPattern.getCartridgeType(),
                     statisticsPattern.getFactor(), nextSample);
@@ -52,8 +50,6 @@ public class MockHealthStatisticsUpdater implements Runnable {
             }
         } catch (Exception e) {
             log.error("Could not update mock statistics", e);
-        } finally {
-            MockHealthStatistics.getInstance().releaseWriteLock(statisticsPattern.getCartridgeType());
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/fcc30c21/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsNotifier.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsNotifier.java
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsNotifier.java
index 2fd33c4..94744af 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsNotifier.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/statistics/publisher/MockHealthStatisticsNotifier.java
@@ -47,44 +47,38 @@ public class MockHealthStatisticsNotifier implements Runnable {
     public void run() {
         try {
             if (statsPublisher.isEnabled()) {
-                try {
-                    MockHealthStatistics.getInstance().acquireReadLock(mockMemberContext.getServiceName());
+                double memoryConsumption = MockHealthStatistics.getInstance().getStatistics(
+                        mockMemberContext.getServiceName(), MockAutoscalingFactor.MemoryConsumption);
+                double loadAvereage = MockHealthStatistics.getInstance().getStatistics(
+                        mockMemberContext.getServiceName(), MockAutoscalingFactor.LoadAverage);
 
-                    double memoryConsumption = MockHealthStatistics.getInstance().getStatistics(
-                            mockMemberContext.getServiceName(), MockAutoscalingFactor.MemoryConsumption);
-                    double loadAvereage = MockHealthStatistics.getInstance().getStatistics(
-                            mockMemberContext.getServiceName(), MockAutoscalingFactor.LoadAverage);
-
-                     if (log.isDebugEnabled()) {
-                        log.debug(String.format("Publishing memory consumption: [member-id]
%s [value] %f",
-                                mockMemberContext.getMemberId(), memoryConsumption));
-                    }
-                    statsPublisher.publish(
-                            mockMemberContext.getClusterId(),
-                            mockMemberContext.getInstanceId(),
-                            mockMemberContext.getNetworkPartitionId(),
-                            mockMemberContext.getMemberId(),
-                            mockMemberContext.getPartitionId(),
-                            MEMORY_CONSUMPTION,
-                            memoryConsumption
-                    );
+                if (log.isDebugEnabled()) {
+                    log.debug(String.format("Publishing memory consumption: [member-id] %s
[value] %f",
+                            mockMemberContext.getMemberId(), memoryConsumption));
+                }
+                statsPublisher.publish(
+                        mockMemberContext.getClusterId(),
+                        mockMemberContext.getInstanceId(),
+                        mockMemberContext.getNetworkPartitionId(),
+                        mockMemberContext.getMemberId(),
+                        mockMemberContext.getPartitionId(),
+                        MEMORY_CONSUMPTION,
+                        memoryConsumption
+                );
 
-                    if (log.isDebugEnabled()) {
-                        log.debug(String.format("Publishing load average: [member-id] %s
[value] %f",
-                                mockMemberContext.getMemberId(), loadAvereage));
-                    }
-                    statsPublisher.publish(
-                            mockMemberContext.getClusterId(),
-                            mockMemberContext.getInstanceId(),
-                            mockMemberContext.getNetworkPartitionId(),
-                            mockMemberContext.getMemberId(),
-                            mockMemberContext.getPartitionId(),
-                            LOAD_AVERAGE,
-                            loadAvereage
-                    );
-                } finally {
-                    MockHealthStatistics.getInstance().releaseReadLock(mockMemberContext.getServiceName());
+                if (log.isDebugEnabled()) {
+                    log.debug(String.format("Publishing load average: [member-id] %s [value]
%f",
+                            mockMemberContext.getMemberId(), loadAvereage));
                 }
+                statsPublisher.publish(
+                        mockMemberContext.getClusterId(),
+                        mockMemberContext.getInstanceId(),
+                        mockMemberContext.getNetworkPartitionId(),
+                        mockMemberContext.getMemberId(),
+                        mockMemberContext.getPartitionId(),
+                        LOAD_AVERAGE,
+                        loadAvereage
+                );
             } else if (log.isWarnEnabled()) {
                 log.warn("Statistics publisher is disabled");
             }


Mime
View raw message