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 / SocketPair.java
diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/SocketPair.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/SocketPair.java
new file mode 100644 (file)
index 0000000..67b3a83
--- /dev/null
@@ -0,0 +1,41 @@
+package org.opendaylight.controller.sal.connector.remoterpc;
+
+import org.zeromq.ZMQ;
+
+import java.util.UUID;
+
+/**
+ *
+ */
+public class SocketPair implements AutoCloseable{
+  private ZMQ.Socket sender;
+  private ZMQ.Socket receiver;
+
+  private static final String INPROC_PREFIX = "inproc://";
+
+  public SocketPair(){
+    String address = new StringBuilder(INPROC_PREFIX)
+                         .append(UUID.randomUUID())
+                         .toString();
+
+    receiver = Context.getInstance().getZmqContext().socket(ZMQ.PAIR);
+    receiver.bind(address);
+
+    sender = Context.getInstance().getZmqContext().socket(ZMQ.PAIR);
+    sender.connect(address);
+  }
+
+  public ZMQ.Socket getSender(){
+    return this.sender;
+  }
+
+  public ZMQ.Socket getReceiver(){
+    return this.receiver;
+  }
+
+  @Override
+  public void close() throws Exception {
+    sender.close();
+    receiver.close();
+  }
+}