|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.limegroup.gnutella.uploader.HTTPUploader
Maintains state for an HTTP upload request. This class follows the State Pattern, delegating its writeResponse method to the appropriate state. All states except for CONNECTING, COMPLETE, and INTERRUPTED have an associated state class that implements HTTPMessage. Care must be taken to call closeFileStreams whenever a chunk of the transfer is finished, and to call stop when the entire HTTP/1.1 session is finished. A single HTTPUploader should be reused for multiple chunks of a single file in an HTTP/1.1 session. However, multiple HTTPUploaders should be used for multiple files in a single HTTP/1.1 session.
Field Summary |
Fields inherited from interface com.limegroup.gnutella.Uploader |
BROWSE_HOST, COMPLETE, CONNECTING, FILE_NOT_FOUND, FREELOADER, INTERRUPTED, LIMIT_REACHED, MALFORMED_REQUEST, PUSH_PROXY, QUEUED, UNAVAILABLE_RANGE, UPDATE_FILE, UPLOADING |
Constructor Summary | |
HTTPUploader(HTTPRequestMethod method,
java.lang.String fileName,
java.net.Socket socket,
int index,
java.util.Map params,
StalledUploadWatchdog dog)
Consructor for a "normal" non-push upload. |
Method Summary | |
int |
amountUploaded()
The amount of bytes that this upload has transferred. |
void |
closeFileStreams()
Close the file input stream. |
int |
getAmountRequested()
returns the length of the requested size for uploading |
float |
getAverageBandwidth()
Returns the overall averaged bandwidth between all calls of measureBandwidth |
boolean |
getCloseConnection()
Returns whether or not the current state wants to close the connection. |
FileDesc |
getFileDesc()
Returns the FileDesc instance for this uploader. |
java.lang.String |
getFileName()
returns the name of the file being uploaded. |
int |
getFileSize()
returns the length of the file being uploaded. |
int |
getGnutellaPort()
return the port of the gnutella-client host (not the HTTP port) |
java.lang.String |
getHost()
returns the string representation of the IP Address of the host being uploaded to. |
int |
getIndex()
returns the index of the file being uploaded. |
int |
getLastTransferState()
Returns the last transfer state of this uploader. |
float |
getMeasuredBandwidth()
Returns the throughput of this in kilobytes/sec (KB/s) between the last two calls to measureBandwidth, or 0.0 if unknown. |
HTTPRequestMethod |
getMethod()
Returns the current HTTP Request Method. |
java.net.InetAddress |
getNodeAddress()
|
int |
getNodePort()
|
int |
getQueuePosition()
Returns the queued position if queued. |
URN |
getRequestedURN()
Returns the content URN that the client asked for. |
int |
getState()
Returns the current state of this uploader. |
int |
getTotalAmountUploaded()
The total amount of bytes that this upload and all previous uploaders have transferred on this socket in this file-exchange. |
int |
getUploadBegin()
The byte offset where we should start the upload. |
int |
getUploadEnd()
Returns the offset of the last byte to send PLUS ONE. |
java.lang.String |
getUserAgent()
return the userAgent |
void |
initializeStreams()
Initializes the OutputStream for this HTTPUploader to use. |
boolean |
isBrowseHostEnabled()
returns true if browse host is enabled, false if it is not. |
boolean |
isChatEnabled()
returns true if chat for the host is on, false if it is not. |
boolean |
isHeaderParsed()
return whether or not the headers have been parsed |
boolean |
isInactive()
Returns whether or not this upload is in what is considered an "inactive" state, such as completed or aborted. |
void |
measureBandwidth()
Measures the data throughput since the last call to measureBandwidth. |
void |
readHeader(java.io.InputStream iStream)
Reads the HTTP header sent by the requesting client -- note that the 'GET' portion of the request header has already been read. |
void |
reinitialize(HTTPRequestMethod method,
java.util.Map params)
Reinitializes this uploader for a new request method. |
void |
setFileDesc(FileDesc fd)
Sets the FileDesc for this HTTPUploader to use. |
void |
setState(int state)
This method changes the appropriate state class based on the integer representing the state. |
void |
stop()
Closes the outputstream, inputstream, and socket for this upload connection if they are not null. |
boolean |
supportsQueueing()
|
java.lang.String |
toString()
|
void |
writeResponse()
Starts "uploading" the requested file. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public HTTPUploader(HTTPRequestMethod method, java.lang.String fileName, java.net.Socket socket, int index, java.util.Map params, StalledUploadWatchdog dog)
method
- the HTTPRequestMethod for the requestfileName
- the name of the filesocket
- the Socket instance to serve the upload overindex
- the index of the file in the set of shared filesparams
- the map of parameters in the http request.dog
- the StalledUploadWatchdog to use for monitor stalls.
to initialize this' bandwidth tracker so we have historyMethod Detail |
public void reinitialize(HTTPRequestMethod method, java.util.Map params)
method
- the HTTPRequestMethod to change to.params
- the parameter list to change to.public void setFileDesc(FileDesc fd) throws java.io.IOException
java.io.IOException
public void initializeStreams() throws java.io.IOException
java.io.IOException
public void writeResponse() throws java.io.IOException
This method also handles storing any newly discovered alternate locations for this file in the corresponding FileDesc. The new alternate locations are discovered through the requesting client's HTTP headers.
Implements the Uploader interface.
writeResponse
in interface Uploader
java.io.IOException
public void stop()
stop
in interface Uploader
public void closeFileStreams()
public void setState(int state)
setState
in interface Uploader
public boolean getCloseConnection()
public HTTPRequestMethod getMethod()
getMethod
in interface Uploader
public int getQueuePosition()
getQueuePosition
in interface Uploader
public boolean isInactive()
isInactive
in interface Uploader
public int getUploadBegin()
public int getUploadEnd()
public int getFileSize()
Uploader
getFileSize
in interface Uploader
public int getAmountRequested()
Uploader
getAmountRequested
in interface Uploader
public int getIndex()
Uploader
getIndex
in interface Uploader
public java.lang.String getFileName()
Uploader
getFileName
in interface Uploader
public int getState()
Uploader
getState
in interface Uploader
public int getLastTransferState()
Uploader
getLastTransferState
in interface Uploader
public java.lang.String getHost()
Uploader
getHost
in interface Uploader
public boolean isChatEnabled()
Uploader
isChatEnabled
in interface Uploader
public boolean isBrowseHostEnabled()
Uploader
isBrowseHostEnabled
in interface Uploader
public int getGnutellaPort()
Uploader
getGnutellaPort
in interface Uploader
public java.lang.String getUserAgent()
Uploader
getUserAgent
in interface Uploader
public boolean isHeaderParsed()
Uploader
isHeaderParsed
in interface Uploader
public boolean supportsQueueing()
supportsQueueing
in interface Uploader
public java.net.InetAddress getNodeAddress()
public int getNodePort()
public int amountUploaded()
amountUploaded
in interface Uploader
public int getTotalAmountUploaded()
getTotalAmountUploaded
in interface Uploader
public FileDesc getFileDesc()
getFileDesc
in interface Uploader
public URN getRequestedURN()
public void readHeader(java.io.InputStream iStream) throws java.io.IOException
iStream
- the input stream to read the headers from.
IOException
- if the connection closes while reading
ProblemReadingHeaderException
- if any header is invalid
java.io.IOException
public void measureBandwidth()
BandwidthTracker
measureBandwidth
in interface BandwidthTracker
public float getMeasuredBandwidth()
BandwidthTracker
getMeasuredBandwidth
in interface BandwidthTracker
public float getAverageBandwidth()
BandwidthTracker
getAverageBandwidth
in interface BandwidthTracker
public java.lang.String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |