|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.limegroup.gnutella.UploadManager
This class parses HTTP requests and delegates to HTTPUploader to handle individual uploads. The state of HTTPUploader is maintained by this class. HTTPUploader's state follows the following pattern: \ / |->---- UNAVAILABLE_RANGE -->--| |->---- PUSH_PROXY --------->--| /-->---- FILE NOT FOUND ----->--| /--->---- MALFORMED REQUEST -->--| /---->---- BROWSE HOST -------->--| /----->---- UPDATE FILE -------->--| /------>---- QUEUED ------------->--| /------->---- LIMIT REACHED ------>--| /-------->---- UPLOADING ---------->--| -->--CONNECTING-->--/ | | \|/ | | /|\ |--->INTERRUPTED |--------<---COMPLETE-<------<-------<-------<------/ (done) | | (done) The states in the middle (those other than CONNECTING, COMPLETE and INTERRUPTED) are part of the "State Pattern" and have an associated class that implements HTTPMessage. These state pattern classes are ONLY set while a transfer is active. For example, after we determine a request should be 'File Not Found', and send the response back, the state will become COMPLETE (unless there was an IOException while sending the response, in which case the state will become INTERRUPTED). To retrieve the last state that was used for transferring, use HTTPUploader.getLastTransferState(). Of particular note is that Queued uploaders are actually in COMPLETED state for the majority of the time. The QUEUED state is only active when we are actively writing back the 'You are queued' response. COMPLETE uploaders may be using HTTP/1.1, in which case the HTTPUploader recycles back to CONNECTING upon receiving the next GET/HEAD request and repeats. INTERRUPTED HTTPUploaders are never reused. However, it is possible that the socket may be reused. This odd case is ONLY possible when a requester is queued for one file and sends a subsequent request for another file. The first HTTPUploader is set as interrupted and a second one is created for the new file, using the same socket as the first one.
HTTPUploader
Field Summary | |
static int |
BAD_URN_QUERY_INDEX
The file index used in this structure to indicate a bad URN query. |
static int |
BROWSE_HOST_FILE_INDEX
The file index used in this structure to indicate a browse host request |
static int |
MALFORMED_REQUEST_INDEX
The file index used in this structure to indicate a malformed request. |
static int |
MAX_POLL_TIME
|
static int |
MIN_POLL_TIME
The min and max allowed times (in milliseconds) between requests by queued hosts. |
static int |
PUSH_PROXY_FILE_INDEX
The file index used in this structure to indicate a Push Proxy request. |
static boolean |
RECORD_STATS
Whether or not to record stats. |
static int |
UPDATE_FILE_INDEX
The file index used in this structure to indicate an update-file request |
Constructor Summary | |
UploadManager()
|
Method Summary | |
void |
acceptUpload(HTTPRequestMethod method,
java.net.Socket socket,
boolean forceAllow)
Accepts a new upload, creating a new HTTPUploader if it successfully parses the HTTP request. |
int |
calculateBandwidth()
calculates the appropriate burst size for the allocating bandwith on the upload. |
void |
close(java.net.Socket socket)
closes the passed socket and its corresponding I/O streams |
float |
getAverageBandwidth()
returns the summed average of the uploads |
float |
getMeasuredBandwidth()
Returns the total upload throughput, i.e., the sum over all uploads. |
int |
getNumQueuedUploads()
|
boolean |
hadSuccesfulUpload()
Returns true if this has ever successfully uploaded a file during this session. |
boolean |
isBusy()
Returns whether or not there are currently upload slots available, not taking the queue into account. |
boolean |
isQueueFull()
Returns whether or not the upload queue is full. |
boolean |
isServiceable()
Returns whether or not an upload request can be serviced immediately. |
boolean |
killUploadsForFileDesc(FileDesc fd)
Kills all uploads that are uploading the given FileDesc. |
void |
measureBandwidth()
Calls measureBandwidth on each uploader. |
int |
measuredUploadSpeed()
Returns the estimated upload speed in KILOBITS/s [sic] of the next transfer, assuming the client (i.e., downloader) has infinite bandwidth. |
int |
positionInQueue(java.net.Socket socket)
|
int |
uploadsInProgress()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int MIN_POLL_TIME
public static final int MAX_POLL_TIME
public static final int BROWSE_HOST_FILE_INDEX
public static final int UPDATE_FILE_INDEX
public static final int BAD_URN_QUERY_INDEX
public static final int MALFORMED_REQUEST_INDEX
public static final int PUSH_PROXY_FILE_INDEX
public static final boolean RECORD_STATS
Constructor Detail |
public UploadManager()
Method Detail |
public void acceptUpload(HTTPRequestMethod method, java.net.Socket socket, boolean forceAllow)
method
- the initial request type to use, e.g., GET or HEADsocket
- the Socket that will be used for the new upload.
It is assumed that the initial word of the request (e.g., "GET") has
been consumed (e.g., by Acceptor)forceAllow
- forces the UploadManager to allow all requests
on this socket to take place.public void close(java.net.Socket socket)
public boolean isServiceable()
public boolean isBusy()
public boolean isQueueFull()
public int uploadsInProgress()
public int getNumQueuedUploads()
public boolean hadSuccesfulUpload()
This method was added to adopt more of the BearShare QHD standard.
public boolean killUploadsForFileDesc(FileDesc fd)
public int positionInQueue(java.net.Socket socket)
public int calculateBandwidth()
public int measuredUploadSpeed()
public void measureBandwidth()
measureBandwidth
in interface BandwidthTracker
public float getMeasuredBandwidth()
getMeasuredBandwidth
in interface BandwidthTracker
public float getAverageBandwidth()
getAverageBandwidth
in interface BandwidthTracker
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |