2020-01-14 11:10:11 +01:00
|
|
|
package clientP2P;
|
2020-03-19 17:49:39 +01:00
|
|
|
|
|
|
|
import java.util.Scanner;
|
2020-01-25 17:48:21 +01:00
|
|
|
import protocolP2P.Payload;
|
2020-03-22 16:55:05 +01:00
|
|
|
import protocolP2P.ProtocolP2PPacket;
|
|
|
|
import protocolP2P.ProtocolP2PPacketUDP;
|
2020-03-19 17:49:39 +01:00
|
|
|
import tools.HostItem;
|
|
|
|
import tools.Logger;
|
|
|
|
import tools.LogLevel;
|
2020-03-12 17:52:31 +01:00
|
|
|
import clientP2P.ClientDownloadUDP;
|
2020-03-22 16:55:05 +01:00
|
|
|
import clientP2P.ClientManagement;
|
2020-01-12 23:29:49 +01:00
|
|
|
|
2020-01-25 17:48:21 +01:00
|
|
|
/** Implementation of P2P-JAVA-PROJECT CLIENT
|
2020-01-12 23:29:49 +01:00
|
|
|
* @author Louis Royer
|
|
|
|
* @author Flavien Haas
|
|
|
|
* @author JS Auge
|
|
|
|
* @version 1.0
|
|
|
|
*/
|
2020-03-22 16:55:05 +01:00
|
|
|
public class ClientManagementUDP extends ClientManagement {
|
2020-03-21 15:48:18 +01:00
|
|
|
/** Constructor for UDP implementation, with baseDirectory, tracker, partsSubdir, logger and scanner parameters.
|
2020-01-12 23:29:49 +01:00
|
|
|
* @param baseDirectory the root directory where files are stored
|
2020-03-21 15:48:18 +01:00
|
|
|
* @param tracker tracker HostItem
|
|
|
|
* @param partsSubdir subdirectory to store file parts
|
|
|
|
* @param logger Loggger
|
|
|
|
* @param scanner Scanner used to read input
|
2020-03-27 16:22:42 +01:00
|
|
|
* @param client HostItem of the application
|
2020-01-12 23:29:49 +01:00
|
|
|
*/
|
2020-03-27 16:22:42 +01:00
|
|
|
public ClientManagementUDP(String baseDirectory, HostItem tracker, String partsSubdir, Logger logger, Scanner scanner, HostItem client) {
|
|
|
|
super(baseDirectory, tracker, partsSubdir, logger, scanner, client);
|
2020-03-22 16:55:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Initialize downloader
|
|
|
|
* @param filename Name of the file to download
|
|
|
|
*/
|
|
|
|
protected void initDownloader(String filename) {
|
2020-03-27 16:22:42 +01:00
|
|
|
downLoader = (ClientDownload) new ClientDownloadUDP(filename, hostList, partsSubdir, baseDirectory, logger, client);
|
2020-03-22 16:55:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Implementation of writeLog
|
|
|
|
* @param text Text to log
|
|
|
|
* @param logLevel level of logging
|
|
|
|
*/
|
|
|
|
protected void writeLog(String text, LogLevel logLevel) {
|
|
|
|
logger.writeUDP(text, logLevel);
|
2020-01-12 23:29:49 +01:00
|
|
|
}
|
|
|
|
|
2020-03-22 16:55:05 +01:00
|
|
|
/** Implementation of writeLog
|
|
|
|
* @param e exception to log
|
|
|
|
* @param logLevel level of logging
|
2020-01-12 23:29:49 +01:00
|
|
|
*/
|
2020-03-22 16:55:05 +01:00
|
|
|
protected void writeLog(Exception e, LogLevel logLevel) {
|
|
|
|
logger.writeUDP(e, logLevel);
|
2020-01-12 23:29:49 +01:00
|
|
|
}
|
|
|
|
|
2020-03-22 16:55:05 +01:00
|
|
|
/** Create packets
|
|
|
|
* @param payload Payload
|
2020-01-12 23:29:49 +01:00
|
|
|
*/
|
2020-03-22 16:55:05 +01:00
|
|
|
protected < T extends Payload > ProtocolP2PPacket<T> createProtocolP2PPacket(T payload) {
|
|
|
|
return (ProtocolP2PPacket<T>)new ProtocolP2PPacketUDP<T>(payload);
|
2020-01-12 23:29:49 +01:00
|
|
|
}
|
2020-01-14 11:10:11 +01:00
|
|
|
|
2020-03-22 16:55:05 +01:00
|
|
|
/** Getter for tracker socket
|
2020-01-12 23:29:49 +01:00
|
|
|
*/
|
2020-03-22 16:55:05 +01:00
|
|
|
protected Object getTrackerSocket() {
|
|
|
|
return (Object)tracker.getUDPSocket();
|
2020-01-12 23:29:49 +01:00
|
|
|
}
|
2020-03-04 22:29:54 +01:00
|
|
|
|
2020-03-22 16:55:05 +01:00
|
|
|
/** Getter for HostItem socket
|
|
|
|
* @param hostItem HostItem
|
2020-03-04 22:29:54 +01:00
|
|
|
*/
|
2020-03-22 16:55:05 +01:00
|
|
|
protected Object getHostItemSocket(HostItem hostItem) {
|
|
|
|
return (Object)hostItem.getUDPSocket();
|
2020-03-04 22:29:54 +01:00
|
|
|
}
|
2020-03-21 15:48:18 +01:00
|
|
|
|
2020-03-22 16:55:05 +01:00
|
|
|
/** Close HostItem socket
|
|
|
|
* @param hostItem HostItem
|
2020-03-21 15:48:18 +01:00
|
|
|
*/
|
2020-03-22 16:55:05 +01:00
|
|
|
protected void closeHostItemSocket(HostItem hostItem) {
|
|
|
|
hostItem.closeUDPSocket();
|
2020-03-21 15:48:18 +01:00
|
|
|
}
|
2020-01-12 23:29:49 +01:00
|
|
|
}
|