com.dallaway.sloppy
Class SlowProxyThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--com.dallaway.sloppy.SlowProxyThread

public class SlowProxyThread
extends java.lang.Thread

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

log

protected Log log

port

protected int port

host

protected java.net.InetAddress host

request

protected java.net.Socket request

bps

protected int bps

REQUEST_BUFFER_SIZE

protected static int REQUEST_BUFFER_SIZE
Size of the buffer used for handling client requests

RESPONSE_BUFFER_SIZE

protected static int RESPONSE_BUFFER_SIZE
Constructor Detail

SlowProxyThread

public SlowProxyThread(Log log,
                       int port,
                       java.net.InetAddress host,
                       java.net.Socket request,
                       int bps)
Construct a new thread to handle a client request
Parameters:
log - The logger to use
port - The port number of the server to connect to
host - The address of the server to connect to
request - The client request to proxy
bps - Bytes per second
Method Detail

run

public void run()
Implement a proxy by starting a request forwarding thread and a server relaying thread.
Overrides:
run in class java.lang.Thread