Implement Selenium testing framework. Fixed thread safety for socket token management.

This commit is contained in:
Heng Sin Low 2013-04-30 17:38:55 +08:00
parent f1231c0e63
commit 4d3b77a840
1 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,33 @@
// Copyright (C) 2003-2009 by Object Mentor, Inc. All rights reserved.
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.responders.run;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
public class SocketDealer {
private Map<Integer, SocketSeeker> waitingList = new HashMap<Integer, SocketSeeker>(17);
private int ticketCounter = 1;
public synchronized int seekingSocket(SocketSeeker seeker) {
int ticket = ticketCounter++;
waitingList.put(new Integer(ticket), seeker);
return ticket;
}
public synchronized Collection<SocketSeeker> getWaitingList() {
return waitingList.values();
}
public synchronized void dealSocketTo(int ticket, SocketDoner doner) throws Exception {
Integer key = new Integer(ticket);
SocketSeeker seeker = waitingList.get(key);
seeker.acceptSocketFrom(doner);
waitingList.remove(key);
}
public synchronized boolean isWaiting(int ticket) {
return waitingList.containsKey(new Integer(ticket));
}
}