Optimization of server startup, deletion of my benjamin's balls space. Some bug fixes
This commit is contained in:
parent
c38743383f
commit
06fb0086fb
@ -30,15 +30,13 @@ public class App {
|
|||||||
protocolRep.addReader(new HelloRule());
|
protocolRep.addReader(new HelloRule());
|
||||||
|
|
||||||
new UnicastServerListener(clientRep, UNICAST_PORT);
|
new UnicastServerListener(clientRep, UNICAST_PORT);
|
||||||
MulticastServerListener multiCast = new MulticastServerListener(storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT);
|
new MulticastServerListener(storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT);
|
||||||
multiCast.run();
|
|
||||||
FileFrontEnd ffe = new FileFrontEnd(clientRep, storeRep);
|
FileFrontEnd ffe = new FileFrontEnd(clientRep, storeRep);
|
||||||
|
|
||||||
// close repo et client et server.
|
// close repo et client et server.
|
||||||
|
|
||||||
Thread.sleep(60000);
|
Thread.sleep(60000);
|
||||||
|
|
||||||
multiCast.stop();
|
|
||||||
clientRep.close();
|
clientRep.close();
|
||||||
storeRep.close();
|
storeRep.close();
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import lightcontainer.interfaces.ClientHandlerFFE;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ClientHandler
|
* ClientHandler
|
||||||
|
@ -22,10 +22,10 @@ import java.util.Objects;
|
|||||||
* @author Jérémi NIHART <j.nihart@student.helmo.be>
|
* @author Jérémi NIHART <j.nihart@student.helmo.be>
|
||||||
*/
|
*/
|
||||||
public class StoreProcessor implements Runnable, AutoCloseable {
|
public class StoreProcessor implements Runnable, AutoCloseable {
|
||||||
private String domain;
|
|
||||||
// Variables
|
// Variables
|
||||||
private final StoreProcessorFFE fileFrontEnd;
|
private final StoreProcessorFFE fileFrontEnd;
|
||||||
private final Socket store;
|
private final Socket store;
|
||||||
|
private final String domain;
|
||||||
private boolean client_run;
|
private boolean client_run;
|
||||||
|
|
||||||
private BufferedReader reader;
|
private BufferedReader reader;
|
||||||
@ -96,6 +96,9 @@ public class StoreProcessor implements Runnable, AutoCloseable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare two StoreProcessor object to check if equals.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
@ -104,6 +107,9 @@ public class StoreProcessor implements Runnable, AutoCloseable {
|
|||||||
return Objects.equals(domain, that.domain);
|
return Objects.equals(domain, that.domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get hash code
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(domain);
|
return Objects.hash(domain);
|
||||||
|
@ -4,14 +4,14 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public abstract class ProtocolReader {
|
public abstract class ProtocolReader {
|
||||||
|
// Variables
|
||||||
private final Pattern rulePattern;
|
private final Pattern rulePattern;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
protected ProtocolReader(String pattern) {
|
protected ProtocolReader(String pattern) {
|
||||||
this.rulePattern = Pattern.compile(pattern);
|
this.rulePattern = Pattern.compile(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public abstract class ProtocolResult {}
|
public abstract class ProtocolResult {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,17 +27,14 @@ public abstract class ProtocolReader {
|
|||||||
for (int i = 1; i <= groups.length; ++i)
|
for (int i = 1; i <= groups.length; ++i)
|
||||||
groups[i - 1] = ruleMatcher.group(i);
|
groups[i - 1] = ruleMatcher.group(i);
|
||||||
|
|
||||||
|
|
||||||
return onExecuted(groups);
|
return onExecuted(groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cette méthode est appelée lors de l'exécution de la règle
|
* Cette méthode est appelée lors de l'exécution de la règle
|
||||||
* @param data
|
* @param data Paramètres pour créer la commande.
|
||||||
*/
|
*/
|
||||||
protected abstract <T> T onExecuted(String... data);
|
protected abstract <T> T onExecuted(String... data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,19 +5,19 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public abstract class ProtocolWriter {
|
public abstract class ProtocolWriter {
|
||||||
|
// Variables
|
||||||
private final Pattern rulePattern;
|
private final Pattern rulePattern;
|
||||||
private final String cmdName;
|
private final String cmdName;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
protected ProtocolWriter(String cmdName, String pattern) {
|
protected ProtocolWriter(String cmdName, String pattern) {
|
||||||
this.rulePattern = Pattern.compile(pattern);
|
this.rulePattern = Pattern.compile(pattern);
|
||||||
this.cmdName = cmdName;
|
this.cmdName = cmdName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de récupérer le nom du protocol
|
* Permet de récupérer le nom de la commande.
|
||||||
* @return
|
* @return Nom de la commande.
|
||||||
*/
|
*/
|
||||||
public String getCmdName() {
|
public String getCmdName() {
|
||||||
return cmdName;
|
return cmdName;
|
||||||
@ -25,16 +25,16 @@ public abstract class ProtocolWriter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Permet de contruire une commande selon une règle établie.
|
* Permet de contruire une commande selon une règle établie.
|
||||||
* @param datas Les données à ajouter dans la commande; L'ordre défini leur position dans la commande
|
* @param data Les données à ajouter dans la commande; L'ordre défini leur position dans la commande
|
||||||
* @return La commande construite
|
* @return La commande construite
|
||||||
*/
|
*/
|
||||||
public String execute(String... datas) {
|
public String execute(String... data) {
|
||||||
// Concatatène le nom de la commande avec les données (trim), avec un espace entre chaque
|
// Concatatène le nom de la commande avec les données (trim), avec un espace entre chaque
|
||||||
String command = null;
|
String command;
|
||||||
StringJoiner builder = new StringJoiner(" ", this.cmdName, "\r\n");
|
StringJoiner builder = new StringJoiner(" ", this.cmdName, "\r\n");
|
||||||
|
|
||||||
for (String data : datas)
|
for (String param : data)
|
||||||
builder.add(data);
|
builder.add(param);
|
||||||
|
|
||||||
command = builder.toString();
|
command = builder.toString();
|
||||||
|
|
||||||
|
@ -23,9 +23,9 @@ public class ProtocolRepositoryImpl implements ProtocolRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String executeWriter(String... datas) {
|
public String executeWriter(String... data) {
|
||||||
for (ProtocolWriter writer : writers) {
|
for (ProtocolWriter writer : writers) {
|
||||||
String command = writer.execute(datas);
|
String command = writer.execute(data);
|
||||||
if (command != null) {
|
if (command != null) {
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,7 @@ import lightcontainer.domains.client.StoreProcessor;
|
|||||||
import lightcontainer.domains.server.MulticastServerListener;
|
import lightcontainer.domains.server.MulticastServerListener;
|
||||||
import lightcontainer.interfaces.MulticastSPR;
|
import lightcontainer.interfaces.MulticastSPR;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
// TODO : C'est genre un ClientHandlerManager quoi hein, normal qu'il fasse blinder de chose ;)
|
// TODO : C'est genre un ClientHandlerManager quoi hein, normal qu'il fasse blinder de chose ;)
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user