Added ability to measure round-trip latency and to assure message integrity.
diff --git a/utils/nio/src/main/java/org/onlab/nio/IOLoop.java b/utils/nio/src/main/java/org/onlab/nio/IOLoop.java
index 1309330..38c9cf6 100644
--- a/utils/nio/src/main/java/org/onlab/nio/IOLoop.java
+++ b/utils/nio/src/main/java/org/onlab/nio/IOLoop.java
@@ -54,6 +54,15 @@
}
/**
+ * Returns the number of streams in custody of the IO loop.
+ *
+ * @return number of message streams using this loop
+ */
+ public int streamCount() {
+ return streams.size();
+ }
+
+ /**
* Creates a new message stream backed by the specified socket channel.
*
* @param byteChannel backing byte channel
@@ -182,9 +191,10 @@
* with a pending accept operation.
*
* @param channel backing socket channel
+ * @return newly accepted message stream
*/
- public void acceptStream(SocketChannel channel) {
- createAndAdmit(channel, SelectionKey.OP_READ);
+ public S acceptStream(SocketChannel channel) {
+ return createAndAdmit(channel, SelectionKey.OP_READ);
}
@@ -193,9 +203,10 @@
* with a pending connect operation.
*
* @param channel backing socket channel
+ * @return newly connected message stream
*/
- public void connectStream(SocketChannel channel) {
- createAndAdmit(channel, SelectionKey.OP_CONNECT);
+ public S connectStream(SocketChannel channel) {
+ return createAndAdmit(channel, SelectionKey.OP_CONNECT);
}
/**
@@ -205,12 +216,14 @@
* @param channel socket channel
* @param op pending operations mask to be applied to the selection
* key as a set of initial interestedOps
+ * @return newly created message stream
*/
- private synchronized void createAndAdmit(SocketChannel channel, int op) {
+ private synchronized S createAndAdmit(SocketChannel channel, int op) {
S stream = createStream(channel);
streams.add(stream);
newStreamRequests.add(new NewStreamRequest(stream, channel, op));
selector.wakeup();
+ return stream;
}
/**