You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2015/06/04 00:10:29 UTC

[1/2] git commit: updated refs/heads/4.5 to 5fb86ae

Repository: cloudstack
Updated Branches:
  refs/heads/4.5 d55d45348 -> 5fb86ae31


CID 1302974: Scanner in try-with-resource

Signed-off-by: Rohit Yadav <ro...@shapeblue.com>

This closes #353

(cherry picked from commit 109b6e94d39d7c6db4ff721c4699e42abe47ec5e)
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>


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

Branch: refs/heads/4.5
Commit: fb50283fbe7875ce64992e268fb9ad5792e75962
Parents: d55d453
Author: Daan Hoogland <da...@gmail.com>
Authored: Wed Jun 3 17:37:13 2015 +0200
Committer: Rohit Yadav <ro...@shapeblue.com>
Committed: Thu Jun 4 00:10:05 2015 +0200

----------------------------------------------------------------------
 .../src/org/apache/cloudstack/utils/linux/MemStat.java | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fb50283f/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/linux/MemStat.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/linux/MemStat.java b/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/linux/MemStat.java
index 1e3c872..1d6a4fc 100644
--- a/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/linux/MemStat.java
+++ b/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/linux/MemStat.java
@@ -16,11 +16,10 @@
 // under the License.
 package org.apache.cloudstack.utils.linux;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Scanner;
 
 public class MemStat {
@@ -29,7 +28,7 @@ public class MemStat {
     protected final static String CACHE_KEY = "Cached";
     protected final static String TOTAL_KEY = "MemTotal";
 
-    private Map<String, Double> _memStats = new HashMap<String, Double>();
+    private final Map<String, Double> _memStats = new HashMap<String, Double>();
 
     public MemStat() {
     }
@@ -51,9 +50,9 @@ public class MemStat {
     }
 
     public void refresh() {
-        try {
-            Scanner fileScanner = new Scanner(new File(MEMINFO_FILE));
-            parseFromScanner(fileScanner);
+        File f = new File(MEMINFO_FILE);
+        try (Scanner scanner = new Scanner(f)) {
+            parseFromScanner(scanner);
         } catch (FileNotFoundException ex) {
             throw new RuntimeException("File " + MEMINFO_FILE + " not found:" + ex.toString());
         }


[2/2] git commit: updated refs/heads/4.5 to 5fb86ae

Posted by bh...@apache.org.
CID 1302976 Scanner in try-with-resource

Signed-off-by: Rohit Yadav <ro...@shapeblue.com>

This closes #352

(cherry picked from commit 3d4d15275340bd9bbec76afb535e4a48371ef421)
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>


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

Branch: refs/heads/4.5
Commit: 5fb86ae316d5e6703e2c54075b8d01149ec8e343
Parents: fb50283
Author: Daan Hoogland <da...@gmail.com>
Authored: Wed Jun 3 17:31:19 2015 +0200
Committer: Rohit Yadav <ro...@shapeblue.com>
Committed: Thu Jun 4 00:10:18 2015 +0200

----------------------------------------------------------------------
 .../kvm/src/org/apache/cloudstack/utils/linux/CPUStat.java  | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5fb86ae3/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/linux/CPUStat.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/linux/CPUStat.java b/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/linux/CPUStat.java
index 38b7e8e..d8228a4 100644
--- a/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/linux/CPUStat.java
+++ b/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/linux/CPUStat.java
@@ -17,12 +17,12 @@
 
 package org.apache.cloudstack.utils.linux;
 
-import org.apache.log4j.Logger;
-
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.util.Scanner;
 
+import org.apache.log4j.Logger;
+
 public class CPUStat {
     private static final Logger s_logger = Logger.getLogger(CPUStat.class);
 
@@ -52,8 +52,9 @@ public class CPUStat {
 
     private UptimeStats getUptimeAndCpuIdleTime() {
         UptimeStats uptime = new UptimeStats(0d, 0d);
-        try {
-            String[] stats =  new Scanner(new File(_uptimeFile)).useDelimiter("\\Z").next().split("\\s+");
+        File f = new File(_uptimeFile);
+        try (Scanner scanner = new Scanner(f);) {
+            String[] stats = scanner.useDelimiter("\\Z").next().split("\\s+");
             uptime = new UptimeStats(Double.parseDouble(stats[0]), Double.parseDouble(stats[1]));
         } catch (FileNotFoundException ex) {
             s_logger.warn("File " + _uptimeFile + " not found:" + ex.toString());