|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.faban.driver.transport.util.MultipleTransport
public class MultipleTransport
This class is used to load multiple HTTP requests, emulating a browser. It is configured with a number of threads, and requests are loaded simultaneously by those threads. Typical usage of this class:
MultipleTransport mt = new MultipleTransport(2); mt.addURL("http://myhost/index.html"); mt.addURL("http://myhost/image1.gif"); mt.addURL("http://myhost/image2.gif"); mt.addURL("http://myhost/image3.gif"); mt.addURL("http://myhost/image4.gif"); boolean success = mt.waitForAll();Nothing is actually loaded until the waitForAll() method is called. When that method is called, the first URL is loaded (hence, the first URL is typically the page URL) in the calling thread. Subsequently, the remaining URLs (typically images and other resources) are loaded by the calling thread and the threads created by this class. The total number of simultaneous threads is specified by the constructor of this class, but that includes the calling thread: that creates a more efficient thread usage. After calling the waitForAll() method, the MultipleTransport is reset and can be reused to load a new set of requests; if the requests are loaded from the same host, then the keep-alive semantics of the HTTP transport will be used. When finished with this object, you should call its close() method to terminate its threads; otherwise the threads will leak. I have chosen not to add a finalizer to this class to close the threads, since that particular operation is known to cause issues with the garbage collector. TODO: Need a way to retrieve individual URL status
Constructor Summary | |
---|---|
MultipleTransport(int n)
Create an MultipleTransport that can load n requests simultaneously. |
Method Summary | |
---|---|
void |
addURL(String url)
Add a request to the list of things to be retrieved. |
void |
addURL(String url,
String postData)
Add a request to the list of things to be retrieved. |
void |
close()
Close down the loader, stopping all its threads. |
void |
run()
Runs the parallel threads fetching the other URLs. |
String |
toString()
Provides a string representation of this transport. |
boolean |
waitForAll()
Start loading requests and wait for them all to be loaded. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public MultipleTransport(int n)
n
- Number of threads to use to load requests. That includes
the thread that calls waitForAll(), so we create n-1 threads.Method Detail |
---|
public void run()
run
in interface Runnable
Runnable.run()
public void addURL(String url)
url
- The URL to loadpublic void addURL(String url, String postData)
url
- The URL to loadpostData
- Data for a POST URL. If data is null, URL is
assumed to be a GET URL.public boolean waitForAll()
public void close()
public String toString()
toString
in class Object
Object.toString()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |