Implementation for enabling remote rpc calls between 2 instances of md-sal
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / implementation / src / main / java / org / opendaylight / controller / sal / connector / remoterpc / dto / Message.java
@@ -6,10 +6,8 @@
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 
-package org.opendaylight.controller.sal.connector.remoterpc.router.zeromq;
+package org.opendaylight.controller.sal.connector.remoterpc.dto;
 
-
-import org.codehaus.jackson.map.ObjectMapper;
 import org.opendaylight.controller.sal.connector.api.RpcRouter;
 
 import java.io.*;
@@ -20,7 +18,8 @@ public class Message implements Serializable {
     ANNOUNCE((byte) 0),  //TODO: Remove announce, add rpc registration and deregistration
     HEARTBEAT((byte) 1),
     REQUEST((byte) 2),
-    RESPONSE((byte) 3);
+    RESPONSE((byte) 3),
+    ERROR((byte)4);
 
     private final byte type;
 
@@ -35,6 +34,7 @@ public class Message implements Serializable {
 
   private MessageType type;
   private String sender;
+  private String recipient;
   private RpcRouter.RouteIdentifier route;
   private Object payload;
 
@@ -70,11 +70,19 @@ public class Message implements Serializable {
     this.payload = payload;
   }
 
+  public String getRecipient() {
+    return recipient;
+  }
+
+  public void setRecipient(String recipient) {
+    this.recipient = recipient;
+  }
   @Override
   public String toString() {
     return "Message{" +
         "type=" + type +
         ", sender='" + sender + '\'' +
+        ", recipient='" + recipient + '\'' +
         ", route=" + route +
         ", payload=" + payload +
         '}';
@@ -108,17 +116,6 @@ public class Message implements Serializable {
     return o.readObject();
   }
 
-  public static byte[] toJsonBytes(Message m) throws IOException {
-    ObjectMapper o = new ObjectMapper();
-    return o.writeValueAsBytes(m);
-  }
-
-  public static Message fromJsonBytes(byte [] bytes) throws IOException {
-
-    ObjectMapper o = new ObjectMapper();
-    return o.readValue(bytes, Message.class);
-  }
-
   public static class Response extends Message implements RpcRouter.RpcReply {
     private ResponseCode code; // response code
 
@@ -163,6 +160,11 @@ public class Message implements Serializable {
       return this;
     }
 
+    public MessageBuilder recipient(String recipient){
+      message.setRecipient(recipient);
+      return this;
+    }
+
     public MessageBuilder route(RpcRouter.RouteIdentifier route){
       message.setRoute(route);
       return this;