X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fnode%2Futils%2FQNameFactory.java;h=1b9a21f85e1b1ba24014a51ed09c4e21492f36d2;hp=002b9ff82e53eea0b62fd98d97756926a2e21bea;hb=dc54b87a6b2fb11d233b8294b684268f4d5161de;hpb=8e42b08cb626a60919c145b2a46d94114c3905d6 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 002b9ff82e..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 @@ -1,34 +1,34 @@ /* + * 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; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import org.opendaylight.yangtools.yang.common.QName; -import java.util.HashMap; -import java.util.Map; - -public class QNameFactory { - private static final Map cache = new HashMap<>(); +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); - public static QName create(String name){ - QName value = cache.get(name); - if(value == null){ - synchronized (cache){ - value = cache.get(name); - if(value == null) { - value = QName.create(name); - cache.put(name, value); + private static final LoadingCache CACHE = CacheBuilder.newBuilder().maximumSize(MAX_QNAME_CACHE_SIZE) + .weakValues().build(new CacheLoader() { + @Override + public QName load(final String key) { + return QName.create(key).intern(); } - } - } - return value; + }); + + private QNameFactory() { + + } + + public static QName create(final String name) { + return CACHE.getUnchecked(name); } }