5c7f6d1a5650333ca1cee7124ff0edd47a8c0378
[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
9 package org.opendaylight.controller.cluster.datastore.node.utils;
10
11 import com.google.common.cache.CacheBuilder;
12 import com.google.common.cache.CacheLoader;
13 import com.google.common.cache.LoadingCache;
14 import org.opendaylight.yangtools.yang.common.QName;
15
16 public final class QNameFactory {
17
18     private static final int MAX_QNAME_CACHE_SIZE = 10000;
19
20     private QNameFactory() {
21     }
22
23     private static final LoadingCache<String, QName> CACHE = CacheBuilder.newBuilder().maximumSize(MAX_QNAME_CACHE_SIZE)
24             .softValues().build(new CacheLoader<String, QName>() {
25                 @Override
26                 public QName load(String key) {
27                     return QName.create(key);
28                 }
29             });
30
31     public static QName create(String name) {
32         return CACHE.getUnchecked(name);
33     }
34 }