Martin Mucha has uploaded a new change for review.

Change subject: core: removed pointless caching.
......................................................................

core: removed pointless caching.

ResourceBundle is already cached. See
java.util.ResourceBundle#clearCache()
Each HashMap caching is wrong and should not exist in code.

Change-Id: I7eb5e71aafb8d8fde253d8713fe6cb7f870d3093
Signed-off-by: Martin Mucha <[email protected]>
---
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirectorTest.java
2 files changed, 18 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/86/29586/1

diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
index f27fd87..2e04c8a 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java
@@ -1,6 +1,5 @@
 package org.ovirt.engine.core.dal.dbbroker.auditloghandling;
 
-import java.util.EnumMap;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -24,36 +23,32 @@
 
 public final class AuditLogDirector {
     private static final Log log = LogFactory.getLog(AuditLogDirector.class);
-    private static final Map<AuditLogType, String> messages = new 
EnumMap<AuditLogType, String>(AuditLogType.class);
     private static final Pattern pattern = Pattern.compile("\\$\\{\\w*\\}"); 
// match ${<alphanumeric>...}
     static final String UNKNOWN_VARIABLE_VALUE = "Non interactive user";
     static final String UNKNOWN_REASON_VALUE = "Not Specified";
     static final String REASON_TOKEN = "reason";
-    static final String APP_ERRORS_MESSAGES_FILE_NAME = 
"bundles/AuditLogMessages";
+    private static final ResourceBundle resourceBundle = getResourceBundle();
 
-    static {
-        initMessages();
-    }
-
-    private static void initMessages() {
-        ResourceBundle bundle = readMessagesFromBundle();
-
-        for (AuditLogType auditLogType : AuditLogType.values()) {
-            messages.put(auditLogType, bundle.getString(auditLogType.name()));
-        }
-    }
-
-    static ResourceBundle readMessagesFromBundle() {
+    static ResourceBundle getResourceBundle() {
         try {
-            return ResourceBundle.getBundle(APP_ERRORS_MESSAGES_FILE_NAME);
+            return ResourceBundle.getBundle(getResourceBundleName());
         } catch (MissingResourceException e) {
-            throw new RuntimeException("Could not load audit log messages from 
the file " +
-                    APP_ERRORS_MESSAGES_FILE_NAME);
+            throw new RuntimeException("Could not find ResourceBundle file '" 
+ getResourceBundleName() +"'.");
         }
+    }
+
+    private static String getResourceBundleName() {
+        return "bundles/AuditLogMessages";
     }
 
     public static String getMessage(AuditLogType logType) {
-        return messages.get(logType);
+        final String key = logType.name();
+        try {
+            return resourceBundle.getString(key);
+        } catch (Exception e) {
+            log.error("Key '" + key + "' is not translated in 
'"+getResourceBundleName()+"'");
+            return logType.name();
+        }
     }
 
     public static void log(AuditLogableBase auditLogable) {
@@ -158,7 +153,7 @@
                     auditLogable.getCustomData());
         }
 
-        final String messageByType = messages.get(logType);
+        final String messageByType = getMessage(logType);
         if (messageByType == null) {
             return null;
         } else {
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirectorTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirectorTest.java
index 884d873..e398a34 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirectorTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirectorTest.java
@@ -138,8 +138,8 @@
 
     @Test
     public void testAllAuditLogTypesHaveTranslationInBundle() {
-        final ResourceBundle resourceBundle = 
AuditLogDirector.readMessagesFromBundle();
-        final String bundleName = 
AuditLogDirector.APP_ERRORS_MESSAGES_FILE_NAME;
+        final ResourceBundle resourceBundle = 
AuditLogDirector.getResourceBundle();
+        final String bundleName = "bundles/AuditLogMessages";
 
         for (AuditLogType auditLogType : AuditLogType.values()) {
             final String key = auditLogType.name();


-- 
To view, visit http://gerrit.ovirt.org/29586
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7eb5e71aafb8d8fde253d8713fe6cb7f870d3093
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Martin Mucha <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to