-
Notifications
You must be signed in to change notification settings - Fork 127
upload package
Federico Dossena edited this page Sep 12, 2019
·
1 revision
A Thread that uses a Connection to upload an endless stream of POST request containing garbage data to the server. The upload starts immediately (no need to call start()
).
This is the upload equivalent of the Downloader
class.
Constructor:
public Uploader(Connection c, String path, int ckSize)
-
c
: the instance of Connection to be used -
path
: path on the server where the garbage data will be sent -
ckSize
: size in megabytes of the garbage data sent with each POST request
Important: when an instance of Uploader is created, a blob of ckSize
megabytes is generated and stays in RAM. Don't instantiate too many!
This thread repeatedly sends a POST request containing garbage data to the server. Responses coming from the server are ignored and discarded.
Callbacks:
-
onProgress(long uploaded)
: periodically called to inform of how much data was uploaded. (Max once every 200ms) -
onError(String err)
: called if something goes wrong.err
contains the error message
Methods:
-
stopASAP()
: asks to stop the upload as soon as possible. The Connection will also be closed. Usejoin()
to wait for the thread to die -
resetUploadCounter()
: resets the counter of the amount of upload data -
getUploaded()
: returns the amount of uploaded data since the beginning or last reset
A stream for the upload test. Manages a Connection and an Uploader, and handles errors according to the specified policy.
This is the upload equivalent of the DownloadStream
class.
Constructor:
public DownloadStream(String server, String path, int ckSize, String errorHandlingMode, int connectTimeout, int soTimeout, int recvBuffer, int sendBuffer, Logger log)
-
server
: URL to the server where we need to connect -
path
: path on the server where the garbage data can be fetched -
ckSize
: size in megabytes of the garbage data -
errorHandlingMode
: what we should do in case of errors:-
SpeedtestConfig.ONERROR_FAIL
: Fail immediately -
SpeedtestConfig.ONERROR_ATTEMPT_RESTART
: Try to reconnect. If that fails, the stream fails -
SpeedtestConfig.ONERROR_MUST_RESTART
: Keep trying to reconnect until we succeed (or stopped)
-
-
connectTimeout
,soTimeout
,recvBuffer
,sendBuffer
: settings for the socket created by Connection -
log
: instance of Logger that is used to report errors such as dead connections
Callbacks:
-
onError(String err)
: called if the stream fails.err
contains the error message
Methods:
-
stopASAP()
: asks to stop the upload as soon as possible. The Connection will also be closed. Usejoin()
to wait for the connection to be actually closed -
resetUploadCounter()
: resets the counter of the amount of uploaded data -
getTotalUploaded()
: returns the amount of uploaded data since the beginning or last reset -
join()
: waits for the instance of Uploader to die