Optimize NodeIdentifier reading
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / concepts / MemberName.java
index a6794d0032623dff80e2ef92d1d9e11a9c8c6d2d..09e39e8c582f17a8be1fc72f0e880de137b82972 100644 (file)
@@ -12,6 +12,7 @@ import com.google.common.base.MoreObjects;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import com.google.common.base.Verify;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.Externalizable;
@@ -19,7 +20,7 @@ import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.nio.charset.StandardCharsets;
-import org.opendaylight.yangtools.concepts.Identifier;
+import org.opendaylight.yangtools.concepts.WritableIdentifier;
 
 /**
  * Type-safe encapsulation of a cluster member name.
@@ -27,11 +28,14 @@ import org.opendaylight.yangtools.concepts.Identifier;
  * @author Robert Varga
  */
 @Beta
-public final class MemberName implements Comparable<MemberName>, Identifier, WritableObject {
+public final class MemberName implements Comparable<MemberName>, WritableIdentifier {
     private static final class Proxy implements Externalizable {
         private static final long serialVersionUID = 1L;
         private byte[] serialized;
 
+        // 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() {
             // For Externalizable
         }
@@ -41,13 +45,13 @@ public final class MemberName implements Comparable<MemberName>, Identifier, Wri
         }
 
         @Override
-        public void writeExternal(ObjectOutput out) throws IOException {
+        public void writeExternal(final ObjectOutput out) throws IOException {
             out.writeInt(serialized.length);
             out.write(serialized);
         }
 
         @Override
-        public void readExternal(ObjectInput in) throws IOException {
+        public void readExternal(final ObjectInput in) throws IOException {
             serialized = new byte[in.readInt()];
             in.readFully(serialized);
         }
@@ -60,6 +64,9 @@ public final class MemberName implements Comparable<MemberName>, Identifier, Wri
 
     private static final long serialVersionUID = 1L;
     private final String name;
+
+    @SuppressFBWarnings(value = "VO_VOLATILE_REFERENCE_TO_ARRAY",
+            justification = "The array elements are non-volatile but we don't access them.")
     private volatile byte[] serialized;
 
     private MemberName(final String name) {
@@ -85,9 +92,9 @@ public final class MemberName implements Comparable<MemberName>, Identifier, Wri
 
     @Override
     public void writeTo(final DataOutput out) throws IOException {
-        final byte[] serialized = getSerialized();
-        out.writeInt(serialized.length);
-        out.write(serialized);
+        final byte[] local = getSerialized();
+        out.writeInt(local.length);
+        out.write(local);
     }
 
     public String getName() {
@@ -100,13 +107,13 @@ public final class MemberName implements Comparable<MemberName>, Identifier, Wri
     }
 
     @Override
-    public boolean equals(final Object o) {
-        return this == o || (o instanceof MemberName && name.equals(((MemberName)o).name));
+    public boolean equals(final Object obj) {
+        return this == obj || obj instanceof MemberName && name.equals(((MemberName)obj).name);
     }
 
     @Override
-    public int compareTo(final MemberName o) {
-        return this == o ? 0 : name.compareTo(o.name);
+    public int compareTo(final MemberName obj) {
+        return this == obj ? 0 : name.compareTo(obj.name);
     }
 
     @Override