Bug 2265: Address comments from 12448 10/14510/1
authortpantelis <tpanteli@brocade.com>
Wed, 21 Jan 2015 22:44:19 +0000 (17:44 -0500)
committertpantelis <tpanteli@brocade.com>
Wed, 21 Jan 2015 22:44:19 +0000 (17:44 -0500)
Address comments from https://git.opendaylight.org/gerrit/#/c/12448/:

- CanCommitTransactionReply: "you could have used a CONSTANT here
YES_SERIALIZED, NO_SERIALIZED. Or even completely eliminating the
serializedMessage field"

- MergeData: "We could have use SERIALIZABLE_CLASS.isInstance(message)
here and in lot of other places where we are checking the message
type with equals now."

Change-Id: I8248fb739b45a9ad4795b355f3b4ef9291e99791
Signed-off-by: tpantelis <tpanteli@brocade.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CanCommitTransactionReply.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/MergeData.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/WriteData.java

index 7db4846ef4ff69c4c318ab459a07cc09b7943a47..7e8cd436d2ce0133d612eaa0ec2ad31ec57b54c9 100644 (file)
@@ -17,13 +17,16 @@ public class CanCommitTransactionReply implements SerializableMessage {
     public static final CanCommitTransactionReply YES = new CanCommitTransactionReply(true);
     public static final CanCommitTransactionReply NO = new CanCommitTransactionReply(false);
 
+    private static final ThreePhaseCommitCohortMessages.CanCommitTransactionReply YES_SERIALIZED =
+            ThreePhaseCommitCohortMessages.CanCommitTransactionReply.newBuilder().setCanCommit(true).build();
+
+    private static final ThreePhaseCommitCohortMessages.CanCommitTransactionReply NO_SERIALIZED =
+            ThreePhaseCommitCohortMessages.CanCommitTransactionReply.newBuilder().setCanCommit(false).build();
+
     private final boolean canCommit;
-    private final Object serializedMessage;
 
     private CanCommitTransactionReply(final boolean canCommit) {
         this.canCommit = canCommit;
-        this.serializedMessage = ThreePhaseCommitCohortMessages.CanCommitTransactionReply.newBuilder().
-                setCanCommit(canCommit).build();
     }
 
     public boolean getCanCommit() {
@@ -32,7 +35,7 @@ public class CanCommitTransactionReply implements SerializableMessage {
 
     @Override
     public Object toSerializable() {
-        return serializedMessage;
+        return canCommit ? YES_SERIALIZED : NO_SERIALIZED;
     }
 
     public static CanCommitTransactionReply fromSerializable(final Object message) {
index 9234385b3536bfbe8ccaf528075efcdedc1be792..ae0d630cf267aa75b0ef403b8df7e7733d06e082 100644 (file)
@@ -55,7 +55,7 @@ public class MergeData extends ModifyData implements VersionedSerializableMessag
     }
 
     public static boolean isSerializedType(Object message) {
-        return SERIALIZABLE_CLASS.isAssignableFrom(message.getClass()) ||
+        return SERIALIZABLE_CLASS.isInstance(message) ||
                message instanceof ShardTransactionMessages.MergeData;
     }
 }
index c5e3a6b05966c9c30f12c5f6f7dab93a78fbebf7..989949c88fb0f0c5400ea903119435a6d4ed0940 100644 (file)
@@ -55,7 +55,7 @@ public class WriteData extends ModifyData implements VersionedSerializableMessag
     }
 
     public static boolean isSerializedType(Object message) {
-        return SERIALIZABLE_CLASS.isAssignableFrom(message.getClass()) ||
+        return SERIALIZABLE_CLASS.isInstance(message) ||
                message instanceof ShardTransactionMessages.WriteData;
     }
 }