X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fcds-access-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Faccess%2Fconcepts%2FClientIdentifier.java;h=fe178f26e9d25cc0aa29202ce951b5096fd6a3c1;hb=refs%2Fchanges%2F59%2F47459%2F4;hp=b2016d806c4c7d93f8ba12cadc20f2cb75d2349e;hpb=104ce145c9cd637c9b1caecfe0fe02c4ce4f343c;p=controller.git diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/ClientIdentifier.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/ClientIdentifier.java index b2016d806c..fe178f26e9 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/ClientIdentifier.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/ClientIdentifier.java @@ -10,11 +10,14 @@ package org.opendaylight.controller.cluster.access.concepts; import com.google.common.annotations.Beta; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; +import java.io.DataInput; +import java.io.DataOutput; import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; -import org.opendaylight.yangtools.concepts.Identifier; +import org.opendaylight.yangtools.concepts.WritableIdentifier; +import org.opendaylight.yangtools.concepts.WritableObjects; /** * A cluster-wide unique identifier of a frontend instance. This identifier discerns between individual incarnations @@ -23,54 +26,67 @@ import org.opendaylight.yangtools.concepts.Identifier; * @author Robert Varga */ @Beta -public final class ClientIdentifier implements Identifier { - private static final class Proxy implements Externalizable { +public final class ClientIdentifier implements WritableIdentifier { + private static final class Proxy implements Externalizable { private static final long serialVersionUID = 1L; - private FrontendIdentifier frontendId; + private FrontendIdentifier frontendId; private long generation; + // 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") public Proxy() { // Needed for Externalizable } - Proxy(final FrontendIdentifier frontendId, final long generation) { + Proxy(final FrontendIdentifier frontendId, final long generation) { this.frontendId = Preconditions.checkNotNull(frontendId); this.generation = generation; } @Override - public void writeExternal(ObjectOutput out) throws IOException { - out.writeObject(frontendId); - out.writeLong(generation); + public void writeExternal(final ObjectOutput out) throws IOException { + frontendId.writeTo(out); + WritableObjects.writeLong(out, generation); } - @SuppressWarnings("unchecked") @Override - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - frontendId = (FrontendIdentifier) in.readObject(); - generation = in.readLong(); + public void readExternal(final ObjectInput in) throws IOException { + frontendId = FrontendIdentifier.readFrom(in); + generation = WritableObjects.readLong(in); } private Object readResolve() { - return new ClientIdentifier<>(frontendId, generation); + return new ClientIdentifier(frontendId, generation); } } private static final long serialVersionUID = 1L; - private final FrontendIdentifier frontendId; + private final FrontendIdentifier frontendId; private final long generation; - ClientIdentifier(final FrontendIdentifier frontendId, final long generation) { + ClientIdentifier(final FrontendIdentifier frontendId, final long generation) { this.frontendId = Preconditions.checkNotNull(frontendId); this.generation = generation; } - public static ClientIdentifier create(final FrontendIdentifier frontendId, + public static ClientIdentifier create(final FrontendIdentifier frontendId, final long generation) { - return new ClientIdentifier<>(frontendId, generation); + return new ClientIdentifier(frontendId, generation); } - public FrontendIdentifier getFrontendId() { + public static ClientIdentifier readFrom(final DataInput in) throws IOException { + final FrontendIdentifier frontendId = FrontendIdentifier.readFrom(in); + return new ClientIdentifier(frontendId, WritableObjects.readLong(in)); + } + + @Override + public void writeTo(final DataOutput out) throws IOException { + frontendId.writeTo(out); + WritableObjects.writeLong(out, generation); + } + + public FrontendIdentifier getFrontendId() { return frontendId; } @@ -84,15 +100,15 @@ public final class ClientIdentifier implements Identifie } @Override - public boolean equals(final Object o) { - if (this == o) { + public boolean equals(final Object obj) { + if (this == obj) { return true; } - if (!(o instanceof ClientIdentifier)) { + if (!(obj instanceof ClientIdentifier)) { return false; } - final ClientIdentifier other = (ClientIdentifier) o; + final ClientIdentifier other = (ClientIdentifier) obj; return generation == other.generation && frontendId.equals(other.frontendId); } @@ -103,6 +119,6 @@ public final class ClientIdentifier implements Identifie } private Object writeReplace() { - return new Proxy<>(frontendId, generation); + return new Proxy(frontendId, generation); } }