THRIFT-81. java: TNonblockingServer: Support a limit on read buffer size

This change makes it possible to set a maximum amount of memory that
TNonblockingServer will use for all read buffers (combined).
If it is exceeded, no new data will be read from clients until
memory is freed.  The current implementation does a busy wait in
the main thread when this happens.


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@719741 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/test/java/TestNonblockingServer b/test/java/TestNonblockingServer
index cb330d4..ee2ba9d 100644
--- a/test/java/TestNonblockingServer
+++ b/test/java/TestNonblockingServer
@@ -1,2 +1,2 @@
 #!/bin/bash -v
-java -server -cp thrifttest.jar:../../lib/java/libthrift.jar com.facebook.thrift.test.TestNonblockingServer $*
+java -server -Xmx256m -cp thrifttest.jar:../../lib/java/libthrift.jar com.facebook.thrift.test.TestNonblockingServer $*
diff --git a/test/java/src/OverloadNonblockingServer.java b/test/java/src/OverloadNonblockingServer.java
new file mode 100644
index 0000000..26f5354
--- /dev/null
+++ b/test/java/src/OverloadNonblockingServer.java
@@ -0,0 +1,44 @@
+
+package com.facebook.thrift;
+
+import thrift.test.*;
+
+import com.facebook.thrift.TApplicationException;
+import com.facebook.thrift.TSerializer;
+import com.facebook.thrift.transport.TTransport;
+import com.facebook.thrift.transport.TSocket;
+import com.facebook.thrift.transport.TFramedTransport;
+import com.facebook.thrift.transport.TTransportException;
+import com.facebook.thrift.protocol.TBinaryProtocol;
+import com.facebook.thrift.protocol.TSimpleJSONProtocol;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.List;
+import java.util.ArrayList;
+
+
+public class OverloadNonblockingServer {
+
+  public static void main(String[] args) throws Exception {
+    int msg_size_mb = Integer.parseInt(args[0]);
+    int msg_size = msg_size_mb * 1024 * 1024;
+
+    TSocket socket = new TSocket("localhost", 9090);
+    TBinaryProtocol binprot = new TBinaryProtocol(socket);
+    socket.open();
+    binprot.writeI32(msg_size);
+    binprot.writeI32(1);
+    socket.flush();
+
+    System.in.read();
+    // Thread.sleep(30000);
+    for (int i = 0; i < msg_size_mb; i++) {
+      binprot.writeBinary(new byte[1024 * 1024]);
+    }
+
+    socket.close();
+  }
+}