public abstract class ClientManagement extends ServeErrors
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
baseDirectory |
protected HostItem |
client |
protected ClientDownload |
downLoader |
protected java.util.List<HostItem> |
hostList |
protected Logger |
logger |
protected java.lang.String |
partsSubdir |
protected HostItem |
tracker |
| Constructor and Description |
|---|
ClientManagement(java.lang.String baseDirectory,
HostItem tracker,
java.lang.String partsSubdir,
Logger logger,
HostItem client)
Constructor with baseDirectory, tracker, partsSubdir, logger, and scanner parameters.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract void |
closeHostItemSocket(HostItem hostItem)
Close HostItem socket
|
protected abstract void |
closeTrackerSocket()
Close Tracker socket
|
private byte[] |
computeHashsum(java.lang.String filename,
HashAlgorithm h)
Compute Hashsum of a file.
|
void |
download(java.lang.String filename)
Try to download a file
|
protected abstract java.lang.Object |
getHostItemSocket(HostItem hostItem)
Getter for HostItem socket
|
protected abstract java.lang.Object |
getTrackerSocket()
Getter for tracker socket
|
protected abstract void |
initDownloader(java.lang.String filename)
Initialize downloader
|
void |
initHostList()
Initialize hostList from tracker
|
java.lang.String[] |
listDirectory()
list server’s directory content
|
protected abstract void |
writeLog(java.lang.Exception e,
LogLevel logLevel)
Implementation of writeLog
|
protected abstract void |
writeLog(java.lang.String text,
LogLevel logLevel)
Implementation of writeLog
|
createProtocolP2PPacket, sendEmptyDirectory, sendEmptyFile, sendInternalError, sendNotATracker, sendNotFound, sendUnknownHostprotected java.lang.String baseDirectory
protected java.lang.String partsSubdir
protected java.util.List<HostItem> hostList
protected HostItem tracker
protected HostItem client
protected Logger logger
protected ClientDownload downLoader
public ClientManagement(java.lang.String baseDirectory,
HostItem tracker,
java.lang.String partsSubdir,
Logger logger,
HostItem client)
baseDirectory - the root directory where files are storedtracker - Tracker hostItempartsSubdir - subdirectory to store file partslogger - Logggerclient - HostItem of the applicationprotected abstract java.lang.Object getTrackerSocket()
throws java.net.SocketException,
java.net.UnknownHostException,
java.io.IOException
java.net.SocketExceptionjava.net.UnknownHostExceptionjava.io.IOExceptionprotected abstract void closeTrackerSocket()
public void initHostList()
throws ProtocolError,
InternalError,
java.net.SocketException,
java.net.UnknownHostException,
java.io.IOException
ProtocolErrorInternalErrorjava.net.SocketExceptionjava.net.UnknownHostExceptionjava.io.IOExceptionprivate byte[] computeHashsum(java.lang.String filename,
HashAlgorithm h)
filename - protected abstract java.lang.Object getHostItemSocket(HostItem hostItem)
hostItem - HostItemprotected abstract void closeHostItemSocket(HostItem hostItem)
hostItem - HostItempublic java.lang.String[] listDirectory()
throws EmptyDirectory,
InternalError,
java.net.UnknownHostException,
java.io.IOException,
TransmissionError,
ProtocolError,
VersionError,
SizeError,
InternalRemoteError,
ProtocolRemoteError,
VersionRemoteError
InternalErrorUnknowHostExceptionjava.io.IOExceptionTransmissionErrorProtocolErrorVersionErrorSizeErrorEmptyDirectoryInternalRemoteErrorProtocolRemoteErrorVersionRemoteErrorjava.net.UnknownHostExceptionprotected abstract void initDownloader(java.lang.String filename)
filename - Name of the file to downloadpublic void download(java.lang.String filename)
throws EmptyFile,
NotFound,
InternalError,
java.net.UnknownHostException,
java.io.IOException,
TransmissionError,
ProtocolError,
VersionError,
SizeError,
InternalRemoteError,
ProtocolRemoteError,
VersionRemoteError
filename - name of the file to downloadNotFoundInternalErrorjava.net.UnknownHostExceptionjava.io.IOExceptionTransmissionErrorProtocolErrorVersionErrorSizeErrorInternalRemoteErrorProtocolRemoteErrorVersionRemoteErrorEmptyFileprotected abstract void writeLog(java.lang.String text,
LogLevel logLevel)
writeLog in class ServeErrorstext - Text to loglogLevel - level of loggingprotected abstract void writeLog(java.lang.Exception e,
LogLevel logLevel)
writeLog in class ServeErrorse - exception to loglogLevel - level of logging