--- /dev/null
+// HttpServerState.java\r
+// $Id: HttpServerState.java,v 1.1 2010/06/15 12:25:13 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.www.protocol.http ;\r
+\r
+import java.util.Vector;\r
+import java.util.Enumeration;\r
+\r
+class HttpServerState {\r
+ HttpServer server = null;\r
+ Vector conns = null;\r
+\r
+ protected int state = 0;\r
+ protected HttpException ex = null;\r
+ protected int num_conn = 0;\r
+\r
+ protected static final int PREINIT = 0;\r
+ protected static final int ERROR = 1;\r
+ protected static final int OK = 2;\r
+\r
+ private static final boolean debug = false;\r
+\r
+// Vector allconns = new Vector(); (used for debug)\r
+\r
+ final HttpServer getServer() {\r
+ return server;\r
+ }\r
+\r
+ synchronized void incrConnectionCount() {\r
+ ++num_conn;\r
+ }\r
+\r
+ synchronized void decrConnectionCount() {\r
+ --num_conn;\r
+ }\r
+ synchronized int getConnectionCount() {\r
+ return num_conn;\r
+ }\r
+\r
+ synchronized boolean notEnoughConnections() {\r
+ return (conns == null) || (conns.size() == 0);\r
+ }\r
+\r
+ synchronized void registerConnection(HttpConnection conn) {\r
+ if ( conns == null ) {\r
+ conns = new Vector(4);\r
+ }\r
+ conns.addElement(conn);\r
+ }\r
+ \r
+ synchronized void unregisterConnection(HttpConnection conn) {\r
+ if ( conns != null ) {\r
+ conns.removeElement(conn);\r
+ }\r
+ }\r
+ \r
+ synchronized void deleteConnection(HttpConnection conn) {\r
+ if ( conns != null ) {\r
+ conns.removeElement(conn);\r
+ }\r
+ }\r
+ \r
+ synchronized boolean hasConnection() {\r
+ return (conns != null) && (conns.size() > 0);\r
+ }\r
+ \r
+ synchronized HttpConnection getConnection() {\r
+ if ((conns != null) && (conns.size() > 0)) {\r
+ Enumeration e = conns.elements();\r
+ HttpConnection conn = null;\r
+ while (e.hasMoreElements()) {\r
+ HttpConnection tmp_conn = (HttpConnection) e.nextElement();\r
+ if (tmp_conn.mayReuse()) {\r
+ conn = tmp_conn;\r
+ conns.removeElement(conn);\r
+ break;\r
+ }\r
+ }\r
+ if (conn == null) {\r
+ conn = (HttpConnection) conns.elementAt(0);\r
+ conns.removeElementAt(0);\r
+ }\r
+ conn.cached = true;\r
+ return conn;\r
+ }\r
+ return null;\r
+ }\r
+ \r
+ public String toString() {\r
+ String tostring = "";\r
+ if (conns == null)\r
+ tostring = "null";\r
+ else if (conns.size() == 0)\r
+ tostring = "empty";\r
+ else {\r
+ for (int i = 0 ; i < conns.size() ; i++) {\r
+ tostring += "["+\r
+ ((HttpConnection) conns.elementAt(i)).toString()+\r
+ "]";\r
+ }\r
+ }\r
+ return "" + num_conn + tostring;\r
+ }\r
+\r
+ HttpServerState(HttpServer server) {\r
+ this.server = server;\r
+ }\r
+}\r
+\r
+\r