Client Side API - An easy way to timeout Requests.

Dear Gentlemen,

	I have spent the entire week try to implement Request timeouts in 
Client-Side Jigsaw (only to find out that my problem is not with Jigsaw, but 
rather some third-party advertisement server that takes up to five minutes 
to deliver a puny GIF file).  However, while working on my problem, I did 
find a solution to implementing Request timeouts on the Client-Side without 
modifying the Jigsaw source code.

	Basically, one can construct HttpManagerThreads to run Requests that have 
been created by an HttpExecutiveManager.  Once the HttpExecutiveManager 
starts a HttpManagerThread, it calls wait(timeout milliseconds) on itself 
until either (1) the HttpManagerThread notifies it with a Reply or (2) it 
times out, destroys that HttpManagerThread, and then starts a new 
HttpManagerThread to try running the request again.  This scheme appears to 
be clean and it works well (of course the real solution lies in finishing 
the Client-Side Jigsaw source code).  Below I have posted outlines of the 
two classes that I have used to implemented Request timeouts on the 
Client-Side.

		Truly yours,
		John Philip Anderson
		jpanderson_215@hotmail.com

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public class HttpManagerThread extends Thread{

	Reply reply;
	Request request;
	HttpManager manager;
	HttpExecutiveManager executivemanager;

	HttpManagerThread (Request request, HttpExecutiveManager executivemanager){
		this.request = request;
		this.executivemanager = executivemanager;
		manager = HttpManager.getManager();
		try{cookiefilter.initialize(manager);
		} catch(PropRequestFilterException prfexcpt) {
			System.out.println("PropRequestFilterException : " + prfexcpt);
		}
	}

	public void run(){
		try{	reply = manager.runRequest(request);
		}catch(HttpException httpexcpt){
			System.out.println("HttpException: httpexcpt);
		}
		this.returnReply(reply);
	}

	protected void returnReply(Reply reply){
		executivemanager.takeReply(reply);
	}
}

public class HttpExecutiveManager{

	int timeout;
	boolean replytaken;
	Request request;
	HttpManager manager;

	HttpExecutiveManager(int timeout){
		this.timeout = timeout;
		manager = HttpManager.getManager();
		request = manager.createRequest();
	}

	public synchronized void read(){
		replytaken = false;
		while(!replytaken){
			HttpManagerThread httpmanagerthread = new HttpManagerThread(request, 
this);
			httpmanagerthread.start();
			try{	this.wait(timeout);
			} catch(InterruptedException intrpexcpt) {
				System.out.println("InterruptedException: " + intrpexcpt);
			}
			httpmanagerthread.stop();
			httpmanagerthread = null;
		}
	}

	public synchronized void takeReply(Reply reply){
		this.reply = reply;
		replytaken = true;
		this.notify();
	}
}

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

Received on Thursday, 8 March 2001 15:39:55 UTC