From: Robert Varga Date: Tue, 28 May 2019 10:42:02 +0000 (+0200) Subject: Update QNameFactory caching X-Git-Tag: release/sodium~75 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=dc54b87a6b2fb11d233b8294b684268f4d5161de Update QNameFactory caching This eliminates the use of soft references in favor of weak ones, so that we do not rely on GC heuristics for retention. We also make the maximum cache size runtime-configurable via org.opendaylight.controller.cluster.datastore.node.utils.qname-cache.max-size property. Finally we use QName.intern() to defer to the global QName cache, resulting in better QName instance sharing. JIRA: CONTROLLER-1897 Change-Id: Ice3596d23b96c4ecfc5775cb21968233b042a984 Signed-off-by: Robert Varga --- diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/QNameFactory.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/QNameFactory.java index 5c7f6d1a56..1b9a21f85e 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/QNameFactory.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/QNameFactory.java @@ -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; @@ -14,21 +13,22 @@ import com.google.common.cache.LoadingCache; import org.opendaylight.yangtools.yang.common.QName; public final class QNameFactory { - - private static final int MAX_QNAME_CACHE_SIZE = 10000; - - private 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 CACHE = CacheBuilder.newBuilder().maximumSize(MAX_QNAME_CACHE_SIZE) - .softValues().build(new CacheLoader() { + .weakValues().build(new CacheLoader() { @Override - public QName load(String key) { - return QName.create(key); + public QName load(final String key) { + return QName.create(key).intern(); } }); - public static QName create(String name) { + private QNameFactory() { + + } + + public static QName create(final String name) { return CACHE.getUnchecked(name); } }