You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by re...@apache.org on 2015/08/14 21:47:25 UTC

[02/30] git commit: updated refs/heads/master to 64ff67d

CLOUDSTACK-8656: try-with-resource in  vmsd reader
 moved closeable util function up the hierarchy


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

Branch: refs/heads/master
Commit: e8a00ed989f17ce235a201fadba37f00d2ded7c3
Parents: afcdbc4
Author: Daan Hoogland <da...@onecht.net>
Authored: Tue Aug 4 00:41:10 2015 +0200
Committer: Daan Hoogland <da...@gmail.com>
Committed: Tue Aug 4 11:37:06 2015 +0200

----------------------------------------------------------------------
 framework/db/src/com/cloud/utils/db/DbUtil.java | 14 ++------
 .../src/com/cloud/utils/AutoCloseableUtil.java  | 36 ++++++++++++++++++++
 .../vmware/mo/SnapshotDescriptor.java           | 17 +++------
 3 files changed, 42 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e8a00ed9/framework/db/src/com/cloud/utils/db/DbUtil.java
----------------------------------------------------------------------
diff --git a/framework/db/src/com/cloud/utils/db/DbUtil.java b/framework/db/src/com/cloud/utils/db/DbUtil.java
index d868905..2b52188 100644
--- a/framework/db/src/com/cloud/utils/db/DbUtil.java
+++ b/framework/db/src/com/cloud/utils/db/DbUtil.java
@@ -43,6 +43,8 @@ import javax.persistence.Transient;
 
 import org.apache.log4j.Logger;
 
+import static com.cloud.utils.AutoCloseableUtil.closeAutoCloseable;
+
 public class DbUtil {
     protected final static Logger s_logger = Logger.getLogger(DbUtil.class);
 
@@ -284,16 +286,4 @@ public class DbUtil {
         closeAutoCloseable(connection, "exception while close connection.");
     }
 
-    public static void closeAutoCloseable(AutoCloseable ac, String message) {
-        try {
-
-            if (ac != null) {
-                ac.close();
-            }
-
-        } catch (Exception e) {
-            s_logger.warn("[ignored] " + message, e);
-        }
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e8a00ed9/utils/src/com/cloud/utils/AutoCloseableUtil.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/AutoCloseableUtil.java b/utils/src/com/cloud/utils/AutoCloseableUtil.java
new file mode 100644
index 0000000..f93265b
--- /dev/null
+++ b/utils/src/com/cloud/utils/AutoCloseableUtil.java
@@ -0,0 +1,36 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.utils;
+
+import org.apache.log4j.Logger;
+
+public class AutoCloseableUtil {
+    private final static Logger s_logger = Logger.getLogger(AutoCloseableUtil.class);
+
+    public static void closeAutoCloseable(AutoCloseable ac, String message) {
+        try {
+
+            if (ac != null) {
+                ac.close();
+            }
+
+        } catch (Exception e) {
+            s_logger.warn("[ignored] " + message, e);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e8a00ed9/vmware-base/src/com/cloud/hypervisor/vmware/mo/SnapshotDescriptor.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/SnapshotDescriptor.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/SnapshotDescriptor.java
index 0499be9..82a225e 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/SnapshotDescriptor.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/SnapshotDescriptor.java
@@ -31,7 +31,7 @@ import org.apache.log4j.Logger;
 public class SnapshotDescriptor {
     private static final Logger s_logger = Logger.getLogger(SnapshotDescriptor.class);
 
-    private Properties _properties = new Properties();
+    private final Properties _properties = new Properties();
 
     public SnapshotDescriptor() {
     }
@@ -90,11 +90,9 @@ public class SnapshotDescriptor {
     }
 
     public byte[] getVmsdContent() {
-        BufferedWriter out = null;
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
 
-        try {
-            out = new BufferedWriter(new OutputStreamWriter(bos, "UTF-8"));
+        try (BufferedWriter out = new BufferedWriter(new OutputStreamWriter(bos, "UTF-8"));) {
 
             out.write(".encoding = \"UTF-8\"");
             out.newLine();
@@ -165,13 +163,6 @@ public class SnapshotDescriptor {
         } catch (IOException e) {
             assert (false);
             s_logger.error("Unexpected exception ", e);
-        } finally {
-            if (out != null) {
-                try {
-                    out.close();
-                } catch (IOException e) {
-                }
-            }
         }
 
         return bos.toByteArray();
@@ -288,8 +279,8 @@ public class SnapshotDescriptor {
     }
 
     public static class DiskInfo {
-        private String _diskFileName;
-        private String _deviceName;
+        private final String _diskFileName;
+        private final String _deviceName;
 
         public DiskInfo(String diskFileName, String deviceName) {
             _diskFileName = diskFileName;