diff options
Diffstat (limited to 'NET/worlds/network/WaitList.java')
| -rw-r--r-- | NET/worlds/network/WaitList.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/NET/worlds/network/WaitList.java b/NET/worlds/network/WaitList.java new file mode 100644 index 0000000..6fd3c00 --- /dev/null +++ b/NET/worlds/network/WaitList.java @@ -0,0 +1,48 @@ +package NET.worlds.network; + +import java.util.Vector; + +class WaitList { + private Vector<ConnectionWaiter> _waitList = new Vector<ConnectionWaiter>(); + private Object _parent; + + protected WaitList(Object parent) { + this._parent = parent; + } + + protected synchronized void addWaiter(ConnectionWaiter cw) { + if ((Galaxy.getDebugLevel() & 16384) > 0) { + System.out.println(this._parent + ": waitForConnection(" + cw + ")"); + } + + if (this._waitList.indexOf(cw) < 0) { + this._waitList.addElement(cw); + } + } + + protected synchronized void abortWait(ConnectionWaiter cw) { + assert this._waitList.indexOf(cw) != -1; + + this._waitList.removeElement(cw); + } + + protected synchronized void clear() { + this._waitList = new Vector<ConnectionWaiter>(); + } + + protected synchronized void notify(boolean connected) { + if ((Galaxy.getDebugLevel() & 16384) > 0 && this._waitList.size() > 0) { + System.out.println(this._parent + ": notify(" + connected + ")"); + } + + for (int i = this._waitList.size() - 1; i >= 0; i--) { + ConnectionWaiter cw = this._waitList.elementAt(i); + if ((Galaxy.getDebugLevel() & 16384) > 0) { + System.out.println("\tnotifying " + cw); + } + + cw.connectionCallback(this._parent, connected); + this._waitList.removeElementAt(i); + } + } +} |