--- /dev/null
+// ICPWaiter.java\r
+// $Id: ICPWaiter.java,v 1.1 2010/06/15 12:27:34 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.icp;\r
+\r
+import java.util.Vector;\r
+\r
+class ICPWaiter {\r
+\r
+ /**\r
+ * The identifier this waiter is waitin for.\r
+ */\r
+ protected int id = -1;\r
+ /**\r
+ * The queue of replies, as they arrive:\r
+ */\r
+ protected Vector replies = null;\r
+\r
+ /**\r
+ * Get the identifier this waiter is waiting on.\r
+ * @return The integer identifier.\r
+ */\r
+\r
+ protected final int getIdentifier() {\r
+ return id;\r
+ }\r
+\r
+ /**\r
+ * Get next matching reply until timeout expires.\r
+ * @param timeout The timeout to wait until filaure.\r
+ * @return A ICPReply instance, if available, or <strong>null</strong>\r
+ * if timeout has expired.\r
+ */\r
+\r
+ protected synchronized ICPReply getNextReply(long timeout) {\r
+ // Do we have a reply handy ?\r
+ if ( replies.size() > 0 ) {\r
+ ICPReply reply = (ICPReply) replies.elementAt(0);\r
+ replies.removeElementAt(0);\r
+ return reply;\r
+ }\r
+ // Wait for timeout, or notification.\r
+ try {\r
+ wait(timeout);\r
+ } catch (InterruptedException ex) {\r
+ }\r
+ // Return, depnding on timeout expiration or reply available:\r
+ if ( replies.size() == 0 )\r
+ return null;\r
+ ICPReply reply = (ICPReply) replies.elementAt(0);\r
+ replies.removeElementAt(0);\r
+ return reply;\r
+ }\r
+\r
+ /**\r
+ * Notify that waiter that a matching reply was received.\r
+ * @param reply The matching ICP reply.\r
+ */\r
+\r
+ protected synchronized void notifyReply(ICPReply reply) {\r
+ // Add that reply to the queue, and notify:\r
+ replies.addElement(reply);\r
+ notifyAll();\r
+ }\r
+\r
+ ICPWaiter(int id) {\r
+ this.replies = new Vector(4);\r
+ this.id = id;\r
+ }\r
+\r
+}\r