|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object
|
+--java.lang.Thread
|
+--com.dallaway.sloppy.SlowProxyThread
All requests are handed off to an instance of this class for co-ordinating sender/receiver communication.
We start two threads inside this thread. The first waits on client requests and pipes the directly to the server. The second thread listens for server responses and pipes them back to the client.
Note that recent browsers use HTTP keep-alive so many HTTP requests could be handled by these threads before they quit.
An extra complication is that a web browser will request elements on a page (e.g., GIFs) as separate requests. To maintain a coherent bandwidth bottleneck we have to record the total bytes sent to a particular client. This means we need to identify a client. We use IP address to do this.
| Field Summary | |
protected int |
bps
|
protected java.net.InetAddress |
host
|
protected Log |
log
|
protected int |
port
|
protected java.net.Socket |
request
|
protected static int |
REQUEST_BUFFER_SIZE
Size of the buffer used for handling client requests |
protected static int |
RESPONSE_BUFFER_SIZE
|
| Fields inherited from class java.lang.Thread |
MAX_PRIORITY,
MIN_PRIORITY,
NORM_PRIORITY |
| Constructor Summary | |
SlowProxyThread(Log log,
int port,
java.net.InetAddress host,
java.net.Socket request,
int bps)
Construct a new thread to handle a client request |
|
| Method Summary | |
void |
run()
Implement a proxy by starting a request forwarding thread and a server relaying thread. |
| Methods inherited from class java.lang.Thread |
activeCount,
checkAccess,
countStackFrames,
currentThread,
destroy,
dumpStack,
enumerate,
getContextClassLoader,
getName,
getPriority,
getThreadGroup,
interrupt,
interrupted,
isAlive,
isDaemon,
isInterrupted,
join,
join,
join,
resume,
setContextClassLoader,
setDaemon,
setName,
setPriority,
sleep,
sleep,
start,
stop,
stop,
suspend,
toString,
yield |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
| Field Detail |
protected Log log
protected int port
protected java.net.InetAddress host
protected java.net.Socket request
protected int bps
protected static int REQUEST_BUFFER_SIZE
protected static int RESPONSE_BUFFER_SIZE
| Constructor Detail |
public SlowProxyThread(Log log,
int port,
java.net.InetAddress host,
java.net.Socket request,
int bps)
log - The logger to useport - The port number of the server to connect tohost - The address of the server to connect torequest - The client request to proxybps - Bytes per second| Method Detail |
public void run()
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||