Java code style
This commit is contained in:
parent
ad41d5aeea
commit
40dd0c2bc5
@ -23,16 +23,15 @@ public class ServerP2P {
|
|||||||
private Logger logger;
|
private Logger logger;
|
||||||
private HostItem tracker;
|
private HostItem tracker;
|
||||||
private HostItem server;
|
private HostItem server;
|
||||||
private boolean isinteractive;
|
|
||||||
|
|
||||||
/** Constructor with portServerstr containing a port number.
|
/** Constructor with portServerstr containing a port number.
|
||||||
* @param hostnameServer binded hostname
|
* @param hostnameServer binded hostname
|
||||||
* @param portServer binded port
|
* @param portServer binded port
|
||||||
* @param hostnameTracker tracker hostname
|
* @param hostnameTracker tracker hostname
|
||||||
* @param portTracker tracker port
|
* @param portTracker tracker port
|
||||||
|
* @param isInteractive true if application in interactive mode
|
||||||
*/
|
*/
|
||||||
public ServerP2P(String hostnameServer, int portServer, String hostnameTracker, int portTracker, boolean isinteractive) {
|
public ServerP2P(String hostnameServer, int portServer, String hostnameTracker, int portTracker, boolean isInteractive) {
|
||||||
this.isinteractive = isinteractive;
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
server = new HostItem(hostnameServer, portServer);
|
server = new HostItem(hostnameServer, portServer);
|
||||||
tracker = new HostItem(hostnameTracker, portTracker);
|
tracker = new HostItem(hostnameTracker, portTracker);
|
||||||
@ -40,7 +39,7 @@ public class ServerP2P {
|
|||||||
directories.createSubdir(subdir);
|
directories.createSubdir(subdir);
|
||||||
logger = new Logger(directories.getDataHomeDirectory() + "server.log");
|
logger = new Logger(directories.getDataHomeDirectory() + "server.log");
|
||||||
System.out.println("Server will listen on port " + portServer + " and serve files from " + directories.getDataHomeDirectory() + subdir);
|
System.out.println("Server will listen on port " + portServer + " and serve files from " + directories.getDataHomeDirectory() + subdir);
|
||||||
if(isinteractive){
|
if(isInteractive){
|
||||||
directories.askOpenDataHomeDirectory(subdir, scanner);
|
directories.askOpenDataHomeDirectory(subdir, scanner);
|
||||||
}
|
}
|
||||||
scanner.close();
|
scanner.close();
|
||||||
@ -60,7 +59,7 @@ public class ServerP2P {
|
|||||||
String hostnameTracker = "";
|
String hostnameTracker = "";
|
||||||
int portTracker = 0;
|
int portTracker = 0;
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
boolean isinteractive = false;
|
boolean isInteractive = false;
|
||||||
|
|
||||||
if ((args.length != 5) && (args.length != 0)){
|
if ((args.length != 5) && (args.length != 0)){
|
||||||
System.out.println("usage : java serveurP2P.ServeurP2P (interactive) or java serveurP2P.ServeurP2P -- <serveurHOSTNAME> <serveurPORT> <trackerHOSTNAME> <trackerPORT> (" + serverPortRange + " and " + trackerPortRange +")");
|
System.out.println("usage : java serveurP2P.ServeurP2P (interactive) or java serveurP2P.ServeurP2P -- <serveurHOSTNAME> <serveurPORT> <trackerHOSTNAME> <trackerPORT> (" + serverPortRange + " and " + trackerPortRange +")");
|
||||||
@ -72,7 +71,7 @@ public class ServerP2P {
|
|||||||
hostnameTracker = args[3];
|
hostnameTracker = args[3];
|
||||||
portTracker = Integer.valueOf(Integer.parseInt(args[4]));
|
portTracker = Integer.valueOf(Integer.parseInt(args[4]));
|
||||||
} else {
|
} else {
|
||||||
isinteractive = true;
|
isInteractive = true;
|
||||||
System.out.println("Server, enter hostname to bind (default = localhost): ");
|
System.out.println("Server, enter hostname to bind (default = localhost): ");
|
||||||
hostnameServer = scanner.nextLine();
|
hostnameServer = scanner.nextLine();
|
||||||
if(hostnameServer.equals("")){
|
if(hostnameServer.equals("")){
|
||||||
@ -109,7 +108,7 @@ public class ServerP2P {
|
|||||||
System.out.println("using port : " + portServer);
|
System.out.println("using port : " + portServer);
|
||||||
System.out.println("tracker hostname : " + hostnameTracker);
|
System.out.println("tracker hostname : " + hostnameTracker);
|
||||||
System.out.println("tracker port : " + portTracker);
|
System.out.println("tracker port : " + portTracker);
|
||||||
ServerP2P s = new ServerP2P(hostnameServer, portServer, hostnameTracker, portTracker, isinteractive);
|
ServerP2P s = new ServerP2P(hostnameServer, portServer, hostnameTracker, portTracker, isInteractive);
|
||||||
ServerManagementUDP smudp = new ServerManagementUDP(s.directories.getDataHomeDirectory() + subdir, s.server, s.tracker, s.logger);
|
ServerManagementUDP smudp = new ServerManagementUDP(s.directories.getDataHomeDirectory() + subdir, s.server, s.tracker, s.logger);
|
||||||
ServerManagementTCP smtcp = new ServerManagementTCP(s.directories.getDataHomeDirectory() + subdir, s.server, s.tracker, s.logger);
|
ServerManagementTCP smtcp = new ServerManagementTCP(s.directories.getDataHomeDirectory() + subdir, s.server, s.tracker, s.logger);
|
||||||
Thread tudp = new Thread(smudp);
|
Thread tudp = new Thread(smudp);
|
||||||
|
@ -20,20 +20,19 @@ public class Tracker {
|
|||||||
private HostItem tracker;
|
private HostItem tracker;
|
||||||
private Directories directories;
|
private Directories directories;
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
private boolean isinteractive;
|
|
||||||
|
|
||||||
/** Constructor with portStr containing a port number.
|
/** Constructor with portStr containing a port number.
|
||||||
* @param hostname hostname to bind
|
* @param hostname hostname to bind
|
||||||
* @param port port to bind
|
* @param port port to bind
|
||||||
|
* @param isInteractive true if application is in interactive mode
|
||||||
*/
|
*/
|
||||||
public Tracker(String hostname, int port, boolean isinteractive) {
|
public Tracker(String hostname, int port, boolean isInteractive) {
|
||||||
this.isinteractive = isinteractive;
|
|
||||||
tracker = new HostItem(hostname, port);
|
tracker = new HostItem(hostname, port);
|
||||||
directories = new Directories("P2P_JAVA_PROJECT_TRACKER_" + port);
|
directories = new Directories("P2P_JAVA_PROJECT_TRACKER_" + port);
|
||||||
logger = new Logger(directories.getDataHomeDirectory() + "tracker.log");
|
logger = new Logger(directories.getDataHomeDirectory() + "tracker.log");
|
||||||
System.out.println("Tracker will listen on port " + port + " and write logs into " + directories.getDataHomeDirectory());
|
System.out.println("Tracker will listen on port " + port + " and write logs into " + directories.getDataHomeDirectory());
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
if(isinteractive){
|
if(isInteractive){
|
||||||
directories.askOpenDataHomeDirectory(null, scanner);
|
directories.askOpenDataHomeDirectory(null, scanner);
|
||||||
}
|
}
|
||||||
scanner.close();
|
scanner.close();
|
||||||
@ -51,7 +50,7 @@ public class Tracker {
|
|||||||
String hostname = "";
|
String hostname = "";
|
||||||
int port = 0;
|
int port = 0;
|
||||||
Tracker t;
|
Tracker t;
|
||||||
boolean isinteractive = false;
|
boolean isInteractive = false;
|
||||||
|
|
||||||
if ((args.length != 3) && (args.length != 0)){
|
if ((args.length != 3) && (args.length != 0)){
|
||||||
System.out.println("usage : java tracker.Tracker (interactive) or java trackerP2P.trackerP2P -- <hostname> <PORT> (" + trackerPortRange +")");
|
System.out.println("usage : java tracker.Tracker (interactive) or java trackerP2P.trackerP2P -- <hostname> <PORT> (" + trackerPortRange +")");
|
||||||
@ -60,7 +59,7 @@ public class Tracker {
|
|||||||
hostname = args[1];
|
hostname = args[1];
|
||||||
port = Integer.valueOf(Integer.parseInt(args[2]));
|
port = Integer.valueOf(Integer.parseInt(args[2]));
|
||||||
} else {
|
} else {
|
||||||
isinteractive = true;
|
isInteractive = true;
|
||||||
System.out.println("Tracker Server, enter hostname to bind (default = localhost): ");
|
System.out.println("Tracker Server, enter hostname to bind (default = localhost): ");
|
||||||
hostname = scanner.nextLine();
|
hostname = scanner.nextLine();
|
||||||
if(hostname.equals("")){
|
if(hostname.equals("")){
|
||||||
@ -80,7 +79,7 @@ public class Tracker {
|
|||||||
System.out.println("using hostname : " + hostname);
|
System.out.println("using hostname : " + hostname);
|
||||||
if(trackerPortRange.isPortInRange(port)) {
|
if(trackerPortRange.isPortInRange(port)) {
|
||||||
System.out.println("using port : " + port);
|
System.out.println("using port : " + port);
|
||||||
t = new Tracker(hostname, port, isinteractive);
|
t = new Tracker(hostname, port, isInteractive);
|
||||||
TrackerManagementUDP tmudp = new TrackerManagementUDP(t.tracker, t.logger);
|
TrackerManagementUDP tmudp = new TrackerManagementUDP(t.tracker, t.logger);
|
||||||
TrackerManagementTCP tmtcp = new TrackerManagementTCP(t.tracker, t.logger);
|
TrackerManagementTCP tmtcp = new TrackerManagementTCP(t.tracker, t.logger);
|
||||||
Thread tudp = new Thread(tmudp);
|
Thread tudp = new Thread(tmudp);
|
||||||
|
Loading…
Reference in New Issue
Block a user