Remove the use of ObjectCache 95/30895/2
authorRobert Varga <rovarga@cisco.com>
Mon, 7 Dec 2015 09:24:40 +0000 (10:24 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 7 Dec 2015 12:43:12 +0000 (12:43 +0000)
Short-circuit to the internal interner to keep the caching instances
unified.

Change-Id: I1cac0ba24dab64dd750b1471fc8edbfce4470b93
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QName.java
yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QNameModule.java

index ed05140174f03cbf3932a1f6bd0c0ed4dfb19bdc..f94e95c87c7744dd187522443b342cb595a8afcd 100644 (file)
@@ -20,8 +20,6 @@ import java.util.Objects;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.objcache.ObjectCache;
-import org.opendaylight.yangtools.objcache.ObjectCacheFactory;
 
 /**
  * The QName from XML consists of local name of element and XML namespace, but
@@ -49,7 +47,6 @@ import org.opendaylight.yangtools.objcache.ObjectCacheFactory;
  */
 public final class QName implements Immutable, Serializable, Comparable<QName> {
     private static final Interner<QName> INTERNER = Interners.newWeakInterner();
-    private static final ObjectCache CACHE = ObjectCacheFactory.getObjectCache(QName.class);
     private static final long serialVersionUID = 5398411242927766414L;
 
     static final String QNAME_REVISION_DELIMITER = "?revision=";
@@ -76,27 +73,13 @@ public final class QName implements Immutable, Serializable, Comparable<QName> {
      * Look up specified QName in the global cache and return a shared reference.
      *
      * @param qname QName instance
-     * @return Cached instance, according to {@link ObjectCache} policy.
+     * @return Cached instance, according to {@link org.opendaylight.yangtools.objcache.ObjectCache} policy.
      *
      * @deprecated Use {@link #intern()} instead.
      */
     @Deprecated
     public static QName cachedReference(final QName qname) {
-        // We also want to make sure we keep the QNameModule cached
-        final QNameModule myMod = qname.getModule();
-        final QNameModule cacheMod = QNameModule.cachedReference(myMod);
-
-        final QName what;
-        // Identity comparison is here on purpose, as we are deciding whether to potentially store 'qname'
-        // into cache. It is important that it does not hold user-supplied reference (such a String instance from
-        // XML parser.
-        if (cacheMod == myMod) {
-            what = qname;
-        } else {
-            what = QName.create(cacheMod, qname.localName);
-        }
-
-        return CACHE.getReference(what);
+        return qname.intern();
     }
 
     /**
index 32cf9c0cd557b5168cb1da7dd38a25ea04554e01..0c786146e67c627fece599041af4545e444fd546 100644 (file)
@@ -16,14 +16,11 @@ import java.net.URISyntaxException;
 import java.util.Date;
 import java.util.Objects;
 import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.objcache.ObjectCache;
-import org.opendaylight.yangtools.objcache.ObjectCacheFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public final class QNameModule implements Immutable, Serializable {
     private static final Interner<QNameModule> INTERNER = Interners.newWeakInterner();
-    private static final ObjectCache CACHE = ObjectCacheFactory.getObjectCache(QNameModule.class);
     private static final Logger LOG = LoggerFactory.getLogger(QNameModule.class);
     private static final QNameModule NULL_INSTANCE = new QNameModule(null, null);
     private static final long serialVersionUID = 1L;
@@ -46,13 +43,13 @@ public final class QNameModule implements Immutable, Serializable {
      * Look up specified module in the global cache and return a shared reference.
      *
      * @param module Module instance
-     * @return Cached instance, according to {@link ObjectCache} policy.
+     * @return Cached instance, according to {@link org.opendaylight.yangtools.objcache.ObjectCache} policy.
      *
      * @deprecated Use {@link #intern()} instead.
      */
     @Deprecated
     public static QNameModule cachedReference(final QNameModule module) {
-        return CACHE.getReference(module);
+        return module.intern();
     }
 
     /**