X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fcds-access-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Faccess%2Fconcepts%2FFrontendType.java;fp=opendaylight%2Fmd-sal%2Fcds-access-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Faccess%2Fconcepts%2FFrontendType.java;h=3a25df7dc48447136740fda5624404409863270d;hp=b36cbbe4031c11b1ad8207e3f9a5a0339b78a1bb;hb=d92bd0e575983b3d6a09a73089ef8f9c62f94eaa;hpb=e085f22bb1934959f9d6f7f4368c1afe964b1e07 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); } }