public abstract class ClientDownloadPart extends ServeErrors implements java.lang.Runnable
Modifier and Type | Field and Description |
---|---|
protected HostItem |
client |
protected boolean |
failed |
protected java.lang.String |
filename |
protected Logger |
logger |
protected ClientDownload |
manager |
protected static long |
MAX_PARTIAL_SIZE |
protected boolean |
noTask |
protected java.lang.String |
partsSubdir |
protected java.util.List<java.lang.Long> |
pendingTasks |
protected long |
receivedBytesCount |
private HostItem |
server |
protected boolean |
stop |
protected java.util.List<java.lang.Long> |
tasksDone |
protected boolean |
tasksListsLock |
protected java.util.List<java.lang.Long> |
toDoTasks |
Constructor and Description |
---|
ClientDownloadPart(ClientDownload manager,
java.lang.String filename,
java.lang.String partsSubdir,
Logger logger,
HostItem client,
HostItem server)
Constructor with filename, socket, and part subdir
|
Modifier and Type | Method and Description |
---|---|
void |
assignTask(java.lang.Long task)
Adds offset of files parts to download.
|
protected abstract void |
closeSocket()
Close the socket
|
void |
doTasks()
Send one request and wait for one response.
|
<T extends ProtocolP2PPacket<?>> |
downloadPart(T d)
Download file part associated to the request send (d).
|
java.util.List<java.lang.Long> |
getDone()
Get list of downloaded file parts offset, then clear this list.
|
java.util.List<java.lang.Long> |
getFailed()
Get list of offsets that have not be downloaded if failed, else
empty list.
|
java.lang.Long |
getReceivedBytesCount()
receivedBytesCount getter
|
HostItem |
getServer()
Server getter
|
protected abstract java.lang.Object |
getSocket()
Get the socket
|
boolean |
hasFailed()
True if thread has failed to get a file.
|
protected ProtocolP2PPacket<?> |
reqPart(java.lang.Long offset)
Send a request for a specific offset.
|
void |
run()
Runnable implementation
|
void |
setStop()
Asks to stop thread.
|
createProtocolP2PPacket, sendEmptyDirectory, sendEmptyFile, sendInternalError, sendNotATracker, sendNotFound, sendUnknownHost, writeLog, writeLog
protected long receivedBytesCount
protected java.util.List<java.lang.Long> toDoTasks
protected java.util.List<java.lang.Long> pendingTasks
protected java.util.List<java.lang.Long> tasksDone
protected volatile boolean tasksListsLock
protected volatile boolean stop
protected volatile boolean failed
protected java.lang.String filename
protected volatile boolean noTask
protected java.lang.String partsSubdir
protected static final long MAX_PARTIAL_SIZE
protected ClientDownload manager
protected Logger logger
protected HostItem client
private HostItem server
public ClientDownloadPart(ClientDownload manager, java.lang.String filename, java.lang.String partsSubdir, Logger logger, HostItem client, HostItem server)
filename
- name of file to downloadsocket
- socket to usepartsSubdir
- directory to store .part fileslogger
- Loggerclient
- HostItem of the applicationserver
- HostItem of the server applicationpublic java.lang.Long getReceivedBytesCount()
public HostItem getServer()
public boolean hasFailed()
public void setStop() throws java.lang.InterruptedException
java.lang.InterruptedException
public void run()
run
in interface java.lang.Runnable
protected abstract void closeSocket() throws java.io.IOException
java.io.IOException
public java.util.List<java.lang.Long> getFailed()
public java.util.List<java.lang.Long> getDone() throws java.lang.InterruptedException
java.lang.InterruptedException
public void assignTask(java.lang.Long task) throws java.lang.InterruptedException
task
- offset to downloadjava.lang.InterruptedException
public void doTasks() throws java.lang.InterruptedException
java.lang.InterruptedException
protected ProtocolP2PPacket<?> reqPart(java.lang.Long offset)
offset
- Offset of the file part to downloadprotected abstract java.lang.Object getSocket()
public <T extends ProtocolP2PPacket<?>> boolean downloadPart(T d)
d
- request packet