Merge "Reorder modifiers"
[so.git] / bpmn / MSOCoreBPMN / src / main / java / org / openecomp / mso / bpmn / core / PropertyConfiguration.java
index 9d3af1c..f75722e 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP - SO
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -84,14 +85,21 @@ public class PropertyConfiguration {
        private volatile String msoConfigPath = null;
 
        private final ConcurrentHashMap<String, Map<String, String>> propFileCache =
-               new ConcurrentHashMap<String, Map<String, String>>();
+               new ConcurrentHashMap<>();
 
        private final Object CACHELOCK = new Object();
        private FileWatcherThread fileWatcherThread = null;
 
        // The key is the file name
-       private Map<String, TimerTask> timerTaskMap = new HashMap<String, TimerTask>();
+       private Map<String, TimerTask> timerTaskMap = new HashMap<>();
 
+       /**
+     * Private Constructor.
+     */
+    private PropertyConfiguration() {
+        startUp();
+    }
+                       
        /**
         * Singleton holder pattern eliminates locking when accessing the instance
         * and still provides for lazy initialization.
@@ -107,18 +115,15 @@ public class PropertyConfiguration {
                return PropertyConfigurationInstanceHolder.instance;
        }
 
-       /**
-        * Returns the list of supported files.
-        */
-       public static List<String> supportedFiles() {
-               return new ArrayList<String>(SUPPORTED_FILES);
+       static void resetPropertyConfigurationSingletonInstance(){
+               PropertyConfigurationInstanceHolder.instance = new PropertyConfiguration();
        }
 
        /**
-        * Private Constructor.
+        * Returns the list of supported files.
         */
-       private PropertyConfiguration() {
-               startUp();
+       public static List<String> supportedFiles() {
+               return new ArrayList<>(SUPPORTED_FILES);
        }
 
        /**
@@ -167,7 +172,7 @@ public class PropertyConfiguration {
                                fileWatcherThread.join(waitInSeconds * 1000);
                        } catch (InterruptedException e) {
                                LOGGER.debug("FileWatcherThread " + System.identityHashCode(fileWatcherThread)
-                                       + " shutdown did not occur within " + waitInSeconds + " seconds");
+                                       + " shutdown did not occur within " + waitInSeconds + " seconds",e);
                        }
 
                        LOGGER.debug("Finished shutting down FileWatcherThread " + System.identityHashCode(fileWatcherThread));
@@ -237,29 +242,20 @@ public class PropertyConfiguration {
         * Reads properties from the specified file, updates the property file cache, and
         * returns the properties in a map.
         * @param file the file to read
-        * @param reload true if this is a reload event
         * @return a map of properties
         */
        private Map<String, String> readProperties(File file) throws IOException {
                String fileName = file.getName();
                LOGGER.debug("Reading " + fileName);
 
-               Map<String, String> properties = new HashMap<String, String>();
+               Map<String, String> properties = new HashMap<>();
                Properties newProperties = new Properties();
 
-               FileReader reader = null;
-               try {
-                       reader = new FileReader(file);
+               try (FileReader reader = new FileReader(file)) {
                        newProperties.load(reader);
-               } finally {
-                       if (reader != null) {
-                               try {
-                                       reader.close();
-                                       LOGGER.debug("Closed " + fileName);
-                               } catch (Exception e) {
-                                       // Ignore
-                               }
-                       }
+               }
+               catch (Exception e) {
+                       LOGGER.debug("Exception :",e);
                }
 
                for (Entry<Object, Object> entry : newProperties.entrySet()) {
@@ -290,6 +286,7 @@ public class PropertyConfiguration {
                        interrupt();
                }
 
+               @Override
                public void run() {
                        LOGGER.info(MessageEnum.BPMN_GENERAL_INFO, "BPMN",
                                "FileWatcherThread started");
@@ -351,12 +348,14 @@ public class PropertyConfiguration {
                                                        }
                                                }
                                        } catch (InterruptedException e) {
+                                               LOGGER.debug("InterruptedException :",e);
                                                break;
                                        } catch (ClosedWatchServiceException e) {
                                                LOGGER.info(
                                                                MessageEnum.BPMN_GENERAL_INFO,
                                                                "BPMN",
                                                                "FileWatcherThread shut down because the watch service was closed");
+                                               LOGGER.debug("ClosedWatchServiceException :",e);
                                                break;
                                        } catch (Exception e) {
                                                LOGGER.error(
@@ -379,7 +378,7 @@ public class PropertyConfiguration {
                                        watchService.close();
                                } catch (IOException e) {
                                        LOGGER.debug("FileWatcherThread caught " + e.getClass().getSimpleName()
-                                               + " while closing the watch service");
+                                               + " while closing the watch service",e);
                                }
 
                                LOGGER.info(MessageEnum.BPMN_GENERAL_INFO, "BPMN",