01: // ICPWaiter.java
02: // $Id: ICPWaiter.java,v 1.3 2000/08/16 21:38:04 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
04: // please first read the full copyright statement in file COPYRIGHT.HTML
05:
06: package org.w3c.www.protocol.http.icp;
07:
08: import java.util.Vector;
09:
10: class ICPWaiter {
11:
12: /**
13: * The identifier this waiter is waitin for.
14: */
15: protected int id = -1;
16: /**
17: * The queue of replies, as they arrive:
18: */
19: protected Vector replies = null;
20:
21: /**
22: * Get the identifier this waiter is waiting on.
23: * @return The integer identifier.
24: */
25:
26: protected final int getIdentifier() {
27: return id;
28: }
29:
30: /**
31: * Get next matching reply until timeout expires.
32: * @param timeout The timeout to wait until filaure.
33: * @return A ICPReply instance, if available, or <strong>null</strong>
34: * if timeout has expired.
35: */
36:
37: protected synchronized ICPReply getNextReply(long timeout) {
38: // Do we have a reply handy ?
39: if (replies.size() > 0) {
40: ICPReply reply = (ICPReply) replies.elementAt(0);
41: replies.removeElementAt(0);
42: return reply;
43: }
44: // Wait for timeout, or notification.
45: try {
46: wait(timeout);
47: } catch (InterruptedException ex) {
48: }
49: // Return, depnding on timeout expiration or reply available:
50: if (replies.size() == 0)
51: return null;
52: ICPReply reply = (ICPReply) replies.elementAt(0);
53: replies.removeElementAt(0);
54: return reply;
55: }
56:
57: /**
58: * Notify that waiter that a matching reply was received.
59: * @param reply The matching ICP reply.
60: */
61:
62: protected synchronized void notifyReply(ICPReply reply) {
63: // Add that reply to the queue, and notify:
64: replies.addElement(reply);
65: notifyAll();
66: }
67:
68: ICPWaiter(int id) {
69: this .replies = new Vector(4);
70: this.id = id;
71: }
72:
73: }
|