Java libraries for Thrift

Summary: The basic Thrift stack implemented in Java, still in need of a lot of work but fully functional.

Reviewed By: aditya

Test Plan: Unit tests are the NEXT checkin, I swear

Notes: Perf on the Java stuff actually isn't that bad, and it's far from optimized at the moment. Barely any tweaking has been done. Testing shows that a Java server with the C++ client has RPC performance within 2x of the pure C++ implementations. This is pretty sweet, since this cost will be eclipsed by the cost of whatever processing is being done on an actual server doing real work.




git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664715 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/java/src/transport/TServerSocket.java b/lib/java/src/transport/TServerSocket.java
new file mode 100644
index 0000000..a885fa1
--- /dev/null
+++ b/lib/java/src/transport/TServerSocket.java
@@ -0,0 +1,46 @@
+package com.facebook.thrift.transport;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+/**
+ * Wrapper around ServerSocket for Thrift.
+ *
+ * @author Mark Slee <mcslee@facebook.com>
+ */
+public class TServerSocket extends TServerTransport {
+  
+  private ServerSocket serverSocket_;
+  
+  public TServerSocket(ServerSocket serverSocket) {
+    serverSocket_ = serverSocket;
+  }
+
+  public void listen() throws TTransportException {}
+  
+  protected TSocket acceptImpl() throws TTransportException {
+    if (serverSocket_ == null) {
+      throw new TTransportException("No underlying server socket.");
+    }
+    try {
+      Socket result = serverSocket_.accept();
+      return new TSocket(result);
+    } catch (IOException iox) {
+      throw new TTransportException(iox);
+    }
+  }
+
+  public void close() {
+    if (serverSocket_ != null) {
+      try {
+        serverSocket_.close();
+      } catch (IOException iox) {
+        System.err.println("WARNING: Could not close server socket: " +
+                           iox.getMessage());
+      }
+      serverSocket_ = null;
+    }
+  }
+
+}