public abstract class ClientDownload extends ServeErrors implements java.lang.Runnable
Modifier and Type | Field and Description |
---|---|
protected HostItem |
client |
(package private) static int |
DIFF_PERCENT_PROGRESS |
(package private) static int |
DIFF_TIME_PROGRESS_MILLIS |
protected java.lang.String |
dirStorage |
protected java.lang.String |
filename |
protected byte[] |
hash512 |
protected java.util.List<HostItem> |
hostList |
protected int |
lastPercentProgress |
protected java.time.Instant |
lastTimeProgress |
protected Logger |
logger |
protected static long |
MAX_PARTIAL_SIZE |
protected java.util.List<java.lang.Long> |
offsetsPending |
protected java.util.List<java.lang.Long> |
offsetsToAsk |
protected java.lang.String |
partsSubdir |
protected java.util.Map<HostItem,java.lang.Long> |
ratioUpdater |
protected long |
size |
protected java.util.List<ClientDownloadPart> |
sockList |
protected boolean |
stop |
protected boolean |
success |
protected HostItem |
tracker |
Constructor and Description |
---|
ClientDownload(java.lang.String filename,
java.util.List<HostItem> hostList,
java.lang.String partsSubdir,
java.lang.String dirStorage,
Logger logger,
HostItem client,
HostItem tracker)
Constructor with parameters: filename, list of hosts, parts subdirectory and dirStorage
|
Modifier and Type | Method and Description |
---|---|
protected void |
assignTasks()
Assign tasks randomly to threads.
|
protected void |
checkTasksStatus()
Remove tasks from failed threads.
|
protected abstract void |
closeHostItemSocket(HostItem hostItem)
Close HostItem socket
|
protected abstract ClientDownloadPart |
createDownloadPart(HostItem hostItem)
Create a clientDownloadPart
|
byte[] |
getHashSum512()
Getter for hash512sum
|
protected byte[] |
getHashSum512(HostItem hostItem)
Get hashsum from server.
|
protected abstract java.lang.Object |
getHostItemSocket(HostItem hostItem)
Getter for HostItem socket
|
boolean |
getSuccess()
Success getter.
|
protected void |
init()
Initialize infos about file to download (size, hash512sum, partslist to dl).
|
protected void |
initThreads()
Starts threads for each server in hostList.
|
protected void |
printProgression()
Print progression of the download.
|
protected void |
purgeList()
Removes servers not owning the correct file to download from list.
|
protected void |
reassembleFile()
Reassemble file from file parts.
|
void |
run()
Runnable implementation
|
void |
sendRatioUpdate()
Send Ratio update to the tracker
|
protected void |
setSize()
Set size of file to download.
|
void |
setStop()
Asks thread to stop
|
protected void |
stopTasks()
Stop threads
|
createProtocolP2PPacket, sendEmptyDirectory, sendEmptyFile, sendInternalError, sendNotATracker, sendNotFound, sendUnknownHost, writeLog, writeLog
protected java.util.List<HostItem> hostList
protected java.lang.String filename
protected byte[] hash512
protected java.util.List<ClientDownloadPart> sockList
protected java.util.Map<HostItem,java.lang.Long> ratioUpdater
protected java.util.List<java.lang.Long> offsetsToAsk
protected java.util.List<java.lang.Long> offsetsPending
protected boolean stop
protected long size
protected static final long MAX_PARTIAL_SIZE
protected java.lang.String partsSubdir
protected java.lang.String dirStorage
protected boolean success
protected Logger logger
protected HostItem client
protected HostItem tracker
protected int lastPercentProgress
protected java.time.Instant lastTimeProgress
static final int DIFF_TIME_PROGRESS_MILLIS
static final int DIFF_PERCENT_PROGRESS
public ClientDownload(java.lang.String filename, java.util.List<HostItem> hostList, java.lang.String partsSubdir, java.lang.String dirStorage, Logger logger, HostItem client, HostItem tracker)
filename
- name of file to downloadhostList
- list of serverspartsSubdir
- directory to store .part filesdirStorage
- directory to write assembled filelogger
- Loggerclient
- HostItem of the applicationtracker
- HostItem of the trackerpublic boolean getSuccess()
public byte[] getHashSum512()
protected void stopTasks()
public void setStop()
protected void assignTasks() throws InternalError
InternalError
protected abstract ClientDownloadPart createDownloadPart(HostItem hostItem)
hostItem
- Hostitem of the serverprotected void initThreads()
protected void checkTasksStatus() throws InternalError
InternalError
public void sendRatioUpdate()
protected byte[] getHashSum512(HostItem hostItem) throws InternalError
hostItem
- server to ask hashInternalError
protected void purgeList() throws InternalError
InternalError
protected void reassembleFile()
protected void setSize() throws InternalError
InternalError
protected abstract void closeHostItemSocket(HostItem hostItem)
hostItem
- HostItempublic void run()
run
in interface java.lang.Runnable
protected void printProgression()
protected void init() throws InternalError
InternalError
protected abstract java.lang.Object getHostItemSocket(HostItem hostItem) throws java.net.SocketException, java.net.UnknownHostException, java.io.IOException
hostItem
- HostItemjava.net.SocketException
java.net.UnknownHostException
java.io.IOException