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