Merge "Bug 1386: Avoid commit deadlock"
[controller.git] / opendaylight / md-sal / sal-protocolbuffer-encoding / 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 org.opendaylight.yangtools.yang.common.QName;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 public class QNameFactory {
19     private static final Map<String, QName> cache = new HashMap<>();
20
21     public static QName create(String name){
22         QName value = cache.get(name);
23         if(value == null){
24             synchronized (cache){
25                 value = cache.get(name);
26                 if(value == null) {
27                     value = QName.create(name);
28                     cache.put(name, value);
29                 }
30             }
31         }
32         return value;
33     }
34 }