1b9a21f85e1b1ba24014a51ed09c4e21492f36d2
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / QNameFactory.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.datastore.node.utils;
9
10 import com.google.common.cache.CacheBuilder;
11 import com.google.common.cache.CacheLoader;
12 import com.google.common.cache.LoadingCache;
13 import org.opendaylight.yangtools.yang.common.QName;
14
15 public final class QNameFactory {
16     private static final int MAX_QNAME_CACHE_SIZE = Integer.getInteger(
17         "org.opendaylight.controller.cluster.datastore.node.utils.qname-cache.max-size", 10000);
18
19     private static final LoadingCache<String, QName> CACHE = CacheBuilder.newBuilder().maximumSize(MAX_QNAME_CACHE_SIZE)
20             .weakValues().build(new CacheLoader<String, QName>() {
21                 @Override
22                 public QName load(final String key) {
23                     return QName.create(key).intern();
24                 }
25             });
26
27     private QNameFactory() {
28
29     }
30
31     public static QName create(final String name) {
32         return CACHE.getUnchecked(name);
33     }
34 }