Update QNameFactory caching
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / QNameFactory.java
index c63266ff08e218fc6180fdf1cae61e990677eace..1b9a21f85e1b1ba24014a51ed09c4e21492f36d2 100644 (file)
@@ -1,13 +1,10 @@
 /*
+ * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
- *  Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
- *
- *  This program and the accompanying materials are made available under the
- *  terms of the Eclipse Public License v1.0 which accompanies this distribution,
- *  and is available at http://www.eclipse.org/legal/epl-v10.html
- *
+ * This program and the accompanying materials are made available under the
+ * 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;
@@ -15,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 {
+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 int MAX_QNAME_CACHE_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);
     }
 }