Move Lithium tokens to their own class 59/84559/3
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 20 Sep 2019 17:36:10 +0000 (19:36 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 23 Sep 2019 08:45:32 +0000 (10:45 +0200)
TokenTypes assumes singularity, which can create confusion, as we
have multiple multiple distinct sets. This separates out
Lithium-specific tokens into their own class.

JIRA: CONTROLLER-1919
Change-Id: Id8c47be7c432b44980dbeac8ef41d430c64e5490
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataInput.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataOutput.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/LithiumTokens.java [new file with mode: 0644]
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/TokenTypes.java

index 16bc11237ea1a6cb664ab3e2e886c4edf37bf111..bab9143baebb73fced5888a5afffe7f83dbaafaa 100644 (file)
@@ -278,16 +278,16 @@ abstract class AbstractLithiumDataInput extends AbstractNormalizedNodeDataInput
     final String readCodedString() throws IOException {
         final byte valueType = input.readByte();
         switch (valueType) {
-            case TokenTypes.IS_NULL_VALUE:
+            case LithiumTokens.IS_NULL_VALUE:
                 return null;
-            case TokenTypes.IS_CODE_VALUE:
+            case LithiumTokens.IS_CODE_VALUE:
                 final int code = input.readInt();
                 try {
                     return codedStringMap.get(code);
                 } catch (IndexOutOfBoundsException e) {
                     throw new IOException("String code " + code + " was not found", e);
                 }
-            case TokenTypes.IS_STRING_VALUE:
+            case LithiumTokens.IS_STRING_VALUE:
                 final String value = input.readUTF().intern();
                 codedStringMap.add(value);
                 return value;
index 3a3015bb1af210896df9fc965664b3bad0b3c1bf..f839bb1ff23425f5d15d5c1044af574506d70c8e 100644 (file)
@@ -279,7 +279,7 @@ abstract class AbstractLithiumDataOutput extends AbstractNormalizedNodeDataOutpu
         if (revision.isPresent()) {
             writeString(revision.get().toString());
         } else {
-            writeByte(TokenTypes.IS_NULL_VALUE);
+            writeByte(LithiumTokens.IS_NULL_VALUE);
         }
     }
 
@@ -369,10 +369,10 @@ abstract class AbstractLithiumDataOutput extends AbstractNormalizedNodeDataOutpu
         final Integer value = stringCodeMap.get(verifyNotNull(string));
         if (value == null) {
             stringCodeMap.put(string, stringCodeMap.size());
-            writeByte(TokenTypes.IS_STRING_VALUE);
+            writeByte(LithiumTokens.IS_STRING_VALUE);
             writeUTF(string);
         } else {
-            writeByte(TokenTypes.IS_CODE_VALUE);
+            writeByte(LithiumTokens.IS_CODE_VALUE);
             writeInt(value);
         }
     }
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/LithiumTokens.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/LithiumTokens.java
new file mode 100644 (file)
index 0000000..27241e9
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.datastore.node.utils.stream;
+
+/**
+ * Tokens related to Lithium/NeonSR2 encoding.
+ */
+final class LithiumTokens {
+    /**
+     * The value is a reference to a previously-defined entity, typically through {@link #IS_STRING_VALUE}.
+     */
+    static final byte IS_CODE_VALUE = 1;
+    /**
+     * The value is a String, which needs to be kept memoized for the purposes for being referenced by
+     * {@link #IS_CODE_VALUE}.
+     */
+    static final byte IS_STRING_VALUE = 2;
+    /**
+     * The value is an explicit null.
+     */
+    static final byte IS_NULL_VALUE = 3;
+
+    private LithiumTokens() {
+
+    }
+}
index 66405b1340020dc1774abf47909f4d3695b17208..8fc7d6d55bbcf6feb9343cd83301a34fc097ebba 100644 (file)
@@ -24,11 +24,6 @@ final class TokenTypes {
      */
     static final short NEON_SR2_VERSION = 2;
 
-    // Tokens supported in LITHIUM_VERSION
-    static final byte IS_CODE_VALUE = 1;
-    static final byte IS_STRING_VALUE = 2;
-    static final byte IS_NULL_VALUE = 3;
-
     // Tokens supported in NEON_SR2_VERSION
     static final byte IS_QNAME_CODE = 4;
     static final byte IS_QNAME_VALUE = 5;