
import java.net.*;

public class LoadTest implements LoadListener {

int numComplete = 0, numPassed = 0, numFailed = 0;
final static int NUM_THREADS = 100;
long startTime, stopTime;

public LoadTest(String s) {
	System.out.println("Pounding on "+s);

	URL url;

	Thread t;
	Load l;

	try {
		url = new URL(s);
	}
	catch(MalformedURLException e) {
		System.out.println("Bad URL "+s);
		return;
	}

	startTime = System.currentTimeMillis();

	try {
		for(int i = 0; i < NUM_THREADS; i++) {
			l = new Load(url);
			l.addLoadListener(this);
			t = new Thread(l);
			t.start();
		}
	}
	catch(Exception e) {
		e.printStackTrace();
	}
}

public void loadComplete(Load l) {
	System.out.println("Load "+l+" is finished "+(l.isSuccessful()?"successfully":" and failed"));
	if(!l.isSuccessful()) {
//		l.getException().printStackTrace();
	}
	numComplete++;
	if(l.isSuccessful())
		numPassed++;
	else
		numFailed++;

	if(numComplete == NUM_THREADS) {
		stopTime = System.currentTimeMillis();
		System.out.println("all done: "+(stopTime-startTime));
		System.out.println(numPassed+" passed, "+numFailed+" failed");
	}
}


public static void main(String args[]) {
	new LoadTest(args[0]);
}
}
