Serialization/Deserialization and a host of other fixes
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / FindPrimary.java
index f2497e6517f376e4d7173efdbd4aeb21596d3990..f584467ee91b37f2b0866cb9a39556eba3c9ace8 100644 (file)
@@ -9,13 +9,14 @@
 package org.opendaylight.controller.cluster.datastore.messages;
 
 import com.google.common.base.Preconditions;
+import org.opendaylight.controller.protobuff.messages.shard.ShardManagerMessages;
 
 /**
  * The FindPrimary message is used to locate the primary of any given shard
  *
- * TODO : Make this serializable
  */
-public class FindPrimary{
+public class FindPrimary implements SerializableMessage{
+  public static final Class SERIALIZABLE_CLASS = ShardManagerMessages.FindPrimary.class;
     private final String shardName;
 
     public FindPrimary(String shardName){
@@ -28,4 +29,13 @@ public class FindPrimary{
     public String getShardName() {
         return shardName;
     }
+
+  @Override
+  public Object toSerializable() {
+    return ShardManagerMessages.FindPrimary.newBuilder().setShardName(shardName).build();
+  }
+
+  public static FindPrimary fromSerializable(Object message){
+    return new FindPrimary(((ShardManagerMessages.FindPrimary)message).getShardName());
+  }
 }