Update QNameFactory caching
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / QNameFactory.java
index 7d5379dfe0ce87d2fbd70e6b38a3fd7d432bdba6..1b9a21f85e1b1ba24014a51ed09c4e21492f36d2 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.controller.cluster.datastore.node.utils;
 
 import com.google.common.cache.CacheBuilder;
@@ -13,24 +12,23 @@ import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
 import org.opendaylight.yangtools.yang.common.QName;
 
-public class QNameFactory {
-
-    private static final int MAX_QNAME_CACHE_SIZE = 10000;
+public final class QNameFactory {
+    private static final int MAX_QNAME_CACHE_SIZE = Integer.getInteger(
+        "org.opendaylight.controller.cluster.datastore.node.utils.qname-cache.max-size", 10000);
 
-    private static final LoadingCache<String, QName> CACHE = CacheBuilder.newBuilder()
-        .maximumSize(MAX_QNAME_CACHE_SIZE)
-        .softValues()
-        .build(
-            new CacheLoader<String, QName>() {
+    private static final LoadingCache<String, QName> CACHE = CacheBuilder.newBuilder().maximumSize(MAX_QNAME_CACHE_SIZE)
+            .weakValues().build(new CacheLoader<String, QName>() {
                 @Override
-                public QName load(String key) {
-                    return QName.create(key);
+                public QName load(final String key) {
+                    return QName.create(key).intern();
                 }
-            }
-        );
+            });
 
+    private QNameFactory() {
+
+    }
 
-    public static QName create(String name) {
+    public static QName create(final String name) {
         return CACHE.getUnchecked(name);
     }
 }