Bulk-add copyright headers to java files
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / implementation / src / main / java / org / opendaylight / controller / sal / connector / remoterpc / SocketPair.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.connector.remoterpc;
9
10 import org.zeromq.ZMQ;
11
12 import java.util.UUID;
13
14 /**
15  *
16  */
17 public class SocketPair implements AutoCloseable{
18   private ZMQ.Socket sender;
19   private ZMQ.Socket receiver;
20
21   private static final String INPROC_PREFIX = "inproc://";
22
23   public SocketPair(){
24     String address = new StringBuilder(INPROC_PREFIX)
25                          .append(UUID.randomUUID())
26                          .toString();
27
28     receiver = Context.getInstance().getZmqContext().socket(ZMQ.PAIR);
29     receiver.bind(address);
30
31     sender = Context.getInstance().getZmqContext().socket(ZMQ.PAIR);
32     sender.connect(address);
33   }
34
35   public ZMQ.Socket getSender(){
36     return this.sender;
37   }
38
39   public ZMQ.Socket getReceiver(){
40     return this.receiver;
41   }
42
43   @Override
44   public void close() throws Exception {
45     sender.close();
46     receiver.close();
47   }
48 }