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:
10: private int ticketCounter = 1;
11:
12: public int seekingSocket(SocketSeeker seeker) {
13: int ticket = ticketCounter++;
14: waitingList.put(new Integer(ticket), seeker);
15: return ticket;
16: }
17:
18: public Collection getWaitingList() {
19: return waitingList.values();
20: }
21:
22: public void dealSocketTo(int ticket, SocketDoner doner)
23: throws Exception {
24: Integer key = new Integer(ticket);
25: SocketSeeker seeker = (SocketSeeker) waitingList.get(key);
26: seeker.acceptSocketFrom(doner);
27: waitingList.remove(key);
28: }
29:
30: public boolean isWaiting(int ticket) {
31: return waitingList.containsKey(new Integer(ticket));
32: }
33: }
|