Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / jigsaw / src / org / w3c / jigsaw / http / mux / MuxClientFactory.java
diff --git a/JMCR-Stable/real-world application/jigsaw/src/org/w3c/jigsaw/http/mux/MuxClientFactory.java b/JMCR-Stable/real-world application/jigsaw/src/org/w3c/jigsaw/http/mux/MuxClientFactory.java
new file mode 100644 (file)
index 0000000..79ef7b9
--- /dev/null
@@ -0,0 +1,82 @@
+// MuxClientFactory.java\r
+// $Id: MuxClientFactory.java,v 1.1 2010/06/15 12:24:58 smhuang Exp $\r
+// (c) COPYRIGHT MIT and INRIA, 1996.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.jigsaw.http.mux;\r
+\r
+import java.io.IOException;\r
+import java.io.PrintStream;\r
+\r
+import java.net.ServerSocket;\r
+import java.net.Socket;\r
+\r
+import org.w3c.www.mux.MuxProtocolHandler;\r
+import org.w3c.www.mux.MuxStream;\r
+import org.w3c.www.mux.SampleMuxHandler;\r
+\r
+import org.w3c.jigsaw.http.ClientFactory;\r
+import org.w3c.jigsaw.http.httpd;\r
+\r
+public class MuxClientFactory implements ClientFactory {\r
+    public static final int HTTP_PORT = 80;\r
+\r
+    httpd              server  = null;\r
+    int                cid     = -1;\r
+    SampleMuxHandler   handler = null;\r
+    MuxProtocolHandler httphandler = null;\r
+\r
+    public void shutdown(boolean force) {\r
+       System.out.println("Shutdown: not implemented.");\r
+    }\r
+\r
+    /**\r
+     * Handle that new incomming connection.\r
+     * Wrap the given socket into a MuxStream, the rest is handled magically.\r
+     * @param socket The newly accepted socket.\r
+     */\r
+\r
+    public void handleConnection(Socket socket) {\r
+       try {\r
+           new MuxStream(true\r
+                         , handler\r
+                         , socket);\r
+       } catch (IOException ex) {\r
+           server.errlog(getClass().getName()\r
+                         +": rejected newly accepted connection (IOerror): "\r
+                         + ex.getMessage());\r
+       }\r
+    }\r
+\r
+    /**\r
+     * Create a suitable server socket for our server context.\r
+     * @return A ServerSocket instance.\r
+     * @exception IOException If some IO error occured while creating the\r
+     * server socket.\r
+     */\r
+\r
+    public ServerSocket createServerSocket() \r
+       throws IOException\r
+    {\r
+       return new ServerSocket(server.getPort(), 128);\r
+    }\r
+\r
+    /**\r
+     * Initialize the MUX client factory.\r
+     * @param server The server context in which this factory is to run.\r
+     */\r
+\r
+    public void initialize(httpd server) {\r
+       // Initialize the server itself:\r
+       this.server  = server;\r
+       // Configure the mux stream handler:\r
+       handler     = (SampleMuxHandler) SampleMuxHandler.getStreamHandler();\r
+       httphandler = new MuxHttpHandler(server);\r
+       handler.registerHandler(HTTP_PORT, httphandler);\r
+    }\r
+\r
+    public MuxClientFactory() {\r
+       super();\r
+    }\r
+\r
+}\r