HTTP and Other TCP Servers

public class rServerRegistrar {

public Thread[] cthreads;

public rServerRegistrar(Thread thr) {
cthreads=new Thread[1];
cthreads[0]=thr;
}

public void registerThread(Thread newthread) {
Thread[] tempthreads=new Thread[cthreads.length+1];
for(int i=0;i<cthreads.length;i++) {
tempthreads[i]=cthreads[i];
}
tempthreads[cthreads.length]=newthread;
cthreads=tempthreads;
}

public void deregisterThread(Thread delthread) {
Thread[] tempthreads=new Thread[cthreads.length-1];
int count=0;
for(int i=0;i<cthreads.length;i++) {
if(delthread.getName()!=cthreads[i].getName()) {
tempthreads[count]=cthreads[i];
count++;
}
}
cthreads=tempthreads;
}

private void updateThreads() {
int count=0; // First count the number of alive threads.
for(int i=0;i<cthreads.length;i++) {
if(cthreads[i].isAlive()) count++;
}
Thread[] temp=new Thread[count];
count=0;
for(int i=0;i<cthreads.length;i++) {
if(cthreads[i].isAlive()) {
temp[count]=cthreads[i];
count++;
}
}
}

public Thread[] getClientThreads() {
updateThreads(); // Return all except first thread.
Thread[] temp=new Thread[cthreads.length-1];
for(int i=0;i<temp.length;i++) {
temp[i]=cthreads[i+1];
}
return temp;
}

}

0 Response to "HTTP and Other TCP Servers"

Post a Comment

comments