01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.responders.run;
04:
05: import java.util.*;
06:
07: public class SocketDealer {
08: private Map waitingList = new HashMap(17);
09: private int ticketCounter = 1;
10:
11: public int seekingSocket(SocketSeeker seeker) {
12: int ticket = ticketCounter++;
13: waitingList.put(new Integer(ticket), seeker);
14: return ticket;
15: }
16:
17: public Collection getWaitingList() {
18: return waitingList.values();
19: }
20:
21: public void dealSocketTo(int ticket, SocketDoner doner)
22: throws Exception {
23: Integer key = new Integer(ticket);
24: SocketSeeker seeker = (SocketSeeker) waitingList.get(key);
25: seeker.acceptSocketFrom(doner);
26: waitingList.remove(key);
27: }
28:
29: public boolean isWaiting(int ticket) {
30: return waitingList.containsKey(new Integer(ticket));
31: }
32: }
|