//Override the super class accept to increase the number of servers if they are all busy
//If we already have the maximum number of threads, just queue the request
if (servers.length >= MAXIMUM_NUM_SERVERS)
{
super.acceptRequest(r);
return;
}
//otherwise, if one of the servers is available, just queue the request
for (int i = servers.length-1; i>=0 ; i--)
{
if (servers[i].isAvailable())
{
super.acceptRequest(r);
return;
}
}
//otherwise, increase the server pool by one, then queue the request
Thread t;
ActiveRequestQueue[] tmp_servers = servers;
servers = new ActiveRequestQueue[tmp_servers.length+1];
System.arraycopy(tmp_servers, 0, servers, 0, tmp_servers.length);
servers[tmp_servers.length] = new ActiveRequestQueue(this);
(t = new Thread(servers[tmp_servers.length])).start();
servers[tmp_servers.length].myThread = t;
super.acceptRequest(r);