From cfa32c0058c51a993e5b3e390acf49d7aaeac433 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 20 Sep 2019 19:36:10 +0200 Subject: [PATCH] Move Lithium tokens to their own class 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 --- .../stream/AbstractLithiumDataInput.java | 6 ++-- .../stream/AbstractLithiumDataOutput.java | 6 ++-- .../node/utils/stream/LithiumTokens.java | 31 +++++++++++++++++++ .../node/utils/stream/TokenTypes.java | 5 --- 4 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/LithiumTokens.java diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataInput.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataInput.java index 16bc11237e..bab9143bae 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataInput.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataInput.java @@ -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; diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataOutput.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataOutput.java index 3a3015bb1a..f839bb1ff2 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataOutput.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractLithiumDataOutput.java @@ -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 index 0000000000..27241e99e0 --- /dev/null +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/LithiumTokens.java @@ -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() { + + } +} diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/TokenTypes.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/TokenTypes.java index 66405b1340..8fc7d6d55b 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/TokenTypes.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/TokenTypes.java @@ -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; -- 2.36.6