Added NettyMessagingService constructor that accepts both ip and port
diff --git a/utils/netty/src/main/java/org/onlab/netty/NettyMessagingService.java b/utils/netty/src/main/java/org/onlab/netty/NettyMessagingService.java
index 2f3e039..5ef1768 100644
--- a/utils/netty/src/main/java/org/onlab/netty/NettyMessagingService.java
+++ b/utils/netty/src/main/java/org/onlab/netty/NettyMessagingService.java
@@ -42,7 +42,6 @@
private final Logger log = LoggerFactory.getLogger(getClass());
- private final int port;
private final Endpoint localEp;
private final ConcurrentMap<String, MessageHandler> handlers = new ConcurrentHashMap<>();
private final Cache<Long, AsyncResponse> responseFutures = CacheBuilder.newBuilder()
@@ -77,6 +76,10 @@
clientChannelClass = NioSocketChannel.class;
}
+ public NettyMessagingService(String ip, int port) {
+ localEp = new Endpoint(ip, port);
+ }
+
public NettyMessagingService() {
// TODO: Default port should be configurable.
this(8080);
@@ -84,7 +87,6 @@
// FIXME: Constructor should not throw exceptions.
public NettyMessagingService(int port) {
- this.port = port;
try {
localEp = new Endpoint(java.net.InetAddress.getLocalHost().getHostName(), port);
} catch (UnknownHostException e) {
@@ -106,6 +108,14 @@
clientGroup.shutdownGracefully();
}
+ /**
+ * Returns the local endpoint for this instance.
+ * @return local end point.
+ */
+ public Endpoint localEp() {
+ return localEp;
+ }
+
@Override
public void sendAsync(Endpoint ep, String type, byte[] payload) throws IOException {
InternalMessage message = new InternalMessage.Builder(this)
@@ -127,7 +137,7 @@
channels.returnObject(ep, channel);
}
} catch (Exception e) {
- throw new IOException(e);
+ throw new IOException("Failed to send message to " + ep.toString(), e);
}
}
@@ -174,7 +184,7 @@
.childOption(ChannelOption.SO_KEEPALIVE, true);
// Bind and start to accept incoming connections.
- b.bind(port).sync();
+ b.bind(localEp.port()).sync();
}
private class OnosCommunicationChannelFactory