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());
|
||||
|
||||
new UnicastServerListener(clientRep, UNICAST_PORT);
|
||||
MulticastServerListener multiCast = new MulticastServerListener(storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT);
|
||||
multiCast.run();
|
||||
new MulticastServerListener(storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT);
|
||||
FileFrontEnd ffe = new FileFrontEnd(clientRep, storeRep);
|
||||
|
||||
// close repo et client et server.
|
||||
|
||||
Thread.sleep(60000);
|
||||
|
||||
multiCast.stop();
|
||||
clientRep.close();
|
||||
storeRep.close();
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import lightcontainer.interfaces.ClientHandlerFFE;
|
||||
import java.io.*;
|
||||
import java.net.Socket;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* ClientHandler
|
||||
|
@ -22,10 +22,10 @@ import java.util.Objects;
|
||||
* @author Jérémi NIHART <j.nihart@student.helmo.be>
|
||||
*/
|
||||
public class StoreProcessor implements Runnable, AutoCloseable {
|
||||
private String domain;
|
||||
// Variables
|
||||
private final StoreProcessorFFE fileFrontEnd;
|
||||
private final Socket store;
|
||||
private final String domain;
|
||||
private boolean client_run;
|
||||
|
||||
private BufferedReader reader;
|
||||
@ -96,6 +96,9 @@ public class StoreProcessor implements Runnable, AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two StoreProcessor object to check if equals.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
@ -104,6 +107,9 @@ public class StoreProcessor implements Runnable, AutoCloseable {
|
||||
return Objects.equals(domain, that.domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get hash code
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(domain);
|
||||
|
@ -4,14 +4,14 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public abstract class ProtocolReader {
|
||||
|
||||
// Variables
|
||||
private final Pattern rulePattern;
|
||||
|
||||
// Constructor
|
||||
protected ProtocolReader(String pattern) {
|
||||
this.rulePattern = Pattern.compile(pattern);
|
||||
}
|
||||
|
||||
|
||||
public abstract class ProtocolResult {}
|
||||
|
||||
/**
|
||||
@ -27,17 +27,14 @@ public abstract class ProtocolReader {
|
||||
for (int i = 1; i <= groups.length; ++i)
|
||||
groups[i - 1] = ruleMatcher.group(i);
|
||||
|
||||
|
||||
return onExecuted(groups);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
}
|
||||
|
@ -5,19 +5,19 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public abstract class ProtocolWriter {
|
||||
|
||||
// Variables
|
||||
private final Pattern rulePattern;
|
||||
private final String cmdName;
|
||||
|
||||
|
||||
// Constructor
|
||||
protected ProtocolWriter(String cmdName, String pattern) {
|
||||
this.rulePattern = Pattern.compile(pattern);
|
||||
this.cmdName = cmdName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de récupérer le nom du protocol
|
||||
* @return
|
||||
* Permet de récupérer le nom de la commande.
|
||||
* @return Nom de la commande.
|
||||
*/
|
||||
public String getCmdName() {
|
||||
return cmdName;
|
||||
@ -25,16 +25,16 @@ public abstract class ProtocolWriter {
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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
|
||||
String command = null;
|
||||
String command;
|
||||
StringJoiner builder = new StringJoiner(" ", this.cmdName, "\r\n");
|
||||
|
||||
for (String data : datas)
|
||||
builder.add(data);
|
||||
for (String param : data)
|
||||
builder.add(param);
|
||||
|
||||
command = builder.toString();
|
||||
|
||||
|
@ -23,9 +23,9 @@ public class ProtocolRepositoryImpl implements ProtocolRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String executeWriter(String... datas) {
|
||||
public String executeWriter(String... data) {
|
||||
for (ProtocolWriter writer : writers) {
|
||||
String command = writer.execute(datas);
|
||||
String command = writer.execute(data);
|
||||
if (command != null) {
|
||||
return command;
|
||||
}
|
||||
|
@ -4,9 +4,7 @@ import lightcontainer.domains.client.StoreProcessor;
|
||||
import lightcontainer.domains.server.MulticastServerListener;
|
||||
import lightcontainer.interfaces.MulticastSPR;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
// TODO : C'est genre un ClientHandlerManager quoi hein, normal qu'il fasse blinder de chose ;)
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user