From d92bd0e575983b3d6a09a73089ef8f9c62f94eaa Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 27 Nov 2022 13:59:16 +0100 Subject: [PATCH] Add new cds-access-api proxies Externalizable serialization format record class hierarchy, which leads to significant overheads. This patch introduces proxies which are are flat, i.e. have java.Object as their superclass, eliminating this overhead. The way we do this is we defined SerialForm interfaces which extend Externalizable and define the serialization protocol in terms of default methods. We then define a bunch of classes which are pure data holders implementing individual SerialForms. Also ensure messages properly implement cloneAsVersion() to propagate the target version, now that it matters for them. Finally audit use of java.io.Serial so that we do not import it -- it is just pure overhead vs. using @java.io.Serial directly. JIRA: CONTROLLER-2051 Change-Id: I01132665027687edc1c6d44dda8a6ab0cab6ad6a Signed-off-by: Robert Varga --- .../controller/cluster/access/ABIVersion.java | 11 +++ .../access/AbstractVersionException.java | 3 +- .../access/FutureVersionException.java | 6 +- .../cluster/access/PastVersionException.java | 6 +- .../AbortLocalTransactionRequest.java | 3 +- .../AbstractLocalHistoryRequestProxy.java | 12 +-- .../AbstractLocalTransactionRequest.java | 5 +- .../AbstractReadPathTransactionRequest.java | 31 ++++++- ...ractReadPathTransactionRequestProxyV1.java | 43 +--------- .../AbstractReadTransactionRequest.java | 26 +++++- ...AbstractReadTransactionRequestProxyV1.java | 34 +------- .../AbstractTransactionRequestProxy.java | 12 +-- .../AbstractTransactionSuccessProxy.java | 12 +-- .../cluster/access/commands/CCF.java | 45 ++++++++++ .../cluster/access/commands/CCR.java | 45 ++++++++++ .../cluster/access/commands/CCS.java | 45 ++++++++++ .../cluster/access/commands/CHR.java | 46 +++++++++++ .../commands/ClosedTransactionException.java | 3 +- .../CommitLocalTransactionRequest.java | 3 +- .../access/commands/ConnectClientFailure.java | 24 ++++-- .../commands/ConnectClientFailureProxyV1.java | 20 +---- .../access/commands/ConnectClientRequest.java | 34 ++++++-- .../commands/ConnectClientRequestProxyV1.java | 42 +--------- .../access/commands/ConnectClientSuccess.java | 60 ++++++++++++-- .../commands/ConnectClientSuccessProxyV1.java | 61 +------------- .../commands/CreateLocalHistoryRequest.java | 17 ++-- .../CreateLocalHistoryRequestProxyV1.java | 15 +--- .../cluster/access/commands/DHR.java | 46 +++++++++++ .../access/commands/DeadHistoryException.java | 3 +- .../commands/DeadTransactionException.java | 3 +- .../commands/DestroyLocalHistoryRequest.java | 17 ++-- .../DestroyLocalHistoryRequestProxyV1.java | 15 +--- .../cluster/access/commands/ETR.java | 46 +++++++++++ .../cluster/access/commands/ETS.java | 46 +++++++++++ .../commands/ExistsTransactionRequest.java | 20 +++-- .../ExistsTransactionRequestProxyV1.java | 17 +--- .../commands/ExistsTransactionSuccess.java | 30 +++++-- .../ExistsTransactionSuccessProxyV1.java | 31 +------ .../cluster/access/commands/HF.java | 45 ++++++++++ .../cluster/access/commands/HS.java | 45 ++++++++++ .../cluster/access/commands/ITSR.java | 46 +++++++++++ .../cluster/access/commands/ITSS.java | 46 +++++++++++ .../IncrementTransactionSequenceRequest.java | 43 ++++++++-- ...mentTransactionSequenceRequestProxyV1.java | 34 +------- .../IncrementTransactionSequenceSuccess.java | 23 ++++-- ...mentTransactionSequenceSuccessProxyV1.java | 14 +--- .../access/commands/LocalHistoryFailure.java | 30 +++++-- .../commands/LocalHistoryFailureProxyV1.java | 22 +---- .../access/commands/LocalHistoryRequest.java | 14 +++- .../access/commands/LocalHistorySuccess.java | 31 +++++-- .../commands/LocalHistorySuccessProxyV1.java | 18 +--- .../cluster/access/commands/MTR.java | 46 +++++++++++ .../cluster/access/commands/MTS.java | 46 +++++++++++ .../commands/ModifyTransactionRequest.java | 63 ++++++++++++-- .../ModifyTransactionRequestProxyV1.java | 70 +--------------- .../commands/ModifyTransactionSuccess.java | 17 +++- .../ModifyTransactionSuccessProxyV1.java | 13 +-- .../access/commands/NotLeaderException.java | 3 +- .../commands/OutOfOrderRequestException.java | 3 +- .../OutOfSequenceEnvelopeException.java | 3 +- .../cluster/access/commands/PHR.java | 46 +++++++++++ .../commands/PurgeLocalHistoryRequest.java | 16 +++- .../PurgeLocalHistoryRequestProxyV1.java | 15 +--- .../cluster/access/commands/RTR.java | 46 +++++++++++ .../cluster/access/commands/RTS.java | 46 +++++++++++ .../commands/ReadTransactionRequest.java | 18 +++- .../ReadTransactionRequestProxyV1.java | 16 +--- .../commands/ReadTransactionSuccess.java | 47 +++++++++-- .../ReadTransactionSuccessProxyV1.java | 51 +----------- .../cluster/access/commands/STR.java | 46 +++++++++++ .../cluster/access/commands/STS.java | 46 +++++++++++ .../commands/SkipTransactionsRequest.java | 61 ++++++++++++-- .../commands/SkipTransactionsRequestV1.java | 65 +-------------- .../commands/SkipTransactionsResponse.java | 24 ++++-- .../SkipTransactionsResponseProxyV1.java | 13 +-- .../cluster/access/commands/TAR.java | 46 +++++++++++ .../cluster/access/commands/TAS.java | 46 +++++++++++ .../cluster/access/commands/TCCS.java | 46 +++++++++++ .../cluster/access/commands/TCS.java | 46 +++++++++++ .../cluster/access/commands/TDCR.java | 46 +++++++++++ .../cluster/access/commands/TF.java | 45 ++++++++++ .../cluster/access/commands/TPCR.java | 46 +++++++++++ .../cluster/access/commands/TPCS.java | 46 +++++++++++ .../cluster/access/commands/TPR.java | 46 +++++++++++ .../cluster/access/commands/TPS.java | 46 +++++++++++ .../commands/TransactionAbortRequest.java | 22 +++-- .../TransactionAbortRequestProxyV1.java | 15 +--- .../commands/TransactionAbortSuccess.java | 22 +++-- .../TransactionAbortSuccessProxyV1.java | 13 +-- .../commands/TransactionCanCommitSuccess.java | 23 ++++-- .../TransactionCanCommitSuccessProxyV1.java | 26 +----- .../commands/TransactionCommitSuccess.java | 22 +++-- .../TransactionCommitSuccessProxyV1.java | 13 +-- .../commands/TransactionDoCommitRequest.java | 22 +++-- .../TransactionDoCommitRequestProxyV1.java | 15 +--- .../access/commands/TransactionFailure.java | 28 +++++-- .../commands/TransactionFailureProxyV1.java | 20 +---- .../commands/TransactionPreCommitRequest.java | 22 +++-- .../TransactionPreCommitRequestProxyV1.java | 15 +--- .../commands/TransactionPreCommitSuccess.java | 24 ++++-- .../TransactionPreCommitSuccessProxyV1.java | 13 +-- .../commands/TransactionPurgeRequest.java | 22 +++-- .../TransactionPurgeRequestProxyV1.java | 15 +--- .../commands/TransactionPurgeResponse.java | 26 ++++-- .../TransactionPurgeResponseProxyV1.java | 13 +-- .../access/commands/TransactionRequest.java | 15 +++- .../access/commands/TransactionSuccess.java | 14 +++- .../commands/UnknownHistoryException.java | 3 +- .../concepts/AbstractEnvelopeProxy.java | 47 ++++------- .../access/concepts/AbstractMessageProxy.java | 39 +++------ .../concepts/AbstractRequestFailureProxy.java | 33 +------- .../access/concepts/AbstractRequestProxy.java | 33 +------- .../AbstractResponseEnvelopeProxy.java | 36 +------- .../concepts/AbstractResponseProxy.java | 10 +-- .../access/concepts/AbstractSuccessProxy.java | 10 +-- .../cluster/access/concepts/CI.java | 45 ++++++++++ .../access/concepts/ClientIdentifier.java | 59 ++++++++----- .../cluster/access/concepts/Envelope.java | 49 +++++++++-- .../cluster/access/concepts/FE.java | 45 ++++++++++ .../cluster/access/concepts/FI.java | 45 ++++++++++ .../cluster/access/concepts/FT.java | 45 ++++++++++ .../access/concepts/FailureEnvelope.java | 19 ++++- .../access/concepts/FailureEnvelopeProxy.java | 13 +-- .../access/concepts/FrontendIdentifier.java | 57 ++++++++----- .../cluster/access/concepts/FrontendType.java | 60 +++++++++----- .../cluster/access/concepts/HI.java | 45 ++++++++++ .../concepts/LocalHistoryIdentifier.java | 82 +++++++++++-------- .../cluster/access/concepts/MN.java | 45 ++++++++++ .../cluster/access/concepts/MemberName.java | 58 ++++++++----- .../cluster/access/concepts/Message.java | 54 ++++++++++-- .../cluster/access/concepts/RE.java | 45 ++++++++++ .../cluster/access/concepts/Request.java | 28 ++++++- .../access/concepts/RequestEnvelope.java | 19 ++++- .../access/concepts/RequestEnvelopeProxy.java | 12 +-- .../access/concepts/RequestException.java | 3 +- .../access/concepts/RequestFailure.java | 29 ++++++- .../access/concepts/RequestSuccess.java | 22 +++-- .../cluster/access/concepts/Response.java | 11 +-- .../access/concepts/ResponseEnvelope.java | 32 ++++++-- .../concepts/RetiredGenerationException.java | 4 +- .../concepts/RuntimeRequestException.java | 3 +- .../cluster/access/concepts/SE.java | 53 ++++++++++++ .../access/concepts/SuccessEnvelope.java | 20 ++++- .../access/concepts/SuccessEnvelopeProxy.java | 13 +-- .../cluster/access/concepts/TI.java | 45 ++++++++++ .../concepts/TransactionIdentifier.java | 57 ++++++++----- .../concepts/UnsupportedRequestException.java | 4 +- .../commands/ConnectClientSuccessTest.java | 9 +- .../ExistsTransactionSuccessTest.java | 5 +- .../commands/LocalHistoryFailureTest.java | 8 +- .../ModifyTransactionRequestEmptyTest.java | 6 +- .../ModifyTransactionRequestTest.java | 7 +- .../ReadTransactionSuccessNoDataTest.java | 6 +- .../commands/ReadTransactionSuccessTest.java | 6 +- .../commands/SkipTransactionsRequestTest.java | 5 +- .../SkipTransactionsResponseTest.java | 5 +- .../commands/TransactionAbortRequestTest.java | 5 +- .../commands/TransactionAbortSuccessTest.java | 5 +- .../TransactionCanCommitSuccessTest.java | 7 +- .../TransactionCommitSuccessTest.java | 5 +- .../TransactionDoCommitRequestTest.java | 5 +- .../commands/TransactionFailureTest.java | 8 +- .../TransactionPreCommitRequestTest.java | 5 +- .../TransactionPreCommitSuccessTest.java | 5 +- .../commands/TransactionPurgeRequestTest.java | 5 +- .../TransactionPurgeResponseTest.java | 5 +- .../access/concepts/FailureEnvelopeTest.java | 11 ++- .../client/TransmittingTransmitQueueTest.java | 2 +- 168 files changed, 3170 insertions(+), 1335 deletions(-) create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CCF.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CCR.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CCS.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CHR.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DHR.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ETR.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ETS.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/HF.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/HS.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ITSR.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ITSS.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/MTR.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/MTS.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/PHR.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/RTR.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/RTS.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/STR.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/STS.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TAR.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TAS.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TCCS.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TCS.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TDCR.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TF.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TPCR.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TPCS.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TPR.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TPS.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/CI.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FE.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FI.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FT.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/HI.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/MN.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RE.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/SE.java create mode 100644 opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/TI.java diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/ABIVersion.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/ABIVersion.java index 84eb8f6c97..716083156b 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/ABIVersion.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/ABIVersion.java @@ -136,6 +136,17 @@ public enum ABIVersion implements WritableObject { }; } + /** + * Return {@code true} if this version is earier than some {@code other} version. + * + * @param other Other {@link ABIVersion} + * @return {@code true} if {@code other is later} + * @throws NullPointerException if {@code other} is null + */ + public boolean lt(final @NonNull ABIVersion other) { + return compareTo(other) < 0; + } + @Override public void writeTo(final DataOutput out) throws IOException { out.writeShort(value); diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/AbstractVersionException.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/AbstractVersionException.java index f1c538c718..1555b59501 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/AbstractVersionException.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/AbstractVersionException.java @@ -9,14 +9,13 @@ package org.opendaylight.controller.cluster.access; import static java.util.Objects.requireNonNull; -import java.io.Serial; import org.eclipse.jdt.annotation.NonNull; /** * Abstract base exception used for reporting version mismatches from {@link ABIVersion}. */ public abstract class AbstractVersionException extends Exception { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; private final @NonNull ABIVersion closestVersion; diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/FutureVersionException.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/FutureVersionException.java index 4cd807ee09..f0ceaa4890 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/FutureVersionException.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/FutureVersionException.java @@ -7,17 +7,15 @@ */ package org.opendaylight.controller.cluster.access; -import java.io.Serial; - /** * Exception thrown from {@link ABIVersion#valueOf(short)} when the specified version is too new to be supported * by the codebase. */ public final class FutureVersionException extends AbstractVersionException { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; - FutureVersionException(final short version, ABIVersion closest) { + FutureVersionException(final short version, final ABIVersion closest) { super("Version " + Short.toUnsignedInt(version) + " is too new", version, closest); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/PastVersionException.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/PastVersionException.java index 0b7f134ec9..c333d3495e 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/PastVersionException.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/PastVersionException.java @@ -7,16 +7,12 @@ */ package org.opendaylight.controller.cluster.access; -import java.io.Serial; - /** * Exception thrown from {@link ABIVersion#valueOf(short)} when the specified version is too old and no longer * supported by the codebase. - * - * @author Robert Varga */ public final class PastVersionException extends AbstractVersionException { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; PastVersionException(final short version, final ABIVersion closest) { diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbortLocalTransactionRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbortLocalTransactionRequest.java index 37ddb9e7e7..9e2998c5b2 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbortLocalTransactionRequest.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbortLocalTransactionRequest.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.cluster.access.commands; import akka.actor.ActorRef; -import java.io.Serial; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -18,7 +17,7 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * not important for single transactions, but is critical to ensure transaction ordering within local histories. */ public final class AbortLocalTransactionRequest extends AbstractLocalTransactionRequest { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; public AbortLocalTransactionRequest(final @NonNull TransactionIdentifier identifier, diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractLocalHistoryRequestProxy.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractLocalHistoryRequestProxy.java index cd02a20099..1bd37fb83c 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractLocalHistoryRequestProxy.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractLocalHistoryRequestProxy.java @@ -7,9 +7,6 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.DataInput; -import java.io.IOException; -import java.io.Serial; import org.opendaylight.controller.cluster.access.concepts.AbstractRequestProxy; import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; @@ -21,8 +18,8 @@ import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifie * @param Message type */ abstract class AbstractLocalHistoryRequestProxy> - extends AbstractRequestProxy { - @Serial + extends AbstractRequestProxy implements LocalHistoryRequest.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; protected AbstractLocalHistoryRequestProxy() { @@ -32,9 +29,4 @@ abstract class AbstractLocalHistoryRequestProxy AbstractLocalHistoryRequestProxy(final T request) { super(request); } - - @Override - protected final LocalHistoryIdentifier readTarget(final DataInput in) throws IOException { - return LocalHistoryIdentifier.readFrom(in); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractLocalTransactionRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractLocalTransactionRequest.java index f31e408889..5831e65c11 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractLocalTransactionRequest.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractLocalTransactionRequest.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.cluster.access.commands; import akka.actor.ActorRef; -import java.io.Serial; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.Request; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -23,7 +22,7 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier */ public abstract class AbstractLocalTransactionRequest> extends TransactionRequest { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; AbstractLocalTransactionRequest(final TransactionIdentifier identifier, final long sequence, @@ -32,7 +31,7 @@ public abstract class AbstractLocalTransactionRequest externalizableProxy(final ABIVersion version) { + protected final SerialForm externalizableProxy(final ABIVersion version) { throw new UnsupportedOperationException("Local transaction request " + this + " should never be serialized"); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractReadPathTransactionRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractReadPathTransactionRequest.java index 1cdade9ac0..2b4ee0e7e8 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractReadPathTransactionRequest.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractReadPathTransactionRequest.java @@ -11,11 +11,14 @@ import static java.util.Objects.requireNonNull; import akka.actor.ActorRef; import com.google.common.base.MoreObjects.ToStringHelper; -import java.io.Serial; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput; /** * Abstract base class for {@link TransactionRequest}s accessing data as visible in the isolated context of a particular @@ -29,7 +32,29 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; */ public abstract class AbstractReadPathTransactionRequest> extends AbstractReadTransactionRequest { - @Serial + interface SerialForm> + extends AbstractReadTransactionRequest.SerialForm { + + @Override + default T readExternal(final ObjectInput in, final TransactionIdentifier target, final long sequence, + final ActorRef replyTo, final boolean snapshotOnly) throws IOException { + return readExternal(in, target, sequence, replyTo, snapshotOnly, + NormalizedNodeDataInput.newDataInput(in).readYangInstanceIdentifier()); + } + + @NonNull T readExternal(@NonNull ObjectInput in, @NonNull TransactionIdentifier target, long sequence, + @NonNull ActorRef replyTo, boolean snapshotOnly, @NonNull YangInstanceIdentifier path) throws IOException; + + @Override + default void writeExternal(final ObjectOutput out, final T msg) throws IOException { + AbstractReadTransactionRequest.SerialForm.super.writeExternal(out, msg); + try (var nnout = msg.getVersion().getStreamVersion().newDataOutput(out)) { + nnout.writeYangInstanceIdentifier(msg.getPath()); + } + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; private final @NonNull YangInstanceIdentifier path; @@ -55,5 +80,5 @@ public abstract class AbstractReadPathTransactionRequest externalizableProxy(ABIVersion version); + protected abstract SerialForm externalizableProxy(ABIVersion version); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractReadPathTransactionRequestProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractReadPathTransactionRequestProxyV1.java index e139920d6f..e5429841f3 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractReadPathTransactionRequestProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractReadPathTransactionRequestProxyV1.java @@ -7,17 +7,6 @@ */ package org.opendaylight.controller.cluster.access.commands; -import akka.actor.ActorRef; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput; -import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataOutput; -import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion; - /** * Abstract base class for serialization proxies associated with {@link AbstractReadTransactionRequest}s. It implements * the initial (Boron) serialization format. @@ -27,43 +16,15 @@ import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVer * @param Message type */ abstract class AbstractReadPathTransactionRequestProxyV1> - extends AbstractReadTransactionRequestProxyV1 { - @Serial + extends AbstractReadTransactionRequestProxyV1 implements AbstractReadPathTransactionRequest.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; - private YangInstanceIdentifier path; - private transient NormalizedNodeStreamVersion streamVersion; - protected AbstractReadPathTransactionRequestProxyV1() { // For Externalizable } AbstractReadPathTransactionRequestProxyV1(final T request) { super(request); - path = request.getPath(); - streamVersion = request.getVersion().getStreamVersion(); } - - @Override - public final void writeExternal(final ObjectOutput out) throws IOException { - super.writeExternal(out); - try (NormalizedNodeDataOutput nnout = streamVersion.newDataOutput(out)) { - nnout.writeYangInstanceIdentifier(path); - } - } - - @Override - public final void readExternal(final ObjectInput in) throws ClassNotFoundException, IOException { - super.readExternal(in); - path = NormalizedNodeDataInput.newDataInput(in).readYangInstanceIdentifier(); - } - - @Override - protected final T createReadRequest(final TransactionIdentifier target, final long sequence, - final ActorRef replyTo, final boolean snapshotOnly) { - return createReadPathRequest(target, sequence, replyTo, path, snapshotOnly); - } - - abstract T createReadPathRequest(TransactionIdentifier target, long sequence, ActorRef replyTo, - YangInstanceIdentifier requestPath, boolean snapshotOnly); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractReadTransactionRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractReadTransactionRequest.java index 4c1d3971f5..23fdd85140 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractReadTransactionRequest.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractReadTransactionRequest.java @@ -9,7 +9,10 @@ package org.opendaylight.controller.cluster.access.commands; import akka.actor.ActorRef; import com.google.common.base.MoreObjects.ToStringHelper; -import java.io.Serial; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -24,7 +27,24 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier */ public abstract class AbstractReadTransactionRequest> extends TransactionRequest { - @Serial + interface SerialForm> extends TransactionRequest.SerialForm { + @Override + default T readExternal(final ObjectInput in, final TransactionIdentifier target, final long sequence, + final ActorRef replyTo) throws IOException { + return readExternal(in, target, sequence, replyTo, in.readBoolean()); + } + + @NonNull T readExternal(@NonNull ObjectInput in, @NonNull TransactionIdentifier target, long sequence, + @NonNull ActorRef replyTo, boolean snapshotOnly) throws IOException; + + @Override + default void writeExternal(final ObjectOutput out, final T msg) throws IOException { + TransactionRequest.SerialForm.super.writeExternal(out, msg); + out.writeBoolean(msg.isSnapshotOnly()); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; private final boolean snapshotOnly; @@ -50,5 +70,5 @@ public abstract class AbstractReadTransactionRequest externalizableProxy(ABIVersion version); + protected abstract SerialForm externalizableProxy(ABIVersion version); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractReadTransactionRequestProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractReadTransactionRequestProxyV1.java index 66bca1d746..e8539ea57b 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractReadTransactionRequestProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractReadTransactionRequestProxyV1.java @@ -7,13 +7,6 @@ */ package org.opendaylight.controller.cluster.access.commands; -import akka.actor.ActorRef; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; - /** * Abstract base class for serialization proxies associated with {@link AbstractReadTransactionRequest}s. It implements * the initial (Boron) serialization format. @@ -23,38 +16,15 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * @param Message type */ abstract class AbstractReadTransactionRequestProxyV1> - extends AbstractTransactionRequestProxy { - @Serial + extends AbstractTransactionRequestProxy implements AbstractReadTransactionRequest.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; - private boolean snapshotOnly; - protected AbstractReadTransactionRequestProxyV1() { // For Externalizable } AbstractReadTransactionRequestProxyV1(final T request) { super(request); - snapshotOnly = request.isSnapshotOnly(); } - - @Override - public void writeExternal(final ObjectOutput out) throws IOException { - super.writeExternal(out); - out.writeBoolean(snapshotOnly); - } - - @Override - public void readExternal(final ObjectInput in) throws ClassNotFoundException, IOException { - super.readExternal(in); - snapshotOnly = in.readBoolean(); - } - - @Override - protected final T createRequest(final TransactionIdentifier target, final long sequence, final ActorRef replyTo) { - return createReadRequest(target, sequence, replyTo, snapshotOnly); - } - - @SuppressWarnings("checkstyle:hiddenField") - abstract T createReadRequest(TransactionIdentifier target, long sequence, ActorRef replyTo, boolean snapshotOnly); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractTransactionRequestProxy.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractTransactionRequestProxy.java index b37227056a..f43a0d2230 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractTransactionRequestProxy.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractTransactionRequestProxy.java @@ -7,9 +7,6 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.DataInput; -import java.io.IOException; -import java.io.Serial; import org.opendaylight.controller.cluster.access.concepts.AbstractRequestProxy; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -21,8 +18,8 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * @param Message type */ abstract class AbstractTransactionRequestProxy> - extends AbstractRequestProxy { - @Serial + extends AbstractRequestProxy implements TransactionRequest.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; AbstractTransactionRequestProxy() { @@ -32,9 +29,4 @@ abstract class AbstractTransactionRequestProxy> AbstractTransactionRequestProxy(final T request) { super(request); } - - @Override - protected final TransactionIdentifier readTarget(final DataInput in) throws IOException { - return TransactionIdentifier.readFrom(in); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractTransactionSuccessProxy.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractTransactionSuccessProxy.java index 187ad71c35..ee44907b22 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractTransactionSuccessProxy.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/AbstractTransactionSuccessProxy.java @@ -7,9 +7,6 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.DataInput; -import java.io.IOException; -import java.io.Serial; import org.opendaylight.controller.cluster.access.concepts.AbstractSuccessProxy; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -21,8 +18,8 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * @param Message type */ abstract class AbstractTransactionSuccessProxy> - extends AbstractSuccessProxy { - @Serial + extends AbstractSuccessProxy implements TransactionSuccess.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; AbstractTransactionSuccessProxy() { @@ -32,9 +29,4 @@ abstract class AbstractTransactionSuccessProxy> AbstractTransactionSuccessProxy(final T request) { super(request); } - - @Override - protected final TransactionIdentifier readTarget(final DataInput in) throws IOException { - return TransactionIdentifier.readFrom(in); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CCF.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CCF.java new file mode 100644 index 0000000000..ea9c37e3fd --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CCF.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link ConnectClientFailure}. It implements the Chlorine SR2 serialization format. + */ +final class CCF implements ConnectClientFailure.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private ConnectClientFailure message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public CCF() { + // for Externalizable + } + + CCF(final ConnectClientFailure request) { + message = requireNonNull(request); + } + + @Override + public ConnectClientFailure message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final ConnectClientFailure message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CCR.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CCR.java new file mode 100644 index 0000000000..ace94d579c --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CCR.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link ConnectClientRequest}. It implements the Chlorine SR2 serialization format. + */ +final class CCR implements ConnectClientRequest.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private ConnectClientRequest message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public CCR() { + // for Externalizable + } + + CCR(final ConnectClientRequest request) { + message = requireNonNull(request); + } + + @Override + public ConnectClientRequest message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final ConnectClientRequest message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CCS.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CCS.java new file mode 100644 index 0000000000..ea425e5d2d --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CCS.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link ConnectClientSuccess}. It implements the Chlorine SR2 serialization format. + */ +final class CCS implements ConnectClientSuccess.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private ConnectClientSuccess message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public CCS() { + // for Externalizable + } + + CCS(final ConnectClientSuccess request) { + message = requireNonNull(request); + } + + @Override + public ConnectClientSuccess message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final ConnectClientSuccess message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CHR.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CHR.java new file mode 100644 index 0000000000..da3fd132d1 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CHR.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link CreateLocalHistoryRequest}. It implements the Chlorine SR2 serialization + * format. + */ +final class CHR implements CreateLocalHistoryRequest.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private CreateLocalHistoryRequest message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public CHR() { + // For Externalizable + } + + CHR(final CreateLocalHistoryRequest message) { + this.message = requireNonNull(message); + } + + @Override + public CreateLocalHistoryRequest message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final CreateLocalHistoryRequest message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ClosedTransactionException.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ClosedTransactionException.java index 10bee071a5..67b1a40408 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ClosedTransactionException.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ClosedTransactionException.java @@ -7,7 +7,6 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; import org.opendaylight.controller.cluster.access.concepts.RequestException; /** @@ -17,7 +16,7 @@ import org.opendaylight.controller.cluster.access.concepts.RequestException; * leader moved before the frontend retried the corresponding request. */ public final class ClosedTransactionException extends RequestException { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; private final boolean successful; diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CommitLocalTransactionRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CommitLocalTransactionRequest.java index c51165fb63..c7502d51d4 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CommitLocalTransactionRequest.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CommitLocalTransactionRequest.java @@ -12,7 +12,6 @@ import static java.util.Objects.requireNonNull; import akka.actor.ActorRef; import com.google.common.base.MoreObjects.ToStringHelper; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.io.Serial; import java.util.Optional; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; @@ -25,7 +24,7 @@ import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification; */ public final class CommitLocalTransactionRequest extends AbstractLocalTransactionRequest { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "This field is not Serializable but this class " diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ConnectClientFailure.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ConnectClientFailure.java index e11798ab80..aa93708cd4 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ConnectClientFailure.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ConnectClientFailure.java @@ -7,9 +7,9 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; +import java.io.DataInput; +import java.io.IOException; import org.opendaylight.controller.cluster.access.ABIVersion; -import org.opendaylight.controller.cluster.access.concepts.AbstractRequestFailureProxy; import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; import org.opendaylight.controller.cluster.access.concepts.RequestException; import org.opendaylight.controller.cluster.access.concepts.RequestFailure; @@ -18,7 +18,20 @@ import org.opendaylight.controller.cluster.access.concepts.RequestFailure; * A {@link RequestFailure} reported when {@link ConnectClientRequest} fails. */ public final class ConnectClientFailure extends RequestFailure { - @Serial + interface SerialForm extends RequestFailure.SerialForm { + @Override + default ClientIdentifier readTarget(final DataInput in) throws IOException { + return ClientIdentifier.readFrom(in); + } + + @Override + default ConnectClientFailure createFailure(final ClientIdentifier target, final long sequence, + final RequestException cause) { + return new ConnectClientFailure(target, sequence, cause); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; ConnectClientFailure(final ClientIdentifier target, final long sequence, final RequestException cause) { @@ -30,9 +43,8 @@ public final class ConnectClientFailure extends RequestFailure externalizableProxy( - final ABIVersion version) { - return new ConnectClientFailureProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new CCF(this) : new ConnectClientFailureProxyV1(this); } @Override diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ConnectClientFailureProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ConnectClientFailureProxyV1.java index 84a10dae16..75f3a5f1fc 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ConnectClientFailureProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ConnectClientFailureProxyV1.java @@ -7,12 +7,8 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.DataInput; -import java.io.IOException; -import java.io.Serial; import org.opendaylight.controller.cluster.access.concepts.AbstractRequestFailureProxy; import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; -import org.opendaylight.controller.cluster.access.concepts.RequestException; /** * Serialization proxy for use with {@link ConnectClientFailure}. This class implements initial (Boron) serialization @@ -20,8 +16,9 @@ import org.opendaylight.controller.cluster.access.concepts.RequestException; * * @author Robert Varga */ -final class ConnectClientFailureProxyV1 extends AbstractRequestFailureProxy { - @Serial +final class ConnectClientFailureProxyV1 extends AbstractRequestFailureProxy + implements ConnectClientFailure.SerialForm { + @java.io.Serial private static final long serialVersionUID = 2688639416324657256L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -34,15 +31,4 @@ final class ConnectClientFailureProxyV1 extends AbstractRequestFailureProxy { - @Serial + interface SerialForm extends Request.SerialForm { + @Override + default ConnectClientRequest readExternal(final ObjectInput in, final ClientIdentifier target, + final long sequence, final ActorRef replyTo) throws IOException { + return new ConnectClientRequest(target, sequence, replyTo, ABIVersion.inexactReadFrom(in), + ABIVersion.inexactReadFrom(in)); + } + + @Override + default ClientIdentifier readTarget(final DataInput in) throws IOException { + return ClientIdentifier.readFrom(in); + } + + @Override + default void writeExternal(final ObjectOutput out, final ConnectClientRequest msg) throws IOException { + Request.SerialForm.super.writeExternal(out, msg); + msg.getMinVersion().writeTo(out); + msg.getMaxVersion().writeTo(out); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; private final ABIVersion minVersion; @@ -66,9 +89,8 @@ public final class ConnectClientRequest extends Request externalizableProxy( - final ABIVersion version) { - return new ConnectClientRequestProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new CCR(this) : new ConnectClientRequestProxyV1(this); } @Override diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ConnectClientRequestProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ConnectClientRequestProxyV1.java index b420125b83..419852328f 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ConnectClientRequestProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ConnectClientRequestProxyV1.java @@ -7,13 +7,6 @@ */ package org.opendaylight.controller.cluster.access.commands; -import akka.actor.ActorRef; -import java.io.DataInput; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.AbstractRequestProxy; import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; @@ -23,13 +16,11 @@ import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; * * @author Robert Varga */ -final class ConnectClientRequestProxyV1 extends AbstractRequestProxy { - @Serial +final class ConnectClientRequestProxyV1 extends AbstractRequestProxy + implements ConnectClientRequest.SerialForm { + @java.io.Serial private static final long serialVersionUID = 8439729661327852159L; - private ABIVersion minVersion; - private ABIVersion maxVersion; - // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to // be able to create instances via reflection. @SuppressWarnings("checkstyle:RedundantModifier") @@ -39,32 +30,5 @@ final class ConnectClientRequestProxyV1 extends AbstractRequestProxy { - @Serial + interface SerialForm extends RequestSuccess.SerialForm { + @Override + default ClientIdentifier readTarget(final DataInput in) throws IOException { + return ClientIdentifier.readFrom(in); + } + + @Override + default ConnectClientSuccess readExternal(final ObjectInput in, final ClientIdentifier target, + final long sequence) throws IOException, ClassNotFoundException { + final var backend = JavaSerializer.currentSystem().value().provider() + .resolveActorRef((String) in.readObject()); + final var maxMessages = in.readInt(); + + final int alternatesSize = in.readInt(); + final var alternates = new ArrayList(alternatesSize); + for (int i = 0; i < alternatesSize; ++i) { + alternates.add(ActorSelection.apply(ActorRef.noSender(), (String)in.readObject())); + } + + return new ConnectClientSuccess(target, sequence, backend, alternates, maxMessages, null); + } + + @Override + default void writeExternal(final ObjectOutput out, final ConnectClientSuccess msg) throws IOException { + out.writeObject(Serialization.serializedActorPath(msg.backend)); + out.writeInt(msg.maxMessages); + + out.writeInt(msg.alternates.size()); + for (ActorSelection b : msg.alternates) { + out.writeObject(b.toSerializationFormat()); + } + + // We are ignoring the DataTree, it is not serializable anyway + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; private final @NonNull ImmutableList alternates; @@ -40,6 +82,14 @@ public final class ConnectClientSuccess extends RequestSuccess alternates, final int maxMessages, final ReadOnlyDataTree dataTree) { super(target, sequence); @@ -78,13 +128,13 @@ public final class ConnectClientSuccess extends RequestSuccess { - @Serial +final class ConnectClientSuccessProxyV1 extends AbstractSuccessProxy + implements ConnectClientSuccess.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; - private List alternates; - private ActorRef backend; - private int maxMessages; - // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to // be able to create instances via reflection. @SuppressWarnings("checkstyle:RedundantModifier") @@ -44,46 +30,5 @@ final class ConnectClientSuccessProxyV1 extends AbstractSuccessProxy(alternatesSize); - for (int i = 0; i < alternatesSize; ++i) { - alternates.add(ActorSelection.apply(ActorRef.noSender(), (String)in.readObject())); - } - } - - @Override - protected ConnectClientSuccess createSuccess(final ClientIdentifier target, final long sequence) { - return new ConnectClientSuccess(target, sequence, backend, alternates, maxMessages, null); - } - - @Override - protected ClientIdentifier readTarget(final DataInput in) throws IOException { - return ClientIdentifier.readFrom(in); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CreateLocalHistoryRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CreateLocalHistoryRequest.java index 4e07b8ff75..2520aeefd4 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CreateLocalHistoryRequest.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CreateLocalHistoryRequest.java @@ -8,7 +8,7 @@ package org.opendaylight.controller.cluster.access.commands; import akka.actor.ActorRef; -import java.io.Serial; +import java.io.ObjectInput; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; @@ -16,7 +16,15 @@ import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifie * Request to create a new local history. */ public final class CreateLocalHistoryRequest extends LocalHistoryRequest { - @Serial + interface SerialForm extends LocalHistoryRequest.SerialForm { + @Override + default CreateLocalHistoryRequest readExternal(final ObjectInput in, final LocalHistoryIdentifier target, + final long sequence, final ActorRef replyTo) { + return new CreateLocalHistoryRequest(target, sequence, replyTo); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; public CreateLocalHistoryRequest(final LocalHistoryIdentifier target, final ActorRef replyTo) { @@ -32,9 +40,8 @@ public final class CreateLocalHistoryRequest extends LocalHistoryRequest externalizableProxy( - final ABIVersion version) { - return new CreateLocalHistoryRequestProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new CHR(this) : new CreateLocalHistoryRequestProxyV1(this); } @Override diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CreateLocalHistoryRequestProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CreateLocalHistoryRequestProxyV1.java index ff3d09844e..f5581e1414 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CreateLocalHistoryRequestProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/CreateLocalHistoryRequestProxyV1.java @@ -7,18 +7,15 @@ */ package org.opendaylight.controller.cluster.access.commands; -import akka.actor.ActorRef; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; - /** * Externalizable proxy for use with {@link CreateLocalHistoryRequest}. It implements the initial (Boron) serialization * format. * * @author Robert Varga */ -final class CreateLocalHistoryRequestProxyV1 extends AbstractLocalHistoryRequestProxy { - @Serial +final class CreateLocalHistoryRequestProxyV1 extends AbstractLocalHistoryRequestProxy + implements CreateLocalHistoryRequest.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -31,10 +28,4 @@ final class CreateLocalHistoryRequestProxyV1 extends AbstractLocalHistoryRequest CreateLocalHistoryRequestProxyV1(final CreateLocalHistoryRequest request) { super(request); } - - @Override - protected CreateLocalHistoryRequest createRequest(final LocalHistoryIdentifier target, final long sequence, - final ActorRef replyTo) { - return new CreateLocalHistoryRequest(target, sequence, replyTo); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DHR.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DHR.java new file mode 100644 index 0000000000..ebd0f02aaa --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DHR.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link DestroyLocalHistoryRequest}. It implements the Chlorine SR2 serialization + * format. + */ +final class DHR implements DestroyLocalHistoryRequest.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private DestroyLocalHistoryRequest message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public DHR() { + // for Externalizable + } + + DHR(final DestroyLocalHistoryRequest message) { + this.message = requireNonNull(message); + } + + @Override + public DestroyLocalHistoryRequest message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final DestroyLocalHistoryRequest message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DeadHistoryException.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DeadHistoryException.java index 81c8dabf5c..a91eb6971c 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DeadHistoryException.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DeadHistoryException.java @@ -9,7 +9,6 @@ package org.opendaylight.controller.cluster.access.commands; import com.google.common.collect.RangeSet; import com.google.common.primitives.UnsignedLong; -import java.io.Serial; import org.opendaylight.controller.cluster.access.concepts.RequestException; /** @@ -17,7 +16,7 @@ import org.opendaylight.controller.cluster.access.concepts.RequestException; * been retired. */ public final class DeadHistoryException extends RequestException { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; public DeadHistoryException(final RangeSet purgedHistories) { diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DeadTransactionException.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DeadTransactionException.java index dadfb93110..0f259c1a94 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DeadTransactionException.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DeadTransactionException.java @@ -10,7 +10,6 @@ package org.opendaylight.controller.cluster.access.commands; import com.google.common.collect.ImmutableRangeSet; import com.google.common.collect.RangeSet; import com.google.common.primitives.UnsignedLong; -import java.io.Serial; import org.opendaylight.controller.cluster.access.concepts.RequestException; /** @@ -18,7 +17,7 @@ import org.opendaylight.controller.cluster.access.concepts.RequestException; * already been purged. */ public final class DeadTransactionException extends RequestException { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; private final RangeSet purgedIdentifiers; diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DestroyLocalHistoryRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DestroyLocalHistoryRequest.java index 3c9a4b6945..e70bd53654 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DestroyLocalHistoryRequest.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DestroyLocalHistoryRequest.java @@ -8,7 +8,7 @@ package org.opendaylight.controller.cluster.access.commands; import akka.actor.ActorRef; -import java.io.Serial; +import java.io.ObjectInput; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; @@ -16,7 +16,15 @@ import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifie * Request to destroy a local history. */ public final class DestroyLocalHistoryRequest extends LocalHistoryRequest { - @Serial + interface SerialForm extends LocalHistoryRequest.SerialForm { + @Override + default DestroyLocalHistoryRequest readExternal(final ObjectInput in, final LocalHistoryIdentifier target, + final long sequence, final ActorRef replyTo) { + return new DestroyLocalHistoryRequest(target, sequence, replyTo); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; public DestroyLocalHistoryRequest(final LocalHistoryIdentifier target, final long sequence, @@ -29,9 +37,8 @@ public final class DestroyLocalHistoryRequest extends LocalHistoryRequest externalizableProxy( - final ABIVersion version) { - return new DestroyLocalHistoryRequestProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new DHR(this) : new DestroyLocalHistoryRequestProxyV1(this); } @Override diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DestroyLocalHistoryRequestProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DestroyLocalHistoryRequestProxyV1.java index d5eb96e970..ad285ca8ac 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DestroyLocalHistoryRequestProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/DestroyLocalHistoryRequestProxyV1.java @@ -7,18 +7,15 @@ */ package org.opendaylight.controller.cluster.access.commands; -import akka.actor.ActorRef; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; - /** * Externalizable proxy for use with {@link DestroyLocalHistoryRequest}. It implements the initial (Boron) serialization * format. * * @author Robert Varga */ -final class DestroyLocalHistoryRequestProxyV1 extends AbstractLocalHistoryRequestProxy { - @Serial +final class DestroyLocalHistoryRequestProxyV1 extends AbstractLocalHistoryRequestProxy + implements DestroyLocalHistoryRequest.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -31,10 +28,4 @@ final class DestroyLocalHistoryRequestProxyV1 extends AbstractLocalHistoryReques DestroyLocalHistoryRequestProxyV1(final DestroyLocalHistoryRequest request) { super(request); } - - @Override - protected DestroyLocalHistoryRequest createRequest(final LocalHistoryIdentifier target, final long sequence, - final ActorRef replyTo) { - return new DestroyLocalHistoryRequest(target, sequence, replyTo); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ETR.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ETR.java new file mode 100644 index 0000000000..26964e474a --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ETR.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link ExistsTransactionRequest}. It implements the Chlorine SR2 serialization + * format. + */ +final class ETR implements ExistsTransactionRequest.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private ExistsTransactionRequest message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public ETR() { + // for Externalizable + } + + ETR(final ExistsTransactionRequest message) { + this.message = requireNonNull(message); + } + + @Override + public ExistsTransactionRequest message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final ExistsTransactionRequest message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ETS.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ETS.java new file mode 100644 index 0000000000..8cfc5e29d8 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ETS.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link ExistsTransactionSuccess}. It implements the Chlorine SR2 serialization + * format. + */ +final class ETS implements ExistsTransactionSuccess.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private ExistsTransactionSuccess message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public ETS() { + // for Externalizable + } + + ETS(final ExistsTransactionSuccess message) { + this.message = requireNonNull(message); + } + + @Override + public ExistsTransactionSuccess message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final ExistsTransactionSuccess message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ExistsTransactionRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ExistsTransactionRequest.java index d5e619c706..1d16186af0 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ExistsTransactionRequest.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ExistsTransactionRequest.java @@ -8,7 +8,8 @@ package org.opendaylight.controller.cluster.access.commands; import akka.actor.ActorRef; -import java.io.Serial; +import java.io.IOException; +import java.io.ObjectInput; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -18,11 +19,20 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; * A transaction request to query if a particular path exists in the current view of a particular transaction. */ public final class ExistsTransactionRequest extends AbstractReadPathTransactionRequest { - @Serial + interface SerialForm extends AbstractReadPathTransactionRequest.SerialForm { + @Override + default ExistsTransactionRequest readExternal(final ObjectInput in, final TransactionIdentifier target, + final long sequence, final ActorRef replyTo, final boolean snapshotOnly, final YangInstanceIdentifier path) + throws IOException { + return new ExistsTransactionRequest(target, sequence, replyTo, path, snapshotOnly); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; public ExistsTransactionRequest(final @NonNull TransactionIdentifier identifier, final long sequence, - final @NonNull ActorRef replyTo, final @NonNull YangInstanceIdentifier path, final boolean snapshotOnly) { + final @NonNull ActorRef replyTo, final @NonNull YangInstanceIdentifier path, final boolean snapshotOnly) { super(identifier, sequence, replyTo, path, snapshotOnly); } @@ -36,7 +46,7 @@ public final class ExistsTransactionRequest extends AbstractReadPathTransactionR } @Override - protected ExistsTransactionRequestProxyV1 externalizableProxy(final ABIVersion version) { - return new ExistsTransactionRequestProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new ETR(this) : new ExistsTransactionRequestProxyV1(this); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ExistsTransactionRequestProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ExistsTransactionRequestProxyV1.java index a899da944c..9e048e27dc 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ExistsTransactionRequestProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ExistsTransactionRequestProxyV1.java @@ -7,20 +7,15 @@ */ package org.opendaylight.controller.cluster.access.commands; -import akka.actor.ActorRef; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; - /** * Externalizable proxy for use with {@link ExistsTransactionRequest}. It implements the initial (Boron) serialization * format. * * @author Robert Varga */ -final class ExistsTransactionRequestProxyV1 extends - AbstractReadPathTransactionRequestProxyV1 { - @Serial +final class ExistsTransactionRequestProxyV1 extends AbstractReadPathTransactionRequestProxyV1 + implements ExistsTransactionRequest.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -33,10 +28,4 @@ final class ExistsTransactionRequestProxyV1 extends ExistsTransactionRequestProxyV1(final ExistsTransactionRequest request) { super(request); } - - @Override - ExistsTransactionRequest createReadPathRequest(final TransactionIdentifier target, final long sequence, - final ActorRef replyTo, final YangInstanceIdentifier path, final boolean snapshotOnly) { - return new ExistsTransactionRequest(target, sequence, replyTo, path, snapshotOnly); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ExistsTransactionSuccess.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ExistsTransactionSuccess.java index 3110002e4f..ca5377051a 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ExistsTransactionSuccess.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ExistsTransactionSuccess.java @@ -8,7 +8,9 @@ package org.opendaylight.controller.cluster.access.commands; import com.google.common.base.MoreObjects.ToStringHelper; -import java.io.Serial; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -17,11 +19,29 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * {@link #getExists()}. */ public final class ExistsTransactionSuccess extends TransactionSuccess { - @Serial + interface SerialForm extends TransactionSuccess.SerialForm { + @Override + default ExistsTransactionSuccess readExternal(final ObjectInput in, final TransactionIdentifier target, + final long sequence) throws IOException { + return new ExistsTransactionSuccess(target, sequence, in.readBoolean()); + } + + @Override + default void writeExternal(final ObjectOutput out, final ExistsTransactionSuccess msg) throws IOException { + out.writeBoolean(msg.getExists()); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; private final boolean exists; + private ExistsTransactionSuccess(final ExistsTransactionSuccess success, final ABIVersion version) { + super(success, version); + exists = success.exists; + } + public ExistsTransactionSuccess(final TransactionIdentifier target, final long sequence, final boolean exists) { super(target, sequence); this.exists = exists; @@ -32,13 +52,13 @@ public final class ExistsTransactionSuccess extends TransactionSuccess { - @Serial +final class ExistsTransactionSuccessProxyV1 extends AbstractTransactionSuccessProxy + implements ExistsTransactionSuccess.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; - private boolean exists; - // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to // be able to create instances via reflection. @SuppressWarnings("checkstyle:RedundantModifier") @@ -34,23 +27,5 @@ final class ExistsTransactionSuccessProxyV1 extends AbstractTransactionSuccessPr ExistsTransactionSuccessProxyV1(final ExistsTransactionSuccess request) { super(request); - exists = request.getExists(); - } - - @Override - public void writeExternal(final ObjectOutput out) throws IOException { - super.writeExternal(out); - out.writeBoolean(exists); - } - - @Override - public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { - super.readExternal(in); - exists = in.readBoolean(); - } - - @Override - protected ExistsTransactionSuccess createSuccess(final TransactionIdentifier target, final long sequence) { - return new ExistsTransactionSuccess(target, sequence, exists); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/HF.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/HF.java new file mode 100644 index 0000000000..68e9b09b48 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/HF.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link LocalHistoryFailure}. It implements the Chlorine SR2 serialization format. + */ +final class HF implements LocalHistoryFailure.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private LocalHistoryFailure message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public HF() { + // for Externalizable + } + + HF(final LocalHistoryFailure message) { + this.message = requireNonNull(message); + } + + @Override + public LocalHistoryFailure message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final LocalHistoryFailure message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/HS.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/HS.java new file mode 100644 index 0000000000..4ab0ff5ce0 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/HS.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link LocalHistorySuccess}. It implements the Chlorine SR2 serialization format. + */ +final class HS implements LocalHistorySuccess.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private LocalHistorySuccess message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public HS() { + // for Externalizable + } + + HS(final LocalHistorySuccess message) { + this.message = requireNonNull(message); + } + + @Override + public LocalHistorySuccess message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final LocalHistorySuccess message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ITSR.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ITSR.java new file mode 100644 index 0000000000..ef76f5ea19 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ITSR.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link IncrementTransactionSequenceRequest}. It implements the Chlorine SR2 + * serialization format. + */ +final class ITSR implements IncrementTransactionSequenceRequest.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private IncrementTransactionSequenceRequest message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public ITSR() { + // for Externalizable + } + + ITSR(final IncrementTransactionSequenceRequest message) { + this.message = requireNonNull(message); + } + + @Override + public IncrementTransactionSequenceRequest message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final IncrementTransactionSequenceRequest message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ITSS.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ITSS.java new file mode 100644 index 0000000000..178992ab81 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ITSS.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link IncrementTransactionSequenceSuccess}. It implements the Chlorine SR2 + * serialization format. + */ +final class ITSS implements IncrementTransactionSequenceSuccess.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private IncrementTransactionSequenceSuccess message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public ITSS() { + // for Externalizable + } + + ITSS(final IncrementTransactionSequenceSuccess message) { + this.message = requireNonNull(message); + } + + @Override + public IncrementTransactionSequenceSuccess message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final IncrementTransactionSequenceSuccess message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/IncrementTransactionSequenceRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/IncrementTransactionSequenceRequest.java index 5e85316c41..55a435beee 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/IncrementTransactionSequenceRequest.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/IncrementTransactionSequenceRequest.java @@ -7,30 +7,55 @@ */ package org.opendaylight.controller.cluster.access.commands; +import static com.google.common.base.Preconditions.checkArgument; + import akka.actor.ActorRef; -import com.google.common.base.Preconditions; -import java.io.Serial; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; +import org.opendaylight.yangtools.concepts.WritableObjects; /** * A blank transaction request. This is used to provide backfill requests in converted retransmit scenarios, such as * when a initial request to a transaction (such as a {@link ReadTransactionRequest}) is satisfied by the backend * before the need to replay the transaction to a different remote backend. - * - * @author Robert Varga */ public final class IncrementTransactionSequenceRequest extends AbstractReadTransactionRequest { - @Serial + interface SerialForm extends AbstractReadTransactionRequest.SerialForm { + @Override + default void writeExternal(final ObjectOutput out, final IncrementTransactionSequenceRequest msg) + throws IOException { + AbstractReadTransactionRequest.SerialForm.super.writeExternal(out, msg); + WritableObjects.writeLong(out, msg.getIncrement()); + } + + @Override + default IncrementTransactionSequenceRequest readExternal(final ObjectInput in, + final TransactionIdentifier target, final long sequence, final ActorRef replyTo, + final boolean snapshotOnly) throws IOException { + return new IncrementTransactionSequenceRequest(target, sequence, replyTo, snapshotOnly, + WritableObjects.readLong(in)); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; private final long increment; + public IncrementTransactionSequenceRequest(final IncrementTransactionSequenceRequest request, + final ABIVersion version) { + super(request, version); + increment = request.increment; + } + public IncrementTransactionSequenceRequest(final TransactionIdentifier identifier, final long sequence, final ActorRef replyTo, final boolean snapshotOnly, final long increment) { super(identifier, sequence, replyTo, snapshotOnly); - Preconditions.checkArgument(increment >= 0); + checkArgument(increment >= 0, "Unexpected increment %s", increment); this.increment = increment; } @@ -44,12 +69,12 @@ public final class IncrementTransactionSequenceRequest extends } @Override - protected IncrementTransactionSequenceRequestProxyV1 externalizableProxy(final ABIVersion version) { - return new IncrementTransactionSequenceRequestProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new ITSR(this) : new IncrementTransactionSequenceRequestProxyV1(this); } @Override protected IncrementTransactionSequenceRequest cloneAsVersion(final ABIVersion targetVersion) { - return this; + return new IncrementTransactionSequenceRequest(this, targetVersion); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/IncrementTransactionSequenceRequestProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/IncrementTransactionSequenceRequestProxyV1.java index c400b3c750..bedae8e5e8 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/IncrementTransactionSequenceRequestProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/IncrementTransactionSequenceRequestProxyV1.java @@ -7,21 +7,12 @@ */ package org.opendaylight.controller.cluster.access.commands; -import akka.actor.ActorRef; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; -import org.opendaylight.yangtools.concepts.WritableObjects; - final class IncrementTransactionSequenceRequestProxyV1 - extends AbstractReadTransactionRequestProxyV1 { - @Serial + extends AbstractReadTransactionRequestProxyV1 + implements IncrementTransactionSequenceRequest.SerialForm { + @java.io.Serial private static final long serialVersionUID = -7345885599575376005L; - private long increment; - // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to // be able to create instances via reflection. @SuppressWarnings("checkstyle:RedundantModifier") @@ -31,24 +22,5 @@ final class IncrementTransactionSequenceRequestProxyV1 IncrementTransactionSequenceRequestProxyV1(final IncrementTransactionSequenceRequest request) { super(request); - increment = request.getIncrement(); - } - - @Override - public void writeExternal(final ObjectOutput out) throws IOException { - super.writeExternal(out); - WritableObjects.writeLong(out, increment); - } - - @Override - public void readExternal(final ObjectInput in) throws ClassNotFoundException, IOException { - super.readExternal(in); - increment = WritableObjects.readLong(in); - } - - @Override - IncrementTransactionSequenceRequest createReadRequest(final TransactionIdentifier target, final long sequence, - final ActorRef replyToActor, final boolean snapshotOnly) { - return new IncrementTransactionSequenceRequest(target, sequence, replyToActor, snapshotOnly, increment); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/IncrementTransactionSequenceSuccess.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/IncrementTransactionSequenceSuccess.java index a147545dd9..e462edc4d8 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/IncrementTransactionSequenceSuccess.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/IncrementTransactionSequenceSuccess.java @@ -7,7 +7,7 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; +import java.io.ObjectInput; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -15,20 +15,33 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * Successful reply to an {@link IncrementTransactionSequenceRequest}. */ public final class IncrementTransactionSequenceSuccess extends TransactionSuccess { - @Serial + interface SerialForm extends TransactionSuccess.SerialForm { + @Override + default IncrementTransactionSequenceSuccess readExternal(final ObjectInput it, + final TransactionIdentifier target, final long sequence) { + return new IncrementTransactionSequenceSuccess(target, sequence); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; + private IncrementTransactionSequenceSuccess(final IncrementTransactionSequenceSuccess success, + final ABIVersion version) { + super(success, version); + } + public IncrementTransactionSequenceSuccess(final TransactionIdentifier target, final long sequence) { super(target, sequence); } @Override - protected IncrementTransactionSequenceSuccessProxyV1 externalizableProxy(final ABIVersion version) { - return new IncrementTransactionSequenceSuccessProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new ITSS(this) : new IncrementTransactionSequenceSuccessProxyV1(this); } @Override protected IncrementTransactionSequenceSuccess cloneAsVersion(final ABIVersion version) { - return this; + return new IncrementTransactionSequenceSuccess(this, version); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/IncrementTransactionSequenceSuccessProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/IncrementTransactionSequenceSuccessProxyV1.java index 58c017bb94..0acb9b4429 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/IncrementTransactionSequenceSuccessProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/IncrementTransactionSequenceSuccessProxyV1.java @@ -7,9 +7,6 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; - /** * Externalizable proxy for use with {@link IncrementTransactionSequenceSuccess}. It implements the initial (Boron) * serialization format. @@ -17,8 +14,9 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * @author Robert Varga */ final class IncrementTransactionSequenceSuccessProxyV1 - extends AbstractTransactionSuccessProxy { - @Serial + extends AbstractTransactionSuccessProxy + implements IncrementTransactionSequenceSuccess.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -31,10 +29,4 @@ final class IncrementTransactionSequenceSuccessProxyV1 IncrementTransactionSequenceSuccessProxyV1(final IncrementTransactionSequenceSuccess request) { super(request); } - - @Override - protected IncrementTransactionSequenceSuccess createSuccess(final TransactionIdentifier target, - final long sequence) { - return new IncrementTransactionSequenceSuccess(target, sequence); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistoryFailure.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistoryFailure.java index 60aba50d36..6f2eda8ba6 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistoryFailure.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistoryFailure.java @@ -7,7 +7,8 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; +import java.io.DataInput; +import java.io.IOException; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; import org.opendaylight.controller.cluster.access.concepts.RequestException; @@ -17,20 +18,37 @@ import org.opendaylight.controller.cluster.access.concepts.RequestFailure; * Generic {@link RequestFailure} involving a {@link LocalHistoryRequest}. */ public final class LocalHistoryFailure extends RequestFailure { - @Serial + interface SerialForm extends RequestFailure.SerialForm { + @Override + default LocalHistoryIdentifier readTarget(final DataInput in) throws IOException { + return LocalHistoryIdentifier.readFrom(in); + } + + @Override + default LocalHistoryFailure createFailure(final LocalHistoryIdentifier target, final long sequence, + final RequestException cause) { + return new LocalHistoryFailure(target, sequence, cause); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; + private LocalHistoryFailure(final LocalHistoryFailure failure, final ABIVersion version) { + super(failure, version); + } + LocalHistoryFailure(final LocalHistoryIdentifier target, final long sequence, final RequestException cause) { super(target, sequence, cause); } @Override - protected LocalHistoryFailure cloneAsVersion(final ABIVersion version) { - return this; + protected LocalHistoryFailure cloneAsVersion(final ABIVersion targetVersion) { + return new LocalHistoryFailure(this, targetVersion); } @Override - protected LocalHistoryFailureProxyV1 externalizableProxy(final ABIVersion version) { - return new LocalHistoryFailureProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new HF(this) : new LocalHistoryFailureProxyV1(this); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistoryFailureProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistoryFailureProxyV1.java index 11ebfa55fb..f044936b7a 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistoryFailureProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistoryFailureProxyV1.java @@ -7,12 +7,8 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.DataInput; -import java.io.IOException; -import java.io.Serial; import org.opendaylight.controller.cluster.access.concepts.AbstractRequestFailureProxy; import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; -import org.opendaylight.controller.cluster.access.concepts.RequestException; /** * Externalizable proxy for use with {@link LocalHistoryFailure}. It implements the initial (Boron) serialization @@ -20,9 +16,10 @@ import org.opendaylight.controller.cluster.access.concepts.RequestException; * * @author Robert Varga */ -final class LocalHistoryFailureProxyV1 extends - AbstractRequestFailureProxy { - @Serial +final class LocalHistoryFailureProxyV1 + extends AbstractRequestFailureProxy + implements LocalHistoryFailure.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -35,15 +32,4 @@ final class LocalHistoryFailureProxyV1 extends LocalHistoryFailureProxyV1(final LocalHistoryFailure failure) { super(failure); } - - @Override - protected LocalHistoryFailure createFailure(final LocalHistoryIdentifier target, final long sequence, - final RequestException cause) { - return new LocalHistoryFailure(target, sequence, cause); - } - - @Override - protected LocalHistoryIdentifier readTarget(final DataInput in) throws IOException { - return LocalHistoryIdentifier.readFrom(in); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistoryRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistoryRequest.java index 0fe4c2d618..c304384fd8 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistoryRequest.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistoryRequest.java @@ -9,7 +9,8 @@ package org.opendaylight.controller.cluster.access.commands; import akka.actor.ActorRef; import com.google.common.base.Preconditions; -import java.io.Serial; +import java.io.DataInput; +import java.io.IOException; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; import org.opendaylight.controller.cluster.access.concepts.Request; @@ -22,7 +23,14 @@ import org.opendaylight.controller.cluster.access.concepts.RequestException; * @param Message type */ public abstract class LocalHistoryRequest> extends Request { - @Serial + interface SerialForm> extends Request.SerialForm { + @Override + default LocalHistoryIdentifier readTarget(final DataInput in) throws IOException { + return LocalHistoryIdentifier.readFrom(in); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; LocalHistoryRequest(final LocalHistoryIdentifier target, final long sequence, final ActorRef replyTo) { @@ -40,5 +48,5 @@ public abstract class LocalHistoryRequest> exte } @Override - protected abstract AbstractLocalHistoryRequestProxy externalizableProxy(ABIVersion version); + protected abstract SerialForm externalizableProxy(ABIVersion version); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistorySuccess.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistorySuccess.java index 99c1de1d61..a36994937b 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistorySuccess.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistorySuccess.java @@ -7,9 +7,10 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; +import java.io.DataInput; +import java.io.IOException; +import java.io.ObjectInput; import org.opendaylight.controller.cluster.access.ABIVersion; -import org.opendaylight.controller.cluster.access.concepts.AbstractSuccessProxy; import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; import org.opendaylight.controller.cluster.access.concepts.RequestSuccess; @@ -17,25 +18,37 @@ import org.opendaylight.controller.cluster.access.concepts.RequestSuccess; * Success class for {@link RequestSuccess}es involving a specific local history. */ public final class LocalHistorySuccess extends RequestSuccess { - @Serial - private static final long serialVersionUID = 1L; + interface SerialForm extends RequestSuccess.SerialForm { + @Override + default LocalHistoryIdentifier readTarget(final DataInput in) throws IOException { + return LocalHistoryIdentifier.readFrom(in); + } - public LocalHistorySuccess(final LocalHistoryIdentifier target, final long sequence) { - super(target, sequence); + @Override + default LocalHistorySuccess readExternal(final ObjectInput it, final LocalHistoryIdentifier target, + final long sequence) { + return new LocalHistorySuccess(target, sequence); + } } + @java.io.Serial + private static final long serialVersionUID = 1L; + private LocalHistorySuccess(final LocalHistorySuccess success, final ABIVersion version) { super(success, version); } + public LocalHistorySuccess(final LocalHistoryIdentifier target, final long sequence) { + super(target, sequence); + } + @Override protected LocalHistorySuccess cloneAsVersion(final ABIVersion version) { return new LocalHistorySuccess(this, version); } @Override - protected AbstractSuccessProxy externalizableProxy( - final ABIVersion version) { - return new LocalHistorySuccessProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new HS(this) : new LocalHistorySuccessProxyV1(this); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistorySuccessProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistorySuccessProxyV1.java index 18ea0bd9de..6f05617613 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistorySuccessProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/LocalHistorySuccessProxyV1.java @@ -7,9 +7,6 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.DataInput; -import java.io.IOException; -import java.io.Serial; import org.opendaylight.controller.cluster.access.concepts.AbstractSuccessProxy; import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; @@ -18,8 +15,9 @@ import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifie * * @author Robert Varga */ -final class LocalHistorySuccessProxyV1 extends AbstractSuccessProxy { - @Serial +final class LocalHistorySuccessProxyV1 extends AbstractSuccessProxy + implements LocalHistorySuccess.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -32,14 +30,4 @@ final class LocalHistorySuccessProxyV1 extends AbstractSuccessProxy implements SliceableMessage { - @Serial + interface SerialForm extends TransactionRequest.SerialForm { + + + @Override + default ModifyTransactionRequest readExternal(final ObjectInput in, final TransactionIdentifier target, + final long sequence, final ActorRef replyTo) throws IOException { + + final var protocol = Optional.ofNullable(PersistenceProtocol.readFrom(in)); + final int size = in.readInt(); + final List modifications; + if (size != 0) { + modifications = new ArrayList<>(size); + final var nnin = NormalizedNodeDataInput.newDataInput(in); + final var writer = ReusableImmutableNormalizedNodeStreamWriter.create(); + for (int i = 0; i < size; ++i) { + modifications.add(TransactionModification.readFrom(nnin, writer)); + } + } else { + modifications = ImmutableList.of(); + } + + return new ModifyTransactionRequest(target, sequence, replyTo, modifications, protocol.orElse(null)); + } + + @Override + default void writeExternal(final ObjectOutput out, final ModifyTransactionRequest msg) throws IOException { + TransactionRequest.SerialForm.super.writeExternal(out, msg); + + out.writeByte(PersistenceProtocol.byteValue(msg.getPersistenceProtocol().orElse(null))); + + final var modifications = msg.getModifications(); + out.writeInt(modifications.size()); + if (!modifications.isEmpty()) { + try (var nnout = msg.getVersion().getStreamVersion().newDataOutput(out)) { + for (var op : modifications) { + op.writeTo(nnout); + } + } + } + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "This field is not Serializable but this class " @@ -33,6 +80,12 @@ public final class ModifyTransactionRequest extends TransactionRequest modifications; private final PersistenceProtocol protocol; + private ModifyTransactionRequest(final ModifyTransactionRequest request, final ABIVersion version) { + super(request, version); + modifications = request.modifications; + protocol = request.protocol; + } + ModifyTransactionRequest(final TransactionIdentifier target, final long sequence, final ActorRef replyTo, final List modifications, final PersistenceProtocol protocol) { super(target, sequence, replyTo); @@ -55,12 +108,12 @@ public final class ModifyTransactionRequest extends TransactionRequest { - @Serial +final class ModifyTransactionRequestProxyV1 extends AbstractTransactionRequestProxy + implements ModifyTransactionRequest.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; - private List modifications; - private Optional protocol; - private transient NormalizedNodeStreamVersion streamVersion; - // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to // be able to create instances via reflection. @SuppressWarnings("checkstyle:RedundantModifier") @@ -47,49 +27,5 @@ final class ModifyTransactionRequestProxyV1 extends AbstractTransactionRequestPr ModifyTransactionRequestProxyV1(final ModifyTransactionRequest request) { super(request); - modifications = requireNonNull(request.getModifications()); - protocol = request.getPersistenceProtocol(); - streamVersion = request.getVersion().getStreamVersion(); - } - - @Override - public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { - super.readExternal(in); - - protocol = Optional.ofNullable(PersistenceProtocol.readFrom(in)); - - final int size = in.readInt(); - if (size != 0) { - modifications = new ArrayList<>(size); - final NormalizedNodeDataInput nnin = NormalizedNodeDataInput.newDataInput(in); - final ReusableImmutableNormalizedNodeStreamWriter writer = - ReusableImmutableNormalizedNodeStreamWriter.create(); - for (int i = 0; i < size; ++i) { - modifications.add(TransactionModification.readFrom(nnin, writer)); - } - } else { - modifications = ImmutableList.of(); - } - } - - @Override - public void writeExternal(final ObjectOutput out) throws IOException { - super.writeExternal(out); - - out.writeByte(PersistenceProtocol.byteValue(protocol.orElse(null))); - out.writeInt(modifications.size()); - if (!modifications.isEmpty()) { - try (NormalizedNodeDataOutput nnout = streamVersion.newDataOutput(out)) { - for (TransactionModification op : modifications) { - op.writeTo(nnout); - } - } - } - } - - @Override - protected ModifyTransactionRequest createRequest(final TransactionIdentifier target, final long sequence, - final ActorRef replyTo) { - return new ModifyTransactionRequest(target, sequence, replyTo, modifications, protocol.orElse(null)); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionSuccess.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionSuccess.java index 42f22439b1..c1620a8666 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionSuccess.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionSuccess.java @@ -7,7 +7,8 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; +import java.io.IOException; +import java.io.ObjectInput; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -15,7 +16,15 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * Response to a {@link ModifyTransactionRequest} which does not have a {@link PersistenceProtocol}. */ public final class ModifyTransactionSuccess extends TransactionSuccess { - @Serial + interface SerialForm extends TransactionSuccess.SerialForm { + @Override + default ModifyTransactionSuccess readExternal(final ObjectInput in, final TransactionIdentifier target, + final long sequence) throws IOException { + return new ModifyTransactionSuccess(target, sequence); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; public ModifyTransactionSuccess(final TransactionIdentifier identifier, final long sequence) { @@ -27,8 +36,8 @@ public final class ModifyTransactionSuccess extends TransactionSuccess externalizableProxy(final ABIVersion version) { - return new ModifyTransactionSuccessProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new MTS(this) : new ModifyTransactionSuccessProxyV1(this); } @Override diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionSuccessProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionSuccessProxyV1.java index 4ead55671c..8738f99747 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionSuccessProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionSuccessProxyV1.java @@ -7,17 +7,15 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; - /** * Externalizable proxy for use with {@link ModifyTransactionSuccess}. It implements the initial (Boron) serialization * format. * * @author Robert Varga */ -final class ModifyTransactionSuccessProxyV1 extends AbstractTransactionSuccessProxy { - @Serial +final class ModifyTransactionSuccessProxyV1 extends AbstractTransactionSuccessProxy + implements ModifyTransactionSuccess.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -30,9 +28,4 @@ final class ModifyTransactionSuccessProxyV1 extends AbstractTransactionSuccessPr ModifyTransactionSuccessProxyV1(final ModifyTransactionSuccess success) { super(success); } - - @Override - protected ModifyTransactionSuccess createSuccess(final TransactionIdentifier target, final long sequence) { - return new ModifyTransactionSuccess(target, sequence); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/NotLeaderException.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/NotLeaderException.java index 881953c01b..c4353c37fd 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/NotLeaderException.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/NotLeaderException.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.cluster.access.commands; import akka.actor.ActorRef; -import java.io.Serial; import org.opendaylight.controller.cluster.access.concepts.RequestException; /** @@ -16,7 +15,7 @@ import org.opendaylight.controller.cluster.access.concepts.RequestException; * means that the backend processing has moved and the frontend needs to run rediscovery and retry the request. */ public final class NotLeaderException extends RequestException { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; public NotLeaderException(final ActorRef me) { diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/OutOfOrderRequestException.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/OutOfOrderRequestException.java index 7ee5a2f306..0c908078eb 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/OutOfOrderRequestException.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/OutOfOrderRequestException.java @@ -7,7 +7,6 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; import org.opendaylight.controller.cluster.access.concepts.RequestException; /** @@ -15,7 +14,7 @@ import org.opendaylight.controller.cluster.access.concepts.RequestException; * next expected sequence for the target. This is a hard error, as it indicates a Request is missing in the stream. */ public final class OutOfOrderRequestException extends RequestException { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; public OutOfOrderRequestException(final long expectedRequest) { diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/OutOfSequenceEnvelopeException.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/OutOfSequenceEnvelopeException.java index 61715bc42a..b39e09a6a4 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/OutOfSequenceEnvelopeException.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/OutOfSequenceEnvelopeException.java @@ -7,7 +7,6 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; import org.opendaylight.controller.cluster.access.concepts.RequestException; /** @@ -16,7 +15,7 @@ import org.opendaylight.controller.cluster.access.concepts.RequestException; * the backend is not the leader and it transitions to being a leader with old stream messages still being present. */ public final class OutOfSequenceEnvelopeException extends RequestException { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; public OutOfSequenceEnvelopeException(final long expectedEnvelope) { diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/PHR.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/PHR.java new file mode 100644 index 0000000000..e2b3959e64 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/PHR.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link PurgeLocalHistoryRequest}. It implements the Chlorine SR2 serialization + * format. + */ +final class PHR implements PurgeLocalHistoryRequest.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private PurgeLocalHistoryRequest message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public PHR() { + // for Externalizable + } + + PHR(final PurgeLocalHistoryRequest message) { + this.message = requireNonNull(message); + } + + @Override + public PurgeLocalHistoryRequest message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final PurgeLocalHistoryRequest message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/PurgeLocalHistoryRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/PurgeLocalHistoryRequest.java index 50f1657026..81c632f715 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/PurgeLocalHistoryRequest.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/PurgeLocalHistoryRequest.java @@ -8,7 +8,7 @@ package org.opendaylight.controller.cluster.access.commands; import akka.actor.ActorRef; -import java.io.Serial; +import java.io.ObjectInput; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; @@ -17,7 +17,15 @@ import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifie * {@link DestroyLocalHistoryRequest} and indicates it has removed all state attached to a particular local history. */ public final class PurgeLocalHistoryRequest extends LocalHistoryRequest { - @Serial + interface SerialForm extends LocalHistoryRequest.SerialForm { + @Override + default PurgeLocalHistoryRequest readExternal(final ObjectInput in, final LocalHistoryIdentifier target, + final long sequence, final ActorRef replyTo) { + return new PurgeLocalHistoryRequest(target, sequence, replyTo); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; public PurgeLocalHistoryRequest(final LocalHistoryIdentifier target, final long sequence, final ActorRef replyTo) { @@ -29,8 +37,8 @@ public final class PurgeLocalHistoryRequest extends LocalHistoryRequest externalizableProxy(final ABIVersion version) { - return new PurgeLocalHistoryRequestProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new PHR(this) : new PurgeLocalHistoryRequestProxyV1(this); } @Override diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/PurgeLocalHistoryRequestProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/PurgeLocalHistoryRequestProxyV1.java index ff7f4ee4e2..35571fb11d 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/PurgeLocalHistoryRequestProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/PurgeLocalHistoryRequestProxyV1.java @@ -7,18 +7,15 @@ */ package org.opendaylight.controller.cluster.access.commands; -import akka.actor.ActorRef; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; - /** * Externalizable proxy for use with {@link PurgeLocalHistoryRequest}. It implements the initial (Boron) serialization * format. * * @author Robert Varga */ -final class PurgeLocalHistoryRequestProxyV1 extends AbstractLocalHistoryRequestProxy { - @Serial +final class PurgeLocalHistoryRequestProxyV1 extends AbstractLocalHistoryRequestProxy + implements PurgeLocalHistoryRequest.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -31,10 +28,4 @@ final class PurgeLocalHistoryRequestProxyV1 extends AbstractLocalHistoryRequestP PurgeLocalHistoryRequestProxyV1(final PurgeLocalHistoryRequest request) { super(request); } - - @Override - protected PurgeLocalHistoryRequest createRequest(final LocalHistoryIdentifier target, final long sequence, - final ActorRef replyTo) { - return new PurgeLocalHistoryRequest(target, sequence, replyTo); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/RTR.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/RTR.java new file mode 100644 index 0000000000..e342c1806f --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/RTR.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link ReadTransactionRequest}. It implements the Chlorine SR2 serialization + * format. + */ +final class RTR implements ReadTransactionRequest.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private ReadTransactionRequest message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public RTR() { + // for Externalizable + } + + RTR(final ReadTransactionRequest message) { + this.message = requireNonNull(message); + } + + @Override + public ReadTransactionRequest message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final ReadTransactionRequest message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/RTS.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/RTS.java new file mode 100644 index 0000000000..bcf09f80ba --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/RTS.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link ReadTransactionSuccess}. It implements the Chlorine SR2 serialization + * format. + */ +final class RTS implements ReadTransactionSuccess.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private ReadTransactionSuccess message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public RTS() { + // for Externalizable + } + + RTS(final ReadTransactionSuccess message) { + this.message = requireNonNull(message); + } + + @Override + public ReadTransactionSuccess message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final ReadTransactionSuccess message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionRequest.java index c5a550ce05..00ae65b469 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionRequest.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionRequest.java @@ -8,7 +8,8 @@ package org.opendaylight.controller.cluster.access.commands; import akka.actor.ActorRef; -import java.io.Serial; +import java.io.IOException; +import java.io.ObjectInput; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -18,7 +19,16 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; * A transaction request to read a particular path exists in the current view of a particular transaction. */ public final class ReadTransactionRequest extends AbstractReadPathTransactionRequest { - @Serial + interface SerialForm extends AbstractReadPathTransactionRequest.SerialForm { + @Override + default ReadTransactionRequest readExternal(final ObjectInput in, final TransactionIdentifier target, + final long sequence, final ActorRef replyTo, final boolean snapshotOnly, final YangInstanceIdentifier path) + throws IOException { + return new ReadTransactionRequest(target, sequence, replyTo, path, snapshotOnly); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; public ReadTransactionRequest(final @NonNull TransactionIdentifier identifier, final long sequence, @@ -36,7 +46,7 @@ public final class ReadTransactionRequest extends AbstractReadPathTransactionReq } @Override - protected ReadTransactionRequestProxyV1 externalizableProxy(final ABIVersion version) { - return new ReadTransactionRequestProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new RTR(this) : new ReadTransactionRequestProxyV1(this); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionRequestProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionRequestProxyV1.java index 20d1d308f4..e27869547b 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionRequestProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionRequestProxyV1.java @@ -7,19 +7,15 @@ */ package org.opendaylight.controller.cluster.access.commands; -import akka.actor.ActorRef; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; - /** * Externalizable proxy for use with {@link ReadTransactionRequest}. It implements the initial (Boron) serialization * format. * * @author Robert Varga */ -final class ReadTransactionRequestProxyV1 extends AbstractReadPathTransactionRequestProxyV1 { - @Serial +final class ReadTransactionRequestProxyV1 extends AbstractReadPathTransactionRequestProxyV1 + implements ReadTransactionRequest.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -32,10 +28,4 @@ final class ReadTransactionRequestProxyV1 extends AbstractReadPathTransactionReq ReadTransactionRequestProxyV1(final ReadTransactionRequest request) { super(request); } - - @Override - ReadTransactionRequest createReadPathRequest(final TransactionIdentifier target, final long sequence, - final ActorRef replyTo, final YangInstanceIdentifier path, final boolean snapshotOnly) { - return new ReadTransactionRequest(target, sequence, replyTo, path, snapshotOnly); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionSuccess.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionSuccess.java index 1e473d2b30..b65473aa38 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionSuccess.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionSuccess.java @@ -10,12 +10,15 @@ package org.opendaylight.controller.cluster.access.commands; import static java.util.Objects.requireNonNull; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.io.Serial; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.util.Optional; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.SliceableMessage; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput; /** * Successful reply to an {@link ReadTransactionRequest}. It indicates presence of requested data via @@ -23,12 +26,46 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; */ public final class ReadTransactionSuccess extends TransactionSuccess implements SliceableMessage { - @Serial + interface SerialForm extends TransactionSuccess.SerialForm { + @Override + default ReadTransactionSuccess readExternal(final ObjectInput in, final TransactionIdentifier target, + final long sequence) throws IOException { + final Optional data; + if (in.readBoolean()) { + data = Optional.of(NormalizedNodeDataInput.newDataInput(in).readNormalizedNode()); + } else { + data = Optional.empty(); + } + return new ReadTransactionSuccess(target, sequence, data); + } + + @Override + default void writeExternal(final ObjectOutput out, final ReadTransactionSuccess msg) throws IOException { + TransactionSuccess.SerialForm.super.writeExternal(out, msg); + + final var data = msg.getData(); + if (data.isPresent()) { + out.writeBoolean(true); + try (var nnout = msg.getVersion().getStreamVersion().newDataOutput(out)) { + nnout.writeNormalizedNode(data.orElseThrow()); + } + } else { + out.writeBoolean(false); + } + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "interface-based best effort") private final Optional data; + private ReadTransactionSuccess(final ReadTransactionSuccess request, final ABIVersion version) { + super(request, version); + data = request.data; + } + public ReadTransactionSuccess(final TransactionIdentifier identifier, final long sequence, final Optional data) { super(identifier, sequence); @@ -40,12 +77,12 @@ public final class ReadTransactionSuccess extends TransactionSuccess externalizableProxy(final ABIVersion version) { - return new ReadTransactionSuccessProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new RTS(this) : new ReadTransactionSuccessProxyV1(this); } @Override protected ReadTransactionSuccess cloneAsVersion(final ABIVersion version) { - return this; + return new ReadTransactionSuccess(this, version); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionSuccessProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionSuccessProxyV1.java index df462cf0c3..9818ada0af 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionSuccessProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionSuccessProxyV1.java @@ -7,30 +7,17 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Serial; -import java.util.Optional; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataInput; -import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeDataOutput; -import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion; - /** * Externalizable proxy for use with {@link ReadTransactionSuccess}. It implements the initial (Boron) serialization * format. * * @author Robert Varga */ -final class ReadTransactionSuccessProxyV1 extends AbstractTransactionSuccessProxy { - @Serial +final class ReadTransactionSuccessProxyV1 extends AbstractTransactionSuccessProxy + implements ReadTransactionSuccess.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; - private Optional data; - private transient NormalizedNodeStreamVersion streamVersion; - // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to // be able to create instances via reflection. @SuppressWarnings("checkstyle:RedundantModifier") @@ -40,37 +27,5 @@ final class ReadTransactionSuccessProxyV1 extends AbstractTransactionSuccessProx ReadTransactionSuccessProxyV1(final ReadTransactionSuccess request) { super(request); - data = request.getData(); - streamVersion = request.getVersion().getStreamVersion(); - } - - @Override - public void writeExternal(final ObjectOutput out) throws IOException { - super.writeExternal(out); - - if (data.isPresent()) { - out.writeBoolean(true); - try (NormalizedNodeDataOutput nnout = streamVersion.newDataOutput(out)) { - nnout.writeNormalizedNode(data.get()); - } - } else { - out.writeBoolean(false); - } - } - - @Override - public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { - super.readExternal(in); - - if (in.readBoolean()) { - data = Optional.of(NormalizedNodeDataInput.newDataInput(in).readNormalizedNode()); - } else { - data = Optional.empty(); - } - } - - @Override - protected ReadTransactionSuccess createSuccess(final TransactionIdentifier target, final long sequence) { - return new ReadTransactionSuccess(target, sequence, data); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/STR.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/STR.java new file mode 100644 index 0000000000..aa529eab68 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/STR.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link SkipTransactionsRequest}. It implements the Chlorine SR2 serialization + * format. + */ +final class STR implements SkipTransactionsRequest.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private SkipTransactionsRequest message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public STR() { + // for Externalizable + } + + STR(final SkipTransactionsRequest message) { + this.message = requireNonNull(message); + } + + @Override + public SkipTransactionsRequest message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final SkipTransactionsRequest message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/STS.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/STS.java new file mode 100644 index 0000000000..c548a4fc45 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/STS.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link SkipTransactionsResponse}. It implements the Chlorine SR2 serialization + * format. + */ +final class STS implements SkipTransactionsResponse.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private SkipTransactionsResponse message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public STS() { + // for Externalizable + } + + STS(final SkipTransactionsResponse message) { + this.message = requireNonNull(message); + } + + @Override + public SkipTransactionsResponse message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final SkipTransactionsResponse message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/SkipTransactionsRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/SkipTransactionsRequest.java index 3b97bb9817..54fdfc581a 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/SkipTransactionsRequest.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/SkipTransactionsRequest.java @@ -11,12 +11,15 @@ import akka.actor.ActorRef; import com.google.common.base.MoreObjects.ToStringHelper; import com.google.common.collect.ImmutableList; import com.google.common.primitives.UnsignedLong; -import java.io.Serial; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.util.Collection; import java.util.List; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; +import org.opendaylight.yangtools.concepts.WritableObjects; /** * Request to skip a number of {@link TransactionIdentifier}s within a {code local history}. This request is essentially @@ -28,7 +31,50 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * explicitly retired and are guaranteed to never be used by the frontend. */ public final class SkipTransactionsRequest extends TransactionRequest { - @Serial + interface SerialForm extends TransactionRequest.SerialForm { + @Override + default SkipTransactionsRequest readExternal(final ObjectInput in, final TransactionIdentifier target, + final long sequence, final ActorRef replyTo) throws IOException { + final int size = in.readInt(); + final var builder = ImmutableList.builderWithExpectedSize(size); + int idx; + if (size % 2 != 0) { + builder.add(UnsignedLong.fromLongBits(WritableObjects.readLong(in))); + idx = 1; + } else { + idx = 0; + } + for (; idx < size; idx += 2) { + final byte hdr = WritableObjects.readLongHeader(in); + builder.add(UnsignedLong.fromLongBits(WritableObjects.readFirstLong(in, hdr))); + builder.add(UnsignedLong.fromLongBits(WritableObjects.readSecondLong(in, hdr))); + } + + return new SkipTransactionsRequest(target, sequence, replyTo, builder.build()); + } + + @Override + default void writeExternal(final ObjectOutput out, final SkipTransactionsRequest msg) throws IOException { + TransactionRequest.SerialForm.super.writeExternal(out, msg); + + final var others = msg.others; + final int size = others.size(); + out.writeInt(size); + + int idx; + if (size % 2 != 0) { + WritableObjects.writeLong(out, others.get(0).longValue()); + idx = 1; + } else { + idx = 0; + } + for (; idx < size; idx += 2) { + WritableObjects.writeLongs(out, others.get(idx).longValue(), others.get(idx + 1).longValue()); + } + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; // Note: UnsignedLong is arbitrary, yang.common.Uint64 would work just as well, we really want an immutable @@ -41,6 +87,11 @@ public final class SkipTransactionsRequest extends TransactionRequest { - @Serial +final class SkipTransactionsRequestV1 extends AbstractTransactionRequestProxy + implements SkipTransactionsRequest.SerialForm { + @java.io.Serial private static final long serialVersionUID = -7493419007644462643L; - private List others; - // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to // be able to create instances via reflection. @SuppressWarnings("checkstyle:RedundantModifier") @@ -37,52 +25,5 @@ final class SkipTransactionsRequestV1 extends AbstractTransactionRequestProxybuilderWithExpectedSize(size); - int idx; - if (size % 2 != 0) { - builder.add(UnsignedLong.fromLongBits(WritableObjects.readLong(in))); - idx = 1; - } else { - idx = 0; - } - for (; idx < size; idx += 2) { - final byte hdr = WritableObjects.readLongHeader(in); - builder.add(UnsignedLong.fromLongBits(WritableObjects.readFirstLong(in, hdr))); - builder.add(UnsignedLong.fromLongBits(WritableObjects.readSecondLong(in, hdr))); - } - others = builder.build(); - } - - @Override - public void writeExternal(final ObjectOutput out) throws IOException { - super.writeExternal(out); - - final int size = others.size(); - out.writeInt(size); - - int idx; - if (size % 2 != 0) { - WritableObjects.writeLong(out, others.get(0).longValue()); - idx = 1; - } else { - idx = 0; - } - for (; idx < size; idx += 2) { - WritableObjects.writeLongs(out, others.get(idx).longValue(), others.get(idx + 1).longValue()); - } - } - - @Override - protected SkipTransactionsRequest createRequest(final TransactionIdentifier target, final long sequence, - final ActorRef replyToActor) { - return new SkipTransactionsRequest(target, sequence, replyToActor, others); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/SkipTransactionsResponse.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/SkipTransactionsResponse.java index 6d168d30d6..b2fbc71421 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/SkipTransactionsResponse.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/SkipTransactionsResponse.java @@ -7,29 +7,41 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; +import java.io.ObjectInput; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; /** * Successful reply to a {@link SkipTransactionsRequest}. */ +// FIXME: rename to SkipTransactionsSuccess public final class SkipTransactionsResponse extends TransactionSuccess { - @Serial + interface SerialForm extends TransactionSuccess.SerialForm { + @Override + default SkipTransactionsResponse readExternal(final ObjectInput in, final TransactionIdentifier target, + final long sequence) { + return new SkipTransactionsResponse(target, sequence); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; + private SkipTransactionsResponse(final SkipTransactionsResponse success, final ABIVersion version) { + super(success, version); + } + public SkipTransactionsResponse(final TransactionIdentifier identifier, final long sequence) { super(identifier, sequence); } @Override - protected AbstractTransactionSuccessProxy externalizableProxy( - final ABIVersion version) { - return new SkipTransactionsResponseProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new STS(this) : new SkipTransactionsResponseProxyV1(this); } @Override protected SkipTransactionsResponse cloneAsVersion(final ABIVersion version) { - return this; + return new SkipTransactionsResponse(this, version); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/SkipTransactionsResponseProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/SkipTransactionsResponseProxyV1.java index a1bf23de6d..7e08536f60 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/SkipTransactionsResponseProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/SkipTransactionsResponseProxyV1.java @@ -7,15 +7,13 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; - /** * Externalizable proxy for use with {@link SkipTransactionsResponse}. It implements the initial (Phosphorus SR1) * serialization format. */ -final class SkipTransactionsResponseProxyV1 extends AbstractTransactionSuccessProxy { - @Serial +final class SkipTransactionsResponseProxyV1 extends AbstractTransactionSuccessProxy + implements SkipTransactionsResponse.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -28,9 +26,4 @@ final class SkipTransactionsResponseProxyV1 extends AbstractTransactionSuccessPr SkipTransactionsResponseProxyV1(final SkipTransactionsResponse success) { super(success); } - - @Override - protected SkipTransactionsResponse createSuccess(final TransactionIdentifier target, final long sequence) { - return new SkipTransactionsResponse(target, sequence); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TAR.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TAR.java new file mode 100644 index 0000000000..98f63b75ca --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TAR.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link TransactionAbortRequest}. It implements the Chlorine SR2 serialization + * format. + */ +final class TAR implements TransactionAbortRequest.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private TransactionAbortRequest message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public TAR() { + // for Externalizable + } + + TAR(final TransactionAbortRequest message) { + this.message = requireNonNull(message); + } + + @Override + public TransactionAbortRequest message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final TransactionAbortRequest message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TAS.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TAS.java new file mode 100644 index 0000000000..c34323bf75 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TAS.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link TransactionAbortSuccess}. It implements the Chlorine SR2 serialization + * format. + */ +final class TAS implements TransactionAbortSuccess.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private TransactionAbortSuccess message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public TAS() { + // for Externalizable + } + + TAS(final TransactionAbortSuccess message) { + this.message = requireNonNull(message); + } + + @Override + public TransactionAbortSuccess message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final TransactionAbortSuccess message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TCCS.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TCCS.java new file mode 100644 index 0000000000..ab094b3054 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TCCS.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link TransactionCanCommitSuccess}. It implements the Chlorine SR2 serialization + * format. + */ +final class TCCS implements TransactionCanCommitSuccess.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private TransactionCanCommitSuccess message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public TCCS() { + // for Externalizable + } + + TCCS(final TransactionCanCommitSuccess message) { + this.message = requireNonNull(message); + } + + @Override + public TransactionCanCommitSuccess message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final TransactionCanCommitSuccess message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TCS.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TCS.java new file mode 100644 index 0000000000..5e0265da33 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TCS.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link TransactionCommitSuccess}. It implements the Chlorine SR2 serialization + * format. + */ +final class TCS implements TransactionCommitSuccess.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private TransactionCommitSuccess message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public TCS() { + // for Externalizable + } + + TCS(final TransactionCommitSuccess message) { + this.message = requireNonNull(message); + } + + @Override + public TransactionCommitSuccess message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final TransactionCommitSuccess message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TDCR.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TDCR.java new file mode 100644 index 0000000000..01c2733f9f --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TDCR.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link TransactionDoCommitRequest}. It implements the Chlorine SR2 serialization + * format. + */ +final class TDCR implements TransactionDoCommitRequest.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private TransactionDoCommitRequest message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public TDCR() { + // for Externalizable + } + + TDCR(final TransactionDoCommitRequest message) { + this.message = requireNonNull(message); + } + + @Override + public TransactionDoCommitRequest message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final TransactionDoCommitRequest message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TF.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TF.java new file mode 100644 index 0000000000..6e26fc329d --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TF.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link TransactionFailure}. It implements the Chlorine SR2 serialization format. + */ +final class TF implements TransactionFailure.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private TransactionFailure message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public TF() { + // for Externalizable + } + + TF(final TransactionFailure message) { + this.message = requireNonNull(message); + } + + @Override + public TransactionFailure message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final TransactionFailure message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TPCR.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TPCR.java new file mode 100644 index 0000000000..0bf4ae5ea9 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TPCR.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link TransactionPreCommitRequest}. It implements the Chlorine SR2 serialization + * format. + */ +final class TPCR implements TransactionPreCommitRequest.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private TransactionPreCommitRequest message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public TPCR() { + // for Externalizable + } + + TPCR(final TransactionPreCommitRequest message) { + this.message = requireNonNull(message); + } + + @Override + public TransactionPreCommitRequest message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final TransactionPreCommitRequest message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TPCS.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TPCS.java new file mode 100644 index 0000000000..28c0e95bc3 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TPCS.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link TransactionPreCommitSuccess}. It implements the Chlorine SR2 serialization + * format. + */ +final class TPCS implements TransactionPreCommitSuccess.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private TransactionPreCommitSuccess message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public TPCS() { + // for Externalizable + } + + TPCS(final TransactionPreCommitSuccess message) { + this.message = requireNonNull(message); + } + + @Override + public TransactionPreCommitSuccess message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final TransactionPreCommitSuccess message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TPR.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TPR.java new file mode 100644 index 0000000000..a80e1f6675 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TPR.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link TransactionPurgeRequest}. It implements the Chlorine SR2 serialization + * format. + */ +final class TPR implements TransactionPurgeRequest.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private TransactionPurgeRequest message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public TPR() { + // for Externalizable + } + + TPR(final TransactionPurgeRequest message) { + this.message = requireNonNull(message); + } + + @Override + public TransactionPurgeRequest message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final TransactionPurgeRequest message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TPS.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TPS.java new file mode 100644 index 0000000000..cff3891a67 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TPS.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.commands; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Externalizable proxy for use with {@link TransactionPurgeResponse}. It implements the Chlorine SR2 serialization + * format. + */ +final class TPS implements TransactionPurgeResponse.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private TransactionPurgeResponse message; + + @SuppressWarnings("checkstyle:RedundantModifier") + public TPS() { + // for Externalizable + } + + TPS(final TransactionPurgeResponse message) { + this.message = requireNonNull(message); + } + + @Override + public TransactionPurgeResponse message() { + return verifyNotNull(message); + } + + @Override + public void setMessage(final TransactionPurgeResponse message) { + this.message = requireNonNull(message); + } + + @Override + public Object readResolve() { + return message(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortRequest.java index d43d188de4..6ad73ef427 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortRequest.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortRequest.java @@ -8,7 +8,7 @@ package org.opendaylight.controller.cluster.access.commands; import akka.actor.ActorRef; -import java.io.Serial; +import java.io.ObjectInput; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -16,20 +16,32 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * A transaction request to perform the abort step of the three-phase commit protocol. */ public final class TransactionAbortRequest extends TransactionRequest { - @Serial + interface SerialForm extends TransactionRequest.SerialForm { + @Override + default TransactionAbortRequest readExternal(final ObjectInput in, final TransactionIdentifier target, + final long sequence, final ActorRef replyTo) { + return new TransactionAbortRequest(target, sequence, replyTo); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; + private TransactionAbortRequest(final TransactionAbortRequest request, final ABIVersion version) { + super(request, version); + } + public TransactionAbortRequest(final TransactionIdentifier target, final long sequence, final ActorRef replyTo) { super(target, sequence, replyTo); } @Override - protected TransactionAbortRequestProxyV1 externalizableProxy(final ABIVersion version) { - return new TransactionAbortRequestProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new TAR(this) : new TransactionAbortRequestProxyV1(this); } @Override protected TransactionAbortRequest cloneAsVersion(final ABIVersion version) { - return this; + return new TransactionAbortRequest(this, version); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortRequestProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortRequestProxyV1.java index b4f80f64e4..87def66318 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortRequestProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortRequestProxyV1.java @@ -7,18 +7,15 @@ */ package org.opendaylight.controller.cluster.access.commands; -import akka.actor.ActorRef; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; - /** * Externalizable proxy for use with {@link TransactionAbortRequest}. It implements the initial (Boron) serialization * format. * * @author Robert Varga */ -final class TransactionAbortRequestProxyV1 extends AbstractTransactionRequestProxy { - @Serial +final class TransactionAbortRequestProxyV1 extends AbstractTransactionRequestProxy + implements TransactionAbortRequest.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -31,10 +28,4 @@ final class TransactionAbortRequestProxyV1 extends AbstractTransactionRequestPro TransactionAbortRequestProxyV1(final TransactionAbortRequest request) { super(request); } - - @Override - protected TransactionAbortRequest createRequest(final TransactionIdentifier target, final long sequence, - final ActorRef replyTo) { - return new TransactionAbortRequest(target, sequence, replyTo); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortSuccess.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortSuccess.java index 44de3f69fe..9f2c4c967b 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortSuccess.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortSuccess.java @@ -7,7 +7,7 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; +import java.io.ObjectInput; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -18,20 +18,32 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * @author Robert Varga */ public final class TransactionAbortSuccess extends TransactionSuccess { - @Serial + interface SerialForm extends TransactionSuccess.SerialForm { + @Override + default TransactionAbortSuccess readExternal(final ObjectInput in, final TransactionIdentifier target, + final long sequence) { + return new TransactionAbortSuccess(target, sequence); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; + private TransactionAbortSuccess(final TransactionAbortSuccess success, final ABIVersion version) { + super(success, version); + } + public TransactionAbortSuccess(final TransactionIdentifier identifier, final long sequence) { super(identifier, sequence); } @Override - protected AbstractTransactionSuccessProxy externalizableProxy(final ABIVersion version) { - return new TransactionAbortSuccessProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new TAS(this) : new TransactionAbortSuccessProxyV1(this); } @Override protected TransactionAbortSuccess cloneAsVersion(final ABIVersion version) { - return this; + return new TransactionAbortSuccess(this, version); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortSuccessProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortSuccessProxyV1.java index c04cadc977..9d057ada5e 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortSuccessProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortSuccessProxyV1.java @@ -7,17 +7,15 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; - /** * Externalizable proxy for use with {@link TransactionAbortSuccess}. It implements the initial (Boron) * serialization format. * * @author Robert Varga */ -final class TransactionAbortSuccessProxyV1 extends AbstractTransactionSuccessProxy { - @Serial +final class TransactionAbortSuccessProxyV1 extends AbstractTransactionSuccessProxy + implements TransactionAbortSuccess.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -30,9 +28,4 @@ final class TransactionAbortSuccessProxyV1 extends AbstractTransactionSuccessPro TransactionAbortSuccessProxyV1(final TransactionAbortSuccess success) { super(success); } - - @Override - protected TransactionAbortSuccess createSuccess(final TransactionIdentifier target, final long sequence) { - return new TransactionAbortSuccess(target, sequence); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionCanCommitSuccess.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionCanCommitSuccess.java index 720305dc42..5e9e74f81b 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionCanCommitSuccess.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionCanCommitSuccess.java @@ -7,7 +7,7 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; +import java.io.ObjectInput; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -18,21 +18,32 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * @author Robert Varga */ public final class TransactionCanCommitSuccess extends TransactionSuccess { - @Serial + interface SerialForm extends TransactionSuccess.SerialForm { + @Override + default TransactionCanCommitSuccess readExternal(final ObjectInput in, final TransactionIdentifier target, + final long sequence) { + return new TransactionCanCommitSuccess(target, sequence); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; + private TransactionCanCommitSuccess(final TransactionCanCommitSuccess success, final ABIVersion version) { + super(success, version); + } + public TransactionCanCommitSuccess(final TransactionIdentifier identifier, final long sequence) { super(identifier, sequence); } @Override - protected AbstractTransactionSuccessProxy externalizableProxy( - final ABIVersion version) { - return new TransactionCanCommitSuccessProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new TCCS(this) : new TransactionCanCommitSuccessProxyV1(this); } @Override protected TransactionCanCommitSuccess cloneAsVersion(final ABIVersion version) { - return this; + return new TransactionCanCommitSuccess(this, version); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionCanCommitSuccessProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionCanCommitSuccessProxyV1.java index b187ce5247..0d731c86ff 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionCanCommitSuccessProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionCanCommitSuccessProxyV1.java @@ -7,20 +7,15 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; - /** * Externalizable proxy for use with {@link TransactionCanCommitSuccess}. It implements the initial (Boron) * serialization format. * * @author Robert Varga */ -final class TransactionCanCommitSuccessProxyV1 extends AbstractTransactionSuccessProxy { - @Serial +final class TransactionCanCommitSuccessProxyV1 extends AbstractTransactionSuccessProxy + implements TransactionCanCommitSuccess.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -33,19 +28,4 @@ final class TransactionCanCommitSuccessProxyV1 extends AbstractTransactionSucces TransactionCanCommitSuccessProxyV1(final TransactionCanCommitSuccess success) { super(success); } - - @Override - public void writeExternal(final ObjectOutput out) throws IOException { - super.writeExternal(out); - } - - @Override - public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { - super.readExternal(in); - } - - @Override - protected TransactionCanCommitSuccess createSuccess(final TransactionIdentifier target, final long sequence) { - return new TransactionCanCommitSuccess(target, sequence); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionCommitSuccess.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionCommitSuccess.java index 8ba0b476ad..a91fe5c9bf 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionCommitSuccess.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionCommitSuccess.java @@ -7,7 +7,7 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; +import java.io.ObjectInput; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -18,20 +18,32 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * @author Robert Varga */ public final class TransactionCommitSuccess extends TransactionSuccess { - @Serial + interface SerialForm extends TransactionSuccess.SerialForm { + @Override + default TransactionCommitSuccess readExternal(final ObjectInput in, final TransactionIdentifier target, + final long sequence) { + return new TransactionCommitSuccess(target, sequence); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; + private TransactionCommitSuccess(final TransactionCommitSuccess success, final ABIVersion version) { + super(success, version); + } + public TransactionCommitSuccess(final TransactionIdentifier identifier, final long sequence) { super(identifier, sequence); } @Override - protected AbstractTransactionSuccessProxy externalizableProxy(final ABIVersion version) { - return new TransactionCommitSuccessProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new TCS(this) : new TransactionCommitSuccessProxyV1(this); } @Override protected TransactionCommitSuccess cloneAsVersion(final ABIVersion version) { - return this; + return new TransactionCommitSuccess(this, version); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionCommitSuccessProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionCommitSuccessProxyV1.java index 42a8151db9..ad2f1cb6c4 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionCommitSuccessProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionCommitSuccessProxyV1.java @@ -7,17 +7,15 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; - /** * Externalizable proxy for use with {@link TransactionCommitSuccess}. It implements the initial (Boron) * serialization format. * * @author Robert Varga */ -final class TransactionCommitSuccessProxyV1 extends AbstractTransactionSuccessProxy { - @Serial +final class TransactionCommitSuccessProxyV1 extends AbstractTransactionSuccessProxy + implements TransactionCommitSuccess.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -30,9 +28,4 @@ final class TransactionCommitSuccessProxyV1 extends AbstractTransactionSuccessPr TransactionCommitSuccessProxyV1(final TransactionCommitSuccess success) { super(success); } - - @Override - protected TransactionCommitSuccess createSuccess(final TransactionIdentifier target, final long sequence) { - return new TransactionCommitSuccess(target, sequence); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionDoCommitRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionDoCommitRequest.java index 92ede4f1d8..9ba1f1d48f 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionDoCommitRequest.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionDoCommitRequest.java @@ -8,7 +8,7 @@ package org.opendaylight.controller.cluster.access.commands; import akka.actor.ActorRef; -import java.io.Serial; +import java.io.ObjectInput; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -16,20 +16,32 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * A transaction request to perform the final, doCommit, step of the three-phase commit protocol. */ public final class TransactionDoCommitRequest extends TransactionRequest { - @Serial + interface SerialForm extends TransactionRequest.SerialForm { + @Override + default TransactionDoCommitRequest readExternal(final ObjectInput in, final TransactionIdentifier target, + final long sequence, final ActorRef replyTo) { + return new TransactionDoCommitRequest(target, sequence, replyTo); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; + private TransactionDoCommitRequest(final TransactionDoCommitRequest request, final ABIVersion version) { + super(request, version); + } + public TransactionDoCommitRequest(final TransactionIdentifier target, final long sequence, final ActorRef replyTo) { super(target, sequence, replyTo); } @Override - protected TransactionDoCommitRequestProxyV1 externalizableProxy(final ABIVersion version) { - return new TransactionDoCommitRequestProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new TDCR(this) : new TransactionDoCommitRequestProxyV1(this); } @Override protected TransactionDoCommitRequest cloneAsVersion(final ABIVersion version) { - return this; + return new TransactionDoCommitRequest(this, version); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionDoCommitRequestProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionDoCommitRequestProxyV1.java index c510e3f071..ea9cfdb041 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionDoCommitRequestProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionDoCommitRequestProxyV1.java @@ -7,18 +7,15 @@ */ package org.opendaylight.controller.cluster.access.commands; -import akka.actor.ActorRef; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; - /** * Externalizable proxy for use with {@link TransactionDoCommitRequest}. It implements the initial (Boron) serialization * format. * * @author Robert Varga */ -final class TransactionDoCommitRequestProxyV1 extends AbstractTransactionRequestProxy { - @Serial +final class TransactionDoCommitRequestProxyV1 extends AbstractTransactionRequestProxy + implements TransactionDoCommitRequest.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -31,10 +28,4 @@ final class TransactionDoCommitRequestProxyV1 extends AbstractTransactionRequest TransactionDoCommitRequestProxyV1(final TransactionDoCommitRequest request) { super(request); } - - @Override - protected TransactionDoCommitRequest createRequest(final TransactionIdentifier target, final long sequence, - final ActorRef replyTo) { - return new TransactionDoCommitRequest(target, sequence, replyTo); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionFailure.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionFailure.java index 86240ddfbc..af8509601a 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionFailure.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionFailure.java @@ -7,7 +7,8 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; +import java.io.DataInput; +import java.io.IOException; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.RequestException; import org.opendaylight.controller.cluster.access.concepts.RequestFailure; @@ -17,20 +18,37 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * Generic {@link RequestFailure} involving a {@link TransactionRequest}. */ public final class TransactionFailure extends RequestFailure { - @Serial + interface SerialForm extends RequestFailure.SerialForm { + @Override + default TransactionIdentifier readTarget(final DataInput in) throws IOException { + return TransactionIdentifier.readFrom(in); + } + + @Override + default TransactionFailure createFailure(final TransactionIdentifier target, final long sequence, + final RequestException cause) { + return new TransactionFailure(target, sequence, cause); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; + private TransactionFailure(final TransactionFailure failure, final ABIVersion version) { + super(failure, version); + } + TransactionFailure(final TransactionIdentifier target, final long sequence, final RequestException cause) { super(target, sequence, cause); } @Override protected TransactionFailure cloneAsVersion(final ABIVersion version) { - return this; + return new TransactionFailure(this, version); } @Override - protected TransactionFailureProxyV1 externalizableProxy(final ABIVersion version) { - return new TransactionFailureProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new TF(this) : new TransactionFailureProxyV1(this); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionFailureProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionFailureProxyV1.java index 70d1e30e51..335308b05c 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionFailureProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionFailureProxyV1.java @@ -7,11 +7,7 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.DataInput; -import java.io.IOException; -import java.io.Serial; import org.opendaylight.controller.cluster.access.concepts.AbstractRequestFailureProxy; -import org.opendaylight.controller.cluster.access.concepts.RequestException; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; /** @@ -20,8 +16,9 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * * @author Robert Varga */ -final class TransactionFailureProxyV1 extends AbstractRequestFailureProxy { - @Serial +final class TransactionFailureProxyV1 extends AbstractRequestFailureProxy + implements TransactionFailure.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -34,15 +31,4 @@ final class TransactionFailureProxyV1 extends AbstractRequestFailureProxy { - @Serial + interface SerialForm extends TransactionRequest.SerialForm { + @Override + default TransactionPreCommitRequest readExternal(final ObjectInput in, final TransactionIdentifier target, + final long sequence, final ActorRef replyTo) { + return new TransactionPreCommitRequest(target, sequence, replyTo); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; + private TransactionPreCommitRequest(final TransactionPreCommitRequest request, final ABIVersion version) { + super(request, version); + } + public TransactionPreCommitRequest(final TransactionIdentifier target, final long sequence, final ActorRef replyTo) { super(target, sequence, replyTo); } @Override - protected TransactionPreCommitRequestProxyV1 externalizableProxy(final ABIVersion version) { - return new TransactionPreCommitRequestProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new TPCR(this) : new TransactionPreCommitRequestProxyV1(this); } @Override protected TransactionPreCommitRequest cloneAsVersion(final ABIVersion version) { - return this; + return new TransactionPreCommitRequest(this, version); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitRequestProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitRequestProxyV1.java index 2b56cc352b..59fefb66dc 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitRequestProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitRequestProxyV1.java @@ -7,18 +7,15 @@ */ package org.opendaylight.controller.cluster.access.commands; -import akka.actor.ActorRef; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; - /** * Externalizable proxy for use with {@link TransactionPreCommitRequest}. It implements the initial (Boron) * serialization format. * * @author Robert Varga */ -final class TransactionPreCommitRequestProxyV1 extends AbstractTransactionRequestProxy { - @Serial +final class TransactionPreCommitRequestProxyV1 extends AbstractTransactionRequestProxy + implements TransactionPreCommitRequest.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -31,10 +28,4 @@ final class TransactionPreCommitRequestProxyV1 extends AbstractTransactionReques TransactionPreCommitRequestProxyV1(final TransactionPreCommitRequest request) { super(request); } - - @Override - protected TransactionPreCommitRequest createRequest(final TransactionIdentifier target, final long sequence, - final ActorRef replyTo) { - return new TransactionPreCommitRequest(target, sequence, replyTo); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitSuccess.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitSuccess.java index a349d72e8b..635573ba51 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitSuccess.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitSuccess.java @@ -7,7 +7,8 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; +import java.io.IOException; +import java.io.ObjectInput; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -17,21 +18,32 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * @author Robert Varga */ public final class TransactionPreCommitSuccess extends TransactionSuccess { - @Serial + interface SerialForm extends TransactionSuccess.SerialForm { + @Override + default TransactionPreCommitSuccess readExternal(final ObjectInput in, final TransactionIdentifier target, + final long sequence) throws IOException { + return new TransactionPreCommitSuccess(target, sequence); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; + private TransactionPreCommitSuccess(final TransactionPreCommitSuccess success, final ABIVersion version) { + super(success, version); + } + public TransactionPreCommitSuccess(final TransactionIdentifier identifier, final long sequence) { super(identifier, sequence); } @Override - protected AbstractTransactionSuccessProxy externalizableProxy( - final ABIVersion version) { - return new TransactionPreCommitSuccessProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new TPCS(this) : new TransactionPreCommitSuccessProxyV1(this); } @Override protected TransactionPreCommitSuccess cloneAsVersion(final ABIVersion version) { - return this; + return new TransactionPreCommitSuccess(this, version); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitSuccessProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitSuccessProxyV1.java index 4e71077f83..e421f785ff 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitSuccessProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitSuccessProxyV1.java @@ -7,17 +7,15 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; - /** * Externalizable proxy for use with {@link TransactionPreCommitSuccess}. It implements the initial (Boron) * serialization format. * * @author Robert Varga */ -final class TransactionPreCommitSuccessProxyV1 extends AbstractTransactionSuccessProxy { - @Serial +final class TransactionPreCommitSuccessProxyV1 extends AbstractTransactionSuccessProxy + implements TransactionPreCommitSuccess.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -30,9 +28,4 @@ final class TransactionPreCommitSuccessProxyV1 extends AbstractTransactionSucces TransactionPreCommitSuccessProxyV1(final TransactionPreCommitSuccess success) { super(success); } - - @Override - protected TransactionPreCommitSuccess createSuccess(final TransactionIdentifier target, final long sequence) { - return new TransactionPreCommitSuccess(target, sequence); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeRequest.java index a374a891db..dd26df2529 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeRequest.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeRequest.java @@ -8,7 +8,7 @@ package org.opendaylight.controller.cluster.access.commands; import akka.actor.ActorRef; -import java.io.Serial; +import java.io.ObjectInput; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -18,20 +18,32 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * to the transaction and responds with a {@link TransactionPurgeResponse}. */ public final class TransactionPurgeRequest extends TransactionRequest { - @Serial + interface SerialForm extends TransactionRequest.SerialForm { + @Override + default TransactionPurgeRequest readExternal(final ObjectInput in, final TransactionIdentifier target, + final long sequence, final ActorRef replyTo) { + return new TransactionPurgeRequest(target, sequence, replyTo); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; + private TransactionPurgeRequest(final TransactionPurgeRequest request, final ABIVersion version) { + super(request, version); + } + public TransactionPurgeRequest(final TransactionIdentifier target, final long sequence, final ActorRef replyTo) { super(target, sequence, replyTo); } @Override - protected TransactionPurgeRequestProxyV1 externalizableProxy(final ABIVersion version) { - return new TransactionPurgeRequestProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new TPR(this) : new TransactionPurgeRequestProxyV1(this); } @Override protected TransactionPurgeRequest cloneAsVersion(final ABIVersion version) { - return this; + return new TransactionPurgeRequest(this, version); } } \ No newline at end of file diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeRequestProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeRequestProxyV1.java index a6be95d9f9..529cc090f8 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeRequestProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeRequestProxyV1.java @@ -7,18 +7,15 @@ */ package org.opendaylight.controller.cluster.access.commands; -import akka.actor.ActorRef; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; - /** * Externalizable proxy for use with {@link TransactionPurgeRequest}. It implements the initial (Boron) * serialization format. * * @author Robert Varga */ -final class TransactionPurgeRequestProxyV1 extends AbstractTransactionRequestProxy { - @Serial +final class TransactionPurgeRequestProxyV1 extends AbstractTransactionRequestProxy + implements TransactionPurgeRequest.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -31,10 +28,4 @@ final class TransactionPurgeRequestProxyV1 extends AbstractTransactionRequestPro TransactionPurgeRequestProxyV1(final TransactionPurgeRequest request) { super(request); } - - @Override - protected TransactionPurgeRequest createRequest(final TransactionIdentifier target, final long sequence, - final ActorRef replyTo) { - return new TransactionPurgeRequest(target, sequence, replyTo); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeResponse.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeResponse.java index 1d3a74ab05..5b650e60f9 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeResponse.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeResponse.java @@ -7,31 +7,41 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; +import java.io.ObjectInput; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; /** * Successful reply to a {@link TransactionPurgeRequest}. - * - * @author Robert Varga */ +// FIXME: rename to TransactionPurgeSuccess public final class TransactionPurgeResponse extends TransactionSuccess { - @Serial + interface SerialForm extends TransactionSuccess.SerialForm { + @Override + default TransactionPurgeResponse readExternal(final ObjectInput in, final TransactionIdentifier target, + final long sequence) { + return new TransactionPurgeResponse(target, sequence); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; + private TransactionPurgeResponse(final TransactionPurgeResponse success, final ABIVersion version) { + super(success, version); + } + public TransactionPurgeResponse(final TransactionIdentifier identifier, final long sequence) { super(identifier, sequence); } @Override - protected AbstractTransactionSuccessProxy externalizableProxy( - final ABIVersion version) { - return new TransactionPurgeResponseProxyV1(this); + protected SerialForm externalizableProxy(final ABIVersion version) { + return ABIVersion.MAGNESIUM.lt(version) ? new TPS(this) : new TransactionPurgeResponseProxyV1(this); } @Override protected TransactionPurgeResponse cloneAsVersion(final ABIVersion version) { - return this; + return new TransactionPurgeResponse(this, version); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeResponseProxyV1.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeResponseProxyV1.java index f51dc606fa..3875614187 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeResponseProxyV1.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeResponseProxyV1.java @@ -7,17 +7,15 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; - /** * Externalizable proxy for use with {@link TransactionPurgeResponse}. It implements the initial (Boron) * serialization format. * * @author Robert Varga */ -final class TransactionPurgeResponseProxyV1 extends AbstractTransactionSuccessProxy { - @Serial +final class TransactionPurgeResponseProxyV1 extends AbstractTransactionSuccessProxy + implements TransactionPurgeResponse.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -30,9 +28,4 @@ final class TransactionPurgeResponseProxyV1 extends AbstractTransactionSuccessPr TransactionPurgeResponseProxyV1(final TransactionPurgeResponse success) { super(success); } - - @Override - protected TransactionPurgeResponse createSuccess(final TransactionIdentifier target, final long sequence) { - return new TransactionPurgeResponse(target, sequence); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionRequest.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionRequest.java index fb12edeacd..15d98f9150 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionRequest.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionRequest.java @@ -8,7 +8,8 @@ package org.opendaylight.controller.cluster.access.commands; import akka.actor.ActorRef; -import java.io.Serial; +import java.io.DataInput; +import java.io.IOException; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.Request; import org.opendaylight.controller.cluster.access.concepts.RequestException; @@ -21,7 +22,15 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier * @param Message type */ public abstract class TransactionRequest> extends Request { - @Serial + protected interface SerialForm> + extends Request.SerialForm { + @Override + default TransactionIdentifier readTarget(final DataInput in) throws IOException { + return TransactionIdentifier.readFrom(in); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; TransactionRequest(final TransactionIdentifier identifier, final long sequence, final ActorRef replyTo) { @@ -38,5 +47,5 @@ public abstract class TransactionRequest> extend } @Override - protected abstract AbstractTransactionRequestProxy externalizableProxy(ABIVersion version); + protected abstract SerialForm externalizableProxy(ABIVersion version); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionSuccess.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionSuccess.java index f70b750813..689b4d5ee1 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionSuccess.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/TransactionSuccess.java @@ -7,7 +7,8 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; +import java.io.DataInput; +import java.io.IOException; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.controller.cluster.access.concepts.RequestSuccess; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; @@ -20,7 +21,14 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier */ public abstract class TransactionSuccess> extends RequestSuccess { - @Serial + interface SerialForm> extends RequestSuccess.SerialForm { + @Override + default TransactionIdentifier readTarget(final DataInput in) throws IOException { + return TransactionIdentifier.readFrom(in); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; TransactionSuccess(final TransactionIdentifier identifier, final long sequence) { @@ -32,5 +40,5 @@ public abstract class TransactionSuccess> } @Override - protected abstract AbstractTransactionSuccessProxy externalizableProxy(ABIVersion version); + protected abstract SerialForm externalizableProxy(ABIVersion version); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/UnknownHistoryException.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/UnknownHistoryException.java index b7b2228e0f..c688df3c90 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/UnknownHistoryException.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/commands/UnknownHistoryException.java @@ -7,7 +7,6 @@ */ package org.opendaylight.controller.cluster.access.commands; -import java.io.Serial; import org.opendaylight.controller.cluster.access.concepts.RequestException; /** @@ -15,7 +14,7 @@ import org.opendaylight.controller.cluster.access.concepts.RequestException; * typically happens when the linear history ID is newer than the highest observed {@link CreateLocalHistoryRequest}. */ public final class UnknownHistoryException extends RequestException { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; public UnknownHistoryException(final Long lastSeenHistory) { diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractEnvelopeProxy.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractEnvelopeProxy.java index c4d100a560..a97a3f0aad 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractEnvelopeProxy.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractEnvelopeProxy.java @@ -7,51 +7,36 @@ */ package org.opendaylight.controller.cluster.access.concepts; -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Serial; -import org.opendaylight.yangtools.concepts.WritableObjects; - -abstract class AbstractEnvelopeProxy> implements Externalizable { - @Serial +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +abstract class AbstractEnvelopeProxy, E extends Envelope> + implements Envelope.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; - private T message; - private long sessionId; - private long txSequence; + private E envelope; AbstractEnvelopeProxy() { // for Externalizable } - AbstractEnvelopeProxy(final Envelope envelope) { - message = envelope.getMessage(); - txSequence = envelope.getTxSequence(); - sessionId = envelope.getSessionId(); + AbstractEnvelopeProxy(final E envelope) { + this.envelope = requireNonNull(envelope); } @Override - public void writeExternal(final ObjectOutput out) throws IOException { - WritableObjects.writeLongs(out, sessionId, txSequence); - out.writeObject(message); + public final E envelope() { + return verifyNotNull(envelope); } - @SuppressWarnings("unchecked") @Override - public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { - final byte header = WritableObjects.readLongHeader(in); - sessionId = WritableObjects.readFirstLong(in, header); - txSequence = WritableObjects.readSecondLong(in, header); - message = (T) in.readObject(); + public final void setEnvelope(final E envelope) { + this.envelope = requireNonNull(envelope); } - @SuppressWarnings("checkstyle:hiddenField") - abstract Envelope createEnvelope(T wrappedNessage, long sessionId, long txSequence); - - @Serial - final Object readResolve() { - return createEnvelope(message, sessionId, txSequence); + @Override + public final Object readResolve() { + return envelope(); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractMessageProxy.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractMessageProxy.java index 1cc091bdb2..8b0912ff63 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractMessageProxy.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractMessageProxy.java @@ -8,16 +8,10 @@ package org.opendaylight.controller.cluster.access.concepts; import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; -import java.io.DataInput; -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Serial; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.concepts.WritableIdentifier; -import org.opendaylight.yangtools.concepts.WritableObjects; /** * Abstract Externalizable proxy for use with {@link Message} subclasses. @@ -27,40 +21,33 @@ import org.opendaylight.yangtools.concepts.WritableObjects; * @param Target identifier type * @param Message class */ -abstract class AbstractMessageProxy> implements Externalizable { - @Serial +abstract class AbstractMessageProxy> + implements Message.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; - private T target; - private long sequence; + private C message; protected AbstractMessageProxy() { // For Externalizable } AbstractMessageProxy(final @NonNull C message) { - this.target = message.getTarget(); - this.sequence = message.getSequence(); + this.message = requireNonNull(message); } @Override - public void writeExternal(final ObjectOutput out) throws IOException { - target.writeTo(out); - WritableObjects.writeLong(out, sequence); + public final C message() { + return verifyNotNull(message); } @Override - public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { - target = verifyNotNull(readTarget(in)); - sequence = WritableObjects.readLong(in); + public final void setMessage(final C message) { + this.message = requireNonNull(message); } - @Serial - protected final Object readResolve() { - return verifyNotNull(createMessage(target, sequence)); + @Override + public final Object readResolve() { + return message(); } - - protected abstract @NonNull T readTarget(@NonNull DataInput in) throws IOException; - - abstract @NonNull C createMessage(@NonNull T msgTarget, long msgSequence); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractRequestFailureProxy.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractRequestFailureProxy.java index e715c94f01..8089856ed2 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractRequestFailureProxy.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractRequestFailureProxy.java @@ -7,10 +7,6 @@ */ package org.opendaylight.controller.cluster.access.concepts; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Serial; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.concepts.WritableIdentifier; @@ -20,38 +16,15 @@ import org.opendaylight.yangtools.concepts.WritableIdentifier; * @param Target identifier type */ public abstract class AbstractRequestFailureProxy> - extends AbstractResponseProxy { - @Serial + extends AbstractResponseProxy implements RequestFailure.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; - private RequestException cause; - protected AbstractRequestFailureProxy() { // For Externalizable } protected AbstractRequestFailureProxy(final @NonNull C failure) { super(failure); - this.cause = failure.getCause(); - } - - @Override - public void writeExternal(final ObjectOutput out) throws IOException { - super.writeExternal(out); - out.writeObject(cause); - } - - @Override - public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { - super.readExternal(in); - cause = (RequestException) in.readObject(); - } - - @Override - final C createResponse(final T target, final long sequence) { - return createFailure(target, sequence, cause); } - - protected abstract @NonNull C createFailure(@NonNull T target, long sequence, - @NonNull RequestException failureCause); -} +} \ No newline at end of file diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractRequestProxy.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractRequestProxy.java index 762c9728d5..3ce1193e40 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractRequestProxy.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractRequestProxy.java @@ -7,13 +7,6 @@ */ package org.opendaylight.controller.cluster.access.concepts; -import akka.actor.ActorRef; -import akka.serialization.JavaSerializer; -import akka.serialization.Serialization; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Serial; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.concepts.WritableIdentifier; @@ -23,37 +16,15 @@ import org.opendaylight.yangtools.concepts.WritableIdentifier; * @param Target identifier type */ public abstract class AbstractRequestProxy> - extends AbstractMessageProxy { - @Serial + extends AbstractMessageProxy implements Request.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; - private ActorRef replyTo; - protected AbstractRequestProxy() { // For Externalizable } protected AbstractRequestProxy(final @NonNull C request) { super(request); - this.replyTo = request.getReplyTo(); - } - - @Override - public void writeExternal(final ObjectOutput out) throws IOException { - super.writeExternal(out); - out.writeObject(Serialization.serializedActorPath(replyTo)); - } - - @Override - public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { - super.readExternal(in); - replyTo = JavaSerializer.currentSystem().value().provider().resolveActorRef((String) in.readObject()); - } - - @Override - final C createMessage(final T target, final long sequence) { - return createRequest(target, sequence, replyTo); } - - protected abstract @NonNull C createRequest(@NonNull T target, long sequence, @NonNull ActorRef replyToActor); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractResponseEnvelopeProxy.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractResponseEnvelopeProxy.java index 7c35a3fd53..12bbe79a7b 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractResponseEnvelopeProxy.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractResponseEnvelopeProxy.java @@ -7,44 +7,16 @@ */ package org.opendaylight.controller.cluster.access.concepts; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Serial; -import org.opendaylight.yangtools.concepts.WritableObjects; - -abstract class AbstractResponseEnvelopeProxy> extends AbstractEnvelopeProxy { - @Serial +abstract class AbstractResponseEnvelopeProxy, E extends ResponseEnvelope> + extends AbstractEnvelopeProxy { + @java.io.Serial private static final long serialVersionUID = 1L; - private long executionTimeNanos; - AbstractResponseEnvelopeProxy() { // for Externalizable } - AbstractResponseEnvelopeProxy(final ResponseEnvelope envelope) { + AbstractResponseEnvelopeProxy(final E envelope) { super(envelope); - this.executionTimeNanos = envelope.getExecutionTimeNanos(); } - - @Override - public final void writeExternal(final ObjectOutput out) throws IOException { - super.writeExternal(out); - WritableObjects.writeLong(out, executionTimeNanos); - } - - @Override - public final void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { - super.readExternal(in); - executionTimeNanos = WritableObjects.readLong(in); - } - - @Override - final ResponseEnvelope createEnvelope(final T message, final long sessionId, final long txSequence) { - return createEnvelope(message, sessionId, txSequence, executionTimeNanos); - } - - @SuppressWarnings("checkstyle:hiddenField") - abstract ResponseEnvelope createEnvelope(T message, long sessionId, long txSequence, long executionTimeNanos); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractResponseProxy.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractResponseProxy.java index 818410dbb3..4e9f81e0cd 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractResponseProxy.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/AbstractResponseProxy.java @@ -7,7 +7,6 @@ */ package org.opendaylight.controller.cluster.access.concepts; -import java.io.Serial; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.concepts.WritableIdentifier; @@ -21,7 +20,7 @@ import org.opendaylight.yangtools.concepts.WritableIdentifier; */ abstract class AbstractResponseProxy> extends AbstractMessageProxy { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; protected AbstractResponseProxy() { @@ -31,11 +30,4 @@ abstract class AbstractResponseProxy> extends AbstractResponseProxy { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; protected AbstractSuccessProxy() { @@ -28,11 +27,4 @@ public abstract class AbstractSuccessProxy> implements Immutable, Serializable { - @Serial + interface SerialForm, E extends Envelope> extends Externalizable { + + @NonNull E envelope(); + + void setEnvelope(@NonNull E envelope); + + @java.io.Serial + Object readResolve(); + + @Override + default void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { + final byte header = WritableObjects.readLongHeader(in); + final var sessionId = WritableObjects.readFirstLong(in, header); + final var txSequence = WritableObjects.readSecondLong(in, header); + @SuppressWarnings("unchecked") + final var message = (T) in.readObject(); + setEnvelope(readExternal(in, sessionId, txSequence, message)); + } + + E readExternal(ObjectInput in, long sessionId, long txSequence, T message) throws IOException; + + @Override + default void writeExternal(final ObjectOutput out) throws IOException { + writeExternal(out, envelope()); + } + + default void writeExternal(final ObjectOutput out, final @NonNull E envelope) throws IOException { + WritableObjects.writeLongs(out, envelope.getSessionId(), envelope.getTxSequence()); + out.writeObject(envelope.getMessage()); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; private final @NonNull T message; @@ -62,10 +99,12 @@ public abstract class Envelope> implements Immutable, Se .add("txSequence", Long.toHexString(txSequence)).add("message", message).toString(); } - @Serial + @java.io.Serial final Object writeReplace() { - return createProxy(); + return ABIVersion.MAGNESIUM.lt(message.getVersion()) ? createProxy() : legacyProxy(); } - abstract AbstractEnvelopeProxy createProxy(); + abstract @NonNull SerialForm createProxy(); + + abstract @NonNull AbstractEnvelopeProxy legacyProxy(); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FE.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FE.java new file mode 100644 index 0000000000..e80a38dad9 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FE.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.concepts; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Serialization proxy for {@link FailureEnvelope}. + */ +final class FE implements FailureEnvelope.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private FailureEnvelope envelope; + + @SuppressWarnings("checkstyle:RedundantModifier") + public FE() { + // for Externalizable + } + + FE(final FailureEnvelope envelope) { + this.envelope = requireNonNull(envelope); + } + + @Override + public FailureEnvelope envelope() { + return verifyNotNull(envelope); + } + + @Override + public void setEnvelope(final FailureEnvelope envelope) { + this.envelope = requireNonNull(envelope); + } + + @Override + public Object readResolve() { + return envelope(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FI.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FI.java new file mode 100644 index 0000000000..4640c3fa13 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FI.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.concepts; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Serialization proxy for {@link FrontendIdentifier}. + */ +final class FI implements FrontendIdentifier.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private FrontendIdentifier identifier; + + @SuppressWarnings("checkstyle:RedundantModifier") + public FI() { + // for Externalizable + } + + FI(final FrontendIdentifier identifier) { + this.identifier = requireNonNull(identifier); + } + + @Override + public FrontendIdentifier identifier() { + return verifyNotNull(identifier); + } + + @Override + public void setIdentifier(final FrontendIdentifier identifier) { + this.identifier = requireNonNull(identifier); + } + + @Override + public Object readResolve() { + return identifier(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FT.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FT.java new file mode 100644 index 0000000000..60c45fefc6 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FT.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.concepts; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Serialization proxy for {@link FrontendType}. + */ +final class FT implements FrontendType.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private FrontendType type; + + @SuppressWarnings("checkstyle:RedundantModifier") + public FT() { + // for Externalizable + } + + FT(final FrontendType type) { + this.type = requireNonNull(type); + } + + @Override + public FrontendType type() { + return verifyNotNull(type); + } + + @Override + public void setType(final FrontendType type) { + this.type = requireNonNull(type); + } + + @Override + public Object readResolve() { + return type(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FailureEnvelope.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FailureEnvelope.java index c2daa74203..4de13ac8f8 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FailureEnvelope.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FailureEnvelope.java @@ -7,10 +7,18 @@ */ package org.opendaylight.controller.cluster.access.concepts; -import java.io.Serial; +import java.io.ObjectInput; public final class FailureEnvelope extends ResponseEnvelope> { - @Serial + interface SerialForm extends ResponseEnvelope.SerialForm, FailureEnvelope> { + @Override + default FailureEnvelope readExternal(final ObjectInput in, final long sessionId, final long txSequence, + final RequestFailure message, final long executionTimeNanos) { + return new FailureEnvelope(message, sessionId, txSequence, executionTimeNanos); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; public FailureEnvelope(final RequestFailure message, final long sessionId, final long txSequence, @@ -19,7 +27,12 @@ public final class FailureEnvelope extends ResponseEnvelope } @Override - FailureEnvelopeProxy createProxy() { + FE createProxy() { + return new FE(this); + } + + @Override + FailureEnvelopeProxy legacyProxy() { return new FailureEnvelopeProxy(this); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FailureEnvelopeProxy.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FailureEnvelopeProxy.java index 65c2f43b7e..98ae8be089 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FailureEnvelopeProxy.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FailureEnvelopeProxy.java @@ -7,10 +7,9 @@ */ package org.opendaylight.controller.cluster.access.concepts; -import java.io.Serial; - -final class FailureEnvelopeProxy extends AbstractResponseEnvelopeProxy> { - @Serial +final class FailureEnvelopeProxy extends AbstractResponseEnvelopeProxy, FailureEnvelope> + implements FailureEnvelope.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to be @@ -23,10 +22,4 @@ final class FailureEnvelopeProxy extends AbstractResponseEnvelopeProxy> createEnvelope(final RequestFailure message, final long sessionId, - final long txSequence, final long executionTimeNanos) { - return new FailureEnvelope(message, sessionId, txSequence, executionTimeNanos); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FrontendIdentifier.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FrontendIdentifier.java index 5afaa115b0..933aa16c79 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FrontendIdentifier.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FrontendIdentifier.java @@ -7,6 +7,7 @@ */ package org.opendaylight.controller.cluster.access.concepts; +import static com.google.common.base.Verify.verifyNotNull; import static java.util.Objects.requireNonNull; import java.io.DataInput; @@ -15,7 +16,6 @@ import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; -import java.io.Serial; import java.util.Objects; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.concepts.WritableIdentifier; @@ -24,12 +24,32 @@ import org.opendaylight.yangtools.concepts.WritableIdentifier; * A cluster-wide unique identifier of a frontend type located at a cluster member. */ public final class FrontendIdentifier implements WritableIdentifier { - private static final class Proxy implements Externalizable { - @Serial + interface SerialForm extends Externalizable { + @NonNull FrontendIdentifier identifier(); + + void setIdentifier(@NonNull FrontendIdentifier identifier); + + @java.io.Serial + Object readResolve(); + + @Override + default void writeExternal(final ObjectOutput out) throws IOException { + final var id = identifier(); + id.memberName.writeTo(out); + id.clientType.writeTo(out); + } + + @Override + default void readExternal(final ObjectInput in) throws IOException { + setIdentifier(new FrontendIdentifier(MemberName.readFrom(in), FrontendType.readFrom(in))); + } + } + + private static final class Proxy implements SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; - private MemberName memberName; - private FrontendType clientType; + private FrontendIdentifier identifier; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to // be able to create instances via reflection. @@ -38,30 +58,27 @@ public final class FrontendIdentifier implements WritableIdentifier { // Needed for Externalizable } - Proxy(final MemberName memberName, final FrontendType clientType) { - this.memberName = requireNonNull(memberName); - this.clientType = requireNonNull(clientType); + Proxy(final FrontendIdentifier identifier) { + this.identifier = requireNonNull(identifier); } @Override - public void writeExternal(final ObjectOutput out) throws IOException { - memberName.writeTo(out); - clientType.writeTo(out); + public FrontendIdentifier identifier() { + return verifyNotNull(identifier); } @Override - public void readExternal(final ObjectInput in) throws IOException { - memberName = MemberName.readFrom(in); - clientType = FrontendType.readFrom(in); + public void setIdentifier(final FrontendIdentifier identifier) { + this.identifier = requireNonNull(identifier); } - @Serial - private Object readResolve() { - return new FrontendIdentifier(memberName, clientType); + @Override + public Object readResolve() { + return identifier(); } } - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; private final MemberName memberName; @@ -116,8 +133,8 @@ public final class FrontendIdentifier implements WritableIdentifier { return toPersistentId(); } - @Serial + @java.io.Serial private Object writeReplace() { - return new Proxy(memberName, clientType); + return new Proxy(this); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FrontendType.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FrontendType.java index b36cbbe403..3a25df7dc4 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FrontendType.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FrontendType.java @@ -20,7 +20,6 @@ import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; -import java.io.Serial; import java.nio.charset.StandardCharsets; import java.util.regex.Pattern; import org.eclipse.jdt.annotation.NonNull; @@ -33,11 +32,35 @@ import org.opendaylight.yangtools.concepts.WritableIdentifier; * discerned. */ public final class FrontendType implements Comparable, WritableIdentifier { - private static final class Proxy implements Externalizable { - @Serial + interface SerialForm extends Externalizable { + @NonNull FrontendType type(); + + void setType(@NonNull FrontendType type); + + @java.io.Serial + Object readResolve(); + + @Override + default void writeExternal(final ObjectOutput out) throws IOException { + final var serialized = type().getSerialized(); + out.writeInt(serialized.length); + out.write(serialized); + } + + @Override + default void readExternal(final ObjectInput in) throws IOException { + final var serialized = new byte[in.readInt()]; + in.readFully(serialized); + // TODO: consider caching instances here + setType(new FrontendType(new String(serialized, StandardCharsets.UTF_8), serialized)); + } + } + + private static final class Proxy implements SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; - private byte[] serialized; + private FrontendType type; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to // be able to create instances via reflection. @@ -46,33 +69,30 @@ public final class FrontendType implements Comparable, WritableIde // For Externalizable } - Proxy(final byte[] serialized) { - this.serialized = requireNonNull(serialized); + Proxy(final FrontendType type) { + this.type = requireNonNull(type); } @Override - public void writeExternal(final ObjectOutput out) throws IOException { - out.writeInt(serialized.length); - out.write(serialized); + public FrontendType type() { + return verifyNotNull(type); } @Override - public void readExternal(final ObjectInput in) throws IOException { - serialized = new byte[in.readInt()]; - in.readFully(serialized); + public void setType(final FrontendType type) { + this.type = requireNonNull(type); } - @Serial - private Object readResolve() { - // TODO: consider caching instances here - return new FrontendType(new String(serialized, StandardCharsets.UTF_8), serialized); + @Override + public Object readResolve() { + return type(); } } + @java.io.Serial + private static final long serialVersionUID = 1L; private static final String SIMPLE_STRING_REGEX = "^[a-zA-Z0-9-_.*+:=,!~';]+$"; private static final Pattern SIMPLE_STRING_PATTERN = Pattern.compile(SIMPLE_STRING_REGEX); - @Serial - private static final long serialVersionUID = 1L; private final @NonNull String name; @@ -158,8 +178,8 @@ public final class FrontendType implements Comparable, WritableIde return local; } - @Serial + @java.io.Serial Object writeReplace() { - return new Proxy(getSerialized()); + return new Proxy(this); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/HI.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/HI.java new file mode 100644 index 0000000000..a0d4795ac6 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/HI.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.concepts; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Serialization proxy for {@link LocalHistoryIdentifier}. + */ +final class HI implements LocalHistoryIdentifier.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private LocalHistoryIdentifier identifier; + + @SuppressWarnings("checkstyle:RedundantModifier") + public HI() { + // for Externalizable + } + + HI(final LocalHistoryIdentifier identifier) { + this.identifier = requireNonNull(identifier); + } + + @Override + public LocalHistoryIdentifier identifier() { + return verifyNotNull(identifier); + } + + @Override + public void setIdentifier(final LocalHistoryIdentifier identifier) { + this.identifier = requireNonNull(identifier); + } + + @Override + public Object readResolve() { + return identifier(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/LocalHistoryIdentifier.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/LocalHistoryIdentifier.java index e6050e76c5..0e70edc76f 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/LocalHistoryIdentifier.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/LocalHistoryIdentifier.java @@ -7,6 +7,7 @@ */ package org.opendaylight.controller.cluster.access.concepts; +import static com.google.common.base.Verify.verifyNotNull; import static java.util.Objects.requireNonNull; import com.google.common.base.MoreObjects; @@ -16,7 +17,6 @@ import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; -import java.io.Serial; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.concepts.WritableIdentifier; import org.opendaylight.yangtools.concepts.WritableObjects; @@ -28,22 +28,47 @@ import org.opendaylight.yangtools.concepts.WritableObjects; * - an unsigned long cookie, assigned by the client and meaningless on the backend, which just reflects it back */ public final class LocalHistoryIdentifier implements WritableIdentifier { - /* - * Implementation note: cookie is currently required only for module-based sharding, which is implemented as part - * of normal DataBroker interfaces. For DOMDataTreeProducer cookie will always be zero, hence - * we may end up not needing cookie at all. + /** + * Serialized form of {@link LocalHistoryIdentifier}. * - * We use WritableObjects.writeLongs() to output historyId and cookie (in that order). If we - * end up not needing the cookie at all, we can switch to writeLong() and use zero flags for - * compatibility. + * @implNote + * cookie is currently required only for module-based sharding, which is implemented as part of normal + * DataBroker interfaces. For DOMDataTreeProducer cookie will always be zero, hence we may end up not needing + * cookie at all. + * We use WritableObjects.writeLongs() to output historyId and cookie (in that order). If we end up not needing + * the cookie at all, we can switch to writeLong() and use zero flags for compatibility. */ - private static final class Proxy implements Externalizable { - @Serial + interface SerialForm extends Externalizable { + @NonNull LocalHistoryIdentifier identifier(); + + void setIdentifier(@NonNull LocalHistoryIdentifier identifier); + + @java.io.Serial + Object readResolve(); + + @Override + default void writeExternal(final ObjectOutput out) throws IOException { + final var id = identifier(); + id.getClientId().writeTo(out); + WritableObjects.writeLongs(out, id.getHistoryId(), id.getCookie()); + } + + @Override + default void readExternal(final ObjectInput in) throws IOException { + final var clientId = ClientIdentifier.readFrom(in); + + final byte header = WritableObjects.readLongHeader(in); + final var historyId = WritableObjects.readFirstLong(in, header); + final var cookie = WritableObjects.readSecondLong(in, header); + setIdentifier(new LocalHistoryIdentifier(clientId, historyId, cookie)); + } + } + + private static final class Proxy implements SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; - private ClientIdentifier clientId; - private long historyId; - private long cookie; + private LocalHistoryIdentifier identifier; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to // be able to create instances via reflection. @@ -52,34 +77,27 @@ public final class LocalHistoryIdentifier implements WritableIdentifier { // For Externalizable } - Proxy(final ClientIdentifier frontendId, final long historyId, final long cookie) { - clientId = requireNonNull(frontendId); - this.historyId = historyId; - this.cookie = cookie; + Proxy(final LocalHistoryIdentifier identifier) { + this.identifier = requireNonNull(identifier); } @Override - public void writeExternal(final ObjectOutput out) throws IOException { - clientId.writeTo(out); - WritableObjects.writeLongs(out, historyId, cookie); + public LocalHistoryIdentifier identifier() { + return verifyNotNull(identifier); } @Override - public void readExternal(final ObjectInput in) throws IOException { - clientId = ClientIdentifier.readFrom(in); - - final byte header = WritableObjects.readLongHeader(in); - historyId = WritableObjects.readFirstLong(in, header); - cookie = WritableObjects.readSecondLong(in, header); + public void setIdentifier(final LocalHistoryIdentifier identifier) { + this.identifier = requireNonNull(identifier); } - @Serial - private Object readResolve() { - return new LocalHistoryIdentifier(clientId, historyId, cookie); + @Override + public Object readResolve() { + return identifier(); } } - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; private final @NonNull ClientIdentifier clientId; @@ -149,8 +167,8 @@ public final class LocalHistoryIdentifier implements WritableIdentifier { .add("cookie", Long.toUnsignedString(cookie, 16)).toString(); } - @Serial + @java.io.Serial private Object writeReplace() { - return new Proxy(clientId, historyId, cookie); + return new Proxy(this); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/MN.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/MN.java new file mode 100644 index 0000000000..83ef1e59ba --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/MN.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.concepts; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Serialization proxy for {@link MemberName}. + */ +final class MN implements MemberName.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private MemberName name; + + @SuppressWarnings("checkstyle:RedundantModifier") + public MN() { + // for Externalizable + } + + MN(final MemberName name) { + this.name = requireNonNull(name); + } + + @Override + public MemberName name() { + return verifyNotNull(name); + } + + @Override + public void setName(final MemberName name) { + this.name = requireNonNull(name); + } + + @Override + public Object readResolve() { + return name(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/MemberName.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/MemberName.java index f26df83183..41a9136075 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/MemberName.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/MemberName.java @@ -20,7 +20,6 @@ import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; -import java.io.Serial; import java.nio.charset.StandardCharsets; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.concepts.WritableIdentifier; @@ -29,11 +28,35 @@ import org.opendaylight.yangtools.concepts.WritableIdentifier; * Type-safe encapsulation of a cluster member name. */ public final class MemberName implements Comparable, WritableIdentifier { - private static final class Proxy implements Externalizable { - @Serial + interface SerialForm extends Externalizable { + @NonNull MemberName name(); + + void setName(@NonNull MemberName name); + + @java.io.Serial + Object readResolve(); + + @Override + default void writeExternal(final ObjectOutput out) throws IOException { + final var serialized = name().getSerialized(); + out.writeInt(serialized.length); + out.write(serialized); + } + + @Override + default void readExternal(final ObjectInput in) throws IOException { + final var serialized = new byte[in.readInt()]; + in.readFully(serialized); + // TODO: consider caching instances here + setName(new MemberName(new String(serialized, StandardCharsets.UTF_8), serialized)); + } + } + + private static final class Proxy implements SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; - private byte[] serialized; + private MemberName name; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to // be able to create instances via reflection. @@ -42,30 +65,27 @@ public final class MemberName implements Comparable, WritableIdentif // For Externalizable } - Proxy(final byte[] serialized) { - this.serialized = requireNonNull(serialized); + Proxy(final MemberName name) { + this.name = requireNonNull(name); } @Override - public void writeExternal(final ObjectOutput out) throws IOException { - out.writeInt(serialized.length); - out.write(serialized); + public MemberName name() { + return verifyNotNull(name); } @Override - public void readExternal(final ObjectInput in) throws IOException { - serialized = new byte[in.readInt()]; - in.readFully(serialized); + public void setName(final MemberName name) { + this.name = requireNonNull(name); } - @Serial - private Object readResolve() { - // TODO: consider caching instances here - return new MemberName(new String(serialized, StandardCharsets.UTF_8), serialized); + @Override + public Object readResolve() { + return name(); } } - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; private final @NonNull String name; @@ -141,8 +161,8 @@ public final class MemberName implements Comparable, WritableIdentif return local; } - @Serial + @java.io.Serial Object writeReplace() { - return new Proxy(getSerialized()); + return new Proxy(this); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/Message.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/Message.java index 6ee547fc93..86c91ef955 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/Message.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/Message.java @@ -13,12 +13,17 @@ import static java.util.Objects.requireNonNull; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects.ToStringHelper; -import java.io.Serial; +import java.io.DataInput; +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import java.io.Serializable; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.yangtools.concepts.Immutable; import org.opendaylight.yangtools.concepts.WritableIdentifier; +import org.opendaylight.yangtools.concepts.WritableObjects; /** * An abstract concept of a Message. This class cannot be instantiated directly, use its specializations {@link Request} @@ -50,9 +55,46 @@ import org.opendaylight.yangtools.concepts.WritableIdentifier; * @param Target identifier type * @param Message type */ -public abstract class Message> implements Immutable, - Serializable { - @Serial +public abstract class Message> + implements Immutable, Serializable { + /** + * Externalizable proxy for use with {@link Message} subclasses. + * + * @param Target identifier type + * @param Message class + */ + protected interface SerialForm> extends Externalizable { + + @NonNull C message(); + + void setMessage(@NonNull C message); + + @Override + default void writeExternal(final ObjectOutput out) throws IOException { + final var message = message(); + message.getTarget().writeTo(out); + WritableObjects.writeLong(out, message.getSequence()); + writeExternal(out, message); + } + + void writeExternal(@NonNull ObjectOutput out, @NonNull C msg) throws IOException; + + @Override + default void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { + final var target = verifyNotNull(readTarget(in)); + final var sequence = WritableObjects.readLong(in); + setMessage(verifyNotNull(readExternal(in, target, sequence))); + } + + @NonNull C readExternal(@NonNull ObjectInput in, @NonNull T target, long sequence) + throws IOException, ClassNotFoundException; + + Object readResolve(); + + @NonNull T readTarget(@NonNull DataInput in) throws IOException; + } + + @java.io.Serial private static final long serialVersionUID = 1L; private final @NonNull ABIVersion version; @@ -150,9 +192,9 @@ public abstract class Message externalizableProxy(@NonNull ABIVersion reqVersion); + protected abstract @NonNull SerialForm externalizableProxy(@NonNull ABIVersion reqVersion); - @Serial + @java.io.Serial protected final Object writeReplace() { return externalizableProxy(version); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RE.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RE.java new file mode 100644 index 0000000000..455e00e558 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RE.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.concepts; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Serialization proxy for {@link RequestEnvelope}. + */ +final class RE implements RequestEnvelope.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private RequestEnvelope envelope; + + @SuppressWarnings("checkstyle:RedundantModifier") + public RE() { + // for Externalizable + } + + RE(final RequestEnvelope envelope) { + this.envelope = requireNonNull(envelope); + } + + @Override + public RequestEnvelope envelope() { + return verifyNotNull(envelope); + } + + @Override + public void setEnvelope(final RequestEnvelope envelope) { + this.envelope = requireNonNull(envelope); + } + + @Override + public Object readResolve() { + return envelope(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/Request.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/Request.java index d39617cf77..97ce498bda 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/Request.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/Request.java @@ -10,8 +10,12 @@ package org.opendaylight.controller.cluster.access.concepts; import static java.util.Objects.requireNonNull; import akka.actor.ActorRef; +import akka.serialization.JavaSerializer; +import akka.serialization.Serialization; import com.google.common.base.MoreObjects.ToStringHelper; -import java.io.Serial; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.yangtools.concepts.WritableIdentifier; @@ -24,7 +28,25 @@ import org.opendaylight.yangtools.concepts.WritableIdentifier; * @param Message type */ public abstract class Request> extends Message { - @Serial + protected interface SerialForm> + extends Message.SerialForm { + @Override + default C readExternal(final ObjectInput in, final T target, final long sequence) + throws ClassNotFoundException, IOException { + return readExternal(in, target, sequence, + JavaSerializer.currentSystem().value().provider().resolveActorRef((String) in.readObject())); + } + + @NonNull C readExternal(@NonNull ObjectInput in, @NonNull T target, long sequence, @NonNull ActorRef replyTo) + throws IOException; + + @Override + default void writeExternal(final ObjectOutput out, final C msg) throws IOException { + out.writeObject(Serialization.serializedActorPath(msg.getReplyTo())); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; private final @NonNull ActorRef replyTo; @@ -62,5 +84,5 @@ public abstract class Request externalizableProxy(ABIVersion version); + protected abstract SerialForm externalizableProxy(ABIVersion version); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestEnvelope.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestEnvelope.java index 4dac0b0330..5648846fd9 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestEnvelope.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestEnvelope.java @@ -8,10 +8,18 @@ package org.opendaylight.controller.cluster.access.concepts; import akka.actor.ActorRef; -import java.io.Serial; +import java.io.ObjectInput; public final class RequestEnvelope extends Envelope> { - @Serial + interface SerialForm extends Envelope.SerialForm, RequestEnvelope> { + @Override + default RequestEnvelope readExternal(final ObjectInput in, final long sessionId, final long txSequence, + final Request message) { + return new RequestEnvelope(message, sessionId, txSequence); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; public RequestEnvelope(final Request message, final long sessionId, final long txSequence) { @@ -19,7 +27,12 @@ public final class RequestEnvelope extends Envelope> { } @Override - RequestEnvelopeProxy createProxy() { + RE createProxy() { + return new RE(this); + } + + @Override + RequestEnvelopeProxy legacyProxy() { return new RequestEnvelopeProxy(this); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestEnvelopeProxy.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestEnvelopeProxy.java index 21b99807af..ce9b1f72fe 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestEnvelopeProxy.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestEnvelopeProxy.java @@ -7,10 +7,9 @@ */ package org.opendaylight.controller.cluster.access.concepts; -import java.io.Serial; - -final class RequestEnvelopeProxy extends AbstractEnvelopeProxy> { - @Serial +final class RequestEnvelopeProxy extends AbstractEnvelopeProxy, RequestEnvelope> + implements RequestEnvelope.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -23,9 +22,4 @@ final class RequestEnvelopeProxy extends AbstractEnvelopeProxy> { RequestEnvelopeProxy(final RequestEnvelope envelope) { super(envelope); } - - @Override - RequestEnvelope createEnvelope(final Request message, final long sessionId, final long txSequence) { - return new RequestEnvelope(message, sessionId, txSequence); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestException.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestException.java index 41bfd13dd2..d1120c61ef 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestException.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestException.java @@ -9,14 +9,13 @@ package org.opendaylight.controller.cluster.access.concepts; import static java.util.Objects.requireNonNull; -import java.io.Serial; import org.eclipse.jdt.annotation.NonNull; /** * A failure cause behind a {@link RequestFailure} to process a {@link Request}. */ public abstract class RequestException extends Exception { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; protected RequestException(final @NonNull String message) { diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestFailure.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestFailure.java index c30269f63e..7204912669 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestFailure.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestFailure.java @@ -10,7 +10,9 @@ package org.opendaylight.controller.cluster.access.concepts; import static java.util.Objects.requireNonNull; import com.google.common.base.MoreObjects.ToStringHelper; -import java.io.Serial; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.yangtools.concepts.WritableIdentifier; @@ -23,7 +25,28 @@ import org.opendaylight.yangtools.concepts.WritableIdentifier; */ public abstract class RequestFailure> extends Response { - @Serial + /** + * Externalizable proxy for use with {@link RequestFailure} subclasses. + * + * @param Target identifier type + */ + protected interface SerialForm> + extends Message.SerialForm { + @Override + default C readExternal(final ObjectInput in, final T target, final long sequence) + throws IOException, ClassNotFoundException { + return createFailure(target, sequence, (RequestException) in.readObject()); + } + + @Override + default void writeExternal(final ObjectOutput out, final C msg) throws IOException { + out.writeObject(msg.getCause()); + } + + @NonNull C createFailure(@NonNull T target, long sequence, @NonNull RequestException failureCause); + } + + @java.io.Serial private static final long serialVersionUID = 1L; private final @NonNull RequestException cause; @@ -63,5 +86,5 @@ public abstract class RequestFailure externalizableProxy(ABIVersion version); + protected abstract SerialForm externalizableProxy(ABIVersion version); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestSuccess.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestSuccess.java index 7542c4cb36..f7e59ed1e6 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestSuccess.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RequestSuccess.java @@ -7,7 +7,8 @@ */ package org.opendaylight.controller.cluster.access.concepts; -import java.io.Serial; +import java.io.IOException; +import java.io.ObjectOutput; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.yangtools.concepts.WritableIdentifier; @@ -17,19 +18,24 @@ import org.opendaylight.yangtools.concepts.WritableIdentifier; * * @param Target identifier type */ -public abstract class RequestSuccess> extends - Response { - @Serial +public abstract class RequestSuccess> + extends Response { + protected interface SerialForm> + extends Response.SerialForm { + @Override + default void writeExternal(final ObjectOutput out, final C msg) throws IOException { + // Defaults to no-op + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; - protected RequestSuccess(final @NonNull C success, final @NonNull ABIVersion version) { + protected RequestSuccess(final @NonNull C success, final @NonNull ABIVersion version) { super(success, version); } protected RequestSuccess(final @NonNull T target, final long sequence) { super(target, sequence); } - - @Override - protected abstract AbstractSuccessProxy externalizableProxy(ABIVersion version); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/Response.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/Response.java index 7f74e39683..a41fa01db9 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/Response.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/Response.java @@ -7,7 +7,6 @@ */ package org.opendaylight.controller.cluster.access.concepts; -import java.io.Serial; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.access.ABIVersion; import org.opendaylight.yangtools.concepts.WritableIdentifier; @@ -21,7 +20,12 @@ import org.opendaylight.yangtools.concepts.WritableIdentifier; * @param Message type */ public abstract class Response> extends Message { - @Serial + protected interface SerialForm> + extends Message.SerialForm { + + } + + @java.io.Serial private static final long serialVersionUID = 1L; Response(final @NonNull T target, final long sequence) { @@ -31,7 +35,4 @@ public abstract class Response externalizableProxy(ABIVersion version); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/ResponseEnvelope.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/ResponseEnvelope.java index 90fe7beb11..50d1e7434c 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/ResponseEnvelope.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/ResponseEnvelope.java @@ -7,18 +7,39 @@ */ package org.opendaylight.controller.cluster.access.concepts; -import com.google.common.base.Preconditions; -import java.io.Serial; +import static com.google.common.base.Preconditions.checkArgument; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.yangtools.concepts.WritableObjects; public abstract class ResponseEnvelope> extends Envelope { - @Serial + interface SerialForm, E extends ResponseEnvelope> extends Envelope.SerialForm { + @Override + default void writeExternal(final ObjectOutput out, final @NonNull E envelope) throws IOException { + Envelope.SerialForm.super.writeExternal(out, envelope); + WritableObjects.writeLong(out, envelope.getExecutionTimeNanos()); + } + + @Override + default E readExternal(final ObjectInput in, final long sessionId, final long txSequence, final T message) + throws IOException { + return readExternal(in, sessionId, txSequence, message, WritableObjects.readLong(in)); + } + + E readExternal(ObjectInput in, long sessionId, long txSequence, T message, long executionTimeNanos); + } + + @java.io.Serial private static final long serialVersionUID = 1L; private final long executionTimeNanos; ResponseEnvelope(final T message, final long sessionId, final long txSequence, final long executionTimeNanos) { super(message, sessionId, txSequence); - Preconditions.checkArgument(executionTimeNanos >= 0); + checkArgument(executionTimeNanos >= 0, "Negative executionTime"); this.executionTimeNanos = executionTimeNanos; } @@ -31,7 +52,4 @@ public abstract class ResponseEnvelope> extends Envelop public final long getExecutionTimeNanos() { return executionTimeNanos; } - - @Override - abstract AbstractResponseEnvelopeProxy createProxy(); } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RetiredGenerationException.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RetiredGenerationException.java index cc0c6d0e16..3f1f71d17e 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RetiredGenerationException.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RetiredGenerationException.java @@ -7,14 +7,12 @@ */ package org.opendaylight.controller.cluster.access.concepts; -import java.io.Serial; - /** * General error raised when the recipient of a {@link Request} determines that the request contains * a {@link ClientIdentifier} which corresponds to an outdated generation. */ public final class RetiredGenerationException extends RequestException { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; public RetiredGenerationException(final long originatingGeneration, final long newGeneration) { diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RuntimeRequestException.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RuntimeRequestException.java index 713c413e52..3f886a8510 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RuntimeRequestException.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/RuntimeRequestException.java @@ -11,13 +11,12 @@ import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; import com.google.common.base.Strings; -import java.io.Serial; /** * General error raised when the recipient of a {@link Request} fails to process a request. */ public final class RuntimeRequestException extends RequestException { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; public RuntimeRequestException(final String message, final Throwable cause) { diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/SE.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/SE.java new file mode 100644 index 0000000000..59615a474c --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/SE.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.concepts; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +import java.io.ObjectInput; + +/** + * Serialization proxy for {@link SuccessEnvelope}. + */ +final class SE implements SuccessEnvelope.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private SuccessEnvelope envelope; + + @SuppressWarnings("checkstyle:RedundantModifier") + public SE() { + // for Externalizable + } + + SE(final SuccessEnvelope envelope) { + this.envelope = requireNonNull(envelope); + } + + @Override + public SuccessEnvelope envelope() { + return verifyNotNull(envelope); + } + + @Override + public void setEnvelope(final SuccessEnvelope envelope) { + this.envelope = requireNonNull(envelope); + } + + @Override + public SuccessEnvelope readExternal(final ObjectInput in, final long sessionId, final long txSequence, + final RequestSuccess message, final long executionTimeNanos) { + return new SuccessEnvelope(message, sessionId, txSequence, executionTimeNanos); + } + + @Override + public Object readResolve() { + return envelope(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/SuccessEnvelope.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/SuccessEnvelope.java index bf35c4931f..0c6ed7a112 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/SuccessEnvelope.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/SuccessEnvelope.java @@ -7,10 +7,18 @@ */ package org.opendaylight.controller.cluster.access.concepts; -import java.io.Serial; +import java.io.ObjectInput; public final class SuccessEnvelope extends ResponseEnvelope> { - @Serial + interface SerialForm extends ResponseEnvelope.SerialForm, SuccessEnvelope> { + @Override + default SuccessEnvelope readExternal(final ObjectInput in, final long sessionId, final long txSequence, + final RequestSuccess message, final long executionTimeNanos) { + return new SuccessEnvelope(message, sessionId, txSequence, executionTimeNanos); + } + } + + @java.io.Serial private static final long serialVersionUID = 1L; public SuccessEnvelope(final RequestSuccess message, final long sessionId, final long txSequence, @@ -19,7 +27,13 @@ public final class SuccessEnvelope extends ResponseEnvelope } @Override - SuccessEnvelopeProxy createProxy() { + SE createProxy() { + return new SE(this); + } + + @Override + SuccessEnvelopeProxy legacyProxy() { return new SuccessEnvelopeProxy(this); } + } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/SuccessEnvelopeProxy.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/SuccessEnvelopeProxy.java index 76adbb193f..20b46fcb50 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/SuccessEnvelopeProxy.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/SuccessEnvelopeProxy.java @@ -7,10 +7,9 @@ */ package org.opendaylight.controller.cluster.access.concepts; -import java.io.Serial; - -final class SuccessEnvelopeProxy extends AbstractResponseEnvelopeProxy> { - @Serial +final class SuccessEnvelopeProxy extends AbstractResponseEnvelopeProxy, SuccessEnvelope> + implements SuccessEnvelope.SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to @@ -23,10 +22,4 @@ final class SuccessEnvelopeProxy extends AbstractResponseEnvelopeProxy> createEnvelope(final RequestSuccess message, final long sessionId, - final long txSequence, final long executionTimeNanos) { - return new SuccessEnvelope(message, sessionId, txSequence, executionTimeNanos); - } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/TI.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/TI.java new file mode 100644 index 0000000000..653f4fce45 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/TI.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.access.concepts; + +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + +/** + * Serialization proxy for {@link TransactionIdentifier}. + */ +final class TI implements TransactionIdentifier.SerialForm { + @java.io.Serial + private static final long serialVersionUID = 1L; + + private TransactionIdentifier identifier; + + @SuppressWarnings("checkstyle:RedundantModifier") + public TI() { + // for Externalizable + } + + TI(final TransactionIdentifier identifier) { + this.identifier = requireNonNull(identifier); + } + + @Override + public TransactionIdentifier identifier() { + return verifyNotNull(identifier); + } + + @Override + public void setIdentifier(final TransactionIdentifier identifier) { + this.identifier = requireNonNull(identifier); + } + + @Override + public Object readResolve() { + return identifier(); + } +} diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/TransactionIdentifier.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/TransactionIdentifier.java index 29edfe8fda..b03e2cd5c3 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/TransactionIdentifier.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/TransactionIdentifier.java @@ -7,6 +7,7 @@ */ package org.opendaylight.controller.cluster.access.concepts; +import static com.google.common.base.Verify.verifyNotNull; import static java.util.Objects.requireNonNull; import java.io.DataInput; @@ -15,7 +16,6 @@ import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; -import java.io.Serial; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.concepts.WritableIdentifier; import org.opendaylight.yangtools.concepts.WritableObjects; @@ -24,12 +24,32 @@ import org.opendaylight.yangtools.concepts.WritableObjects; * Globally-unique identifier of a transaction. */ public final class TransactionIdentifier implements WritableIdentifier { - private static final class Proxy implements Externalizable { - @Serial + interface SerialForm extends Externalizable { + @NonNull TransactionIdentifier identifier(); + + void setIdentifier(@NonNull TransactionIdentifier identifier); + + @java.io.Serial + Object readResolve(); + + @Override + default void readExternal(final ObjectInput in) throws IOException { + setIdentifier(new TransactionIdentifier(LocalHistoryIdentifier.readFrom(in), WritableObjects.readLong(in))); + } + + @Override + default void writeExternal(final ObjectOutput out) throws IOException { + final var id = identifier(); + id.getHistoryId().writeTo(out); + WritableObjects.writeLong(out, id.getTransactionId()); + } + } + + private static final class Proxy implements SerialForm { + @java.io.Serial private static final long serialVersionUID = 1L; - private LocalHistoryIdentifier historyId; - private long transactionId; + private TransactionIdentifier identifier; // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to // be able to create instances via reflection. @@ -38,30 +58,27 @@ public final class TransactionIdentifier implements WritableIdentifier { // For Externalizable } - Proxy(final LocalHistoryIdentifier historyId, final long transactionId) { - this.historyId = requireNonNull(historyId); - this.transactionId = transactionId; + Proxy(final TransactionIdentifier identifier) { + this.identifier = requireNonNull(identifier); } @Override - public void writeExternal(final ObjectOutput out) throws IOException { - historyId.writeTo(out); - WritableObjects.writeLong(out, transactionId); + public @NonNull TransactionIdentifier identifier() { + return verifyNotNull(identifier); } @Override - public void readExternal(final ObjectInput in) throws IOException { - historyId = LocalHistoryIdentifier.readFrom(in); - transactionId = WritableObjects.readLong(in); + public void setIdentifier(final TransactionIdentifier identifier) { + this.identifier = requireNonNull(identifier); } - @Serial - private Object readResolve() { - return new TransactionIdentifier(historyId, transactionId); + @Override + public Object readResolve() { + return identifier(); } } - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; private final @NonNull LocalHistoryIdentifier historyId; @@ -120,8 +137,8 @@ public final class TransactionIdentifier implements WritableIdentifier { return toShortString(); } - @Serial + @java.io.Serial private Object writeReplace() { - return new Proxy(historyId, transactionId); + return new Proxy(this); } } diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/UnsupportedRequestException.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/UnsupportedRequestException.java index 134a0a94f2..1de266d285 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/UnsupportedRequestException.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/UnsupportedRequestException.java @@ -7,14 +7,12 @@ */ package org.opendaylight.controller.cluster.access.concepts; -import java.io.Serial; - /** * General error raised when the recipient of a {@link Request} determines that it does not know how to handle * the request. */ public final class UnsupportedRequestException extends RequestException { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; public UnsupportedRequestException(final Request request) { diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ConnectClientSuccessTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ConnectClientSuccessTest.java index 82d51e86a7..3f51399aba 100644 --- a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ConnectClientSuccessTest.java +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ConnectClientSuccessTest.java @@ -74,8 +74,13 @@ public class ConnectClientSuccessTest extends AbstractRequestSuccessTest { } private static class MockRequestFailureProxy extends AbstractRequestFailureProxy { - @Serial + @java.io.Serial private static final long serialVersionUID = 5015515628523887221L; @SuppressWarnings("checkstyle:RedundantModifier") @@ -48,19 +47,19 @@ public class FailureEnvelopeTest extends AbstractEnvelopeTest { } @Override - protected MockFailure createFailure(final WritableIdentifier target, final long sequence, - final RequestException failureCause) { + public MockFailure createFailure(final WritableIdentifier target, final long sequence, + final RequestException failureCause) { return new MockFailure(target, failureCause, sequence); } @Override - protected WritableIdentifier readTarget(final DataInput in) throws IOException { + public WritableIdentifier readTarget(final DataInput in) throws IOException { return TransactionIdentifier.readFrom(in); } } private static class MockFailure extends RequestFailure { - @Serial + @java.io.Serial private static final long serialVersionUID = 1L; MockFailure(final WritableIdentifier target, final RequestException cause, final long sequence) { diff --git a/opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/TransmittingTransmitQueueTest.java b/opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/TransmittingTransmitQueueTest.java index b40aefb663..cb8794cdb5 100644 --- a/opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/TransmittingTransmitQueueTest.java +++ b/opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/TransmittingTransmitQueueTest.java @@ -64,7 +64,7 @@ public class TransmittingTransmitQueueTest extends AbstractTransmitQueueTest