Vérification pour empêche le doublon de Storbackend
This commit is contained in:
parent
9fdc69d75f
commit
9eee080b60
@ -18,10 +18,10 @@ public class App {
|
||||
// -- Unicast client port
|
||||
private static final int UNICAST_PORT = 8500;
|
||||
// -- Multicast listener ip, port
|
||||
private static final String MULTICAST_IP = "226.0.0.1";
|
||||
private static final String MULTICAST_IP = "226.66.66.1";
|
||||
private static final int MULTICAST_PORT = 42500;
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// Create all repository
|
||||
ClientHandlerRepository clientRep = new ClientHandlerRepository();
|
||||
StoreProcessorRepository storeRep = new StoreProcessorRepository();
|
||||
@ -30,11 +30,15 @@ public class App {
|
||||
protocolRep.addReader(new HelloRule());
|
||||
|
||||
new UnicastServerListener(clientRep, UNICAST_PORT);
|
||||
new MulticastServerListener(storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT);
|
||||
|
||||
MulticastServerListener multiCast = new MulticastServerListener(storeRep, protocolRep, MULTICAST_IP, MULTICAST_PORT);
|
||||
multiCast.run();
|
||||
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.StoreProcessorFFE;
|
||||
import java.io.*;
|
||||
import java.net.Socket;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* StoreProcessor
|
||||
@ -21,6 +22,7 @@ import java.nio.charset.StandardCharsets;
|
||||
* @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;
|
||||
@ -30,7 +32,8 @@ public class StoreProcessor implements Runnable, AutoCloseable {
|
||||
private PrintWriter writer;
|
||||
|
||||
// Constructor
|
||||
public StoreProcessor(Socket socket, StoreProcessorFFE ffe) {
|
||||
public StoreProcessor(Socket socket, String domain, StoreProcessorFFE ffe) {
|
||||
this.domain = domain;
|
||||
this.fileFrontEnd = ffe;
|
||||
this.store = socket;
|
||||
this.client_run = false;
|
||||
@ -92,4 +95,17 @@ public class StoreProcessor implements Runnable, AutoCloseable {
|
||||
} catch (IOException ignored) { }
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
StoreProcessor that = (StoreProcessor) o;
|
||||
return Objects.equals(domain, that.domain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(domain);
|
||||
}
|
||||
}
|
||||
|
@ -65,13 +65,16 @@ public class MulticastServerListener implements Runnable {
|
||||
try {
|
||||
// TODO Récupérer le port du message du packet et le setup (add description of the line).
|
||||
HelloRule.Result readerResult = protocolRep.executeReader(data);
|
||||
System.out.printf("Réception en multicast : Domain=%s | Port=%d\n", readerResult.getDomain(), readerResult.getPort());
|
||||
|
||||
Socket socket = new Socket(packet.getAddress(), readerResult.getPort());
|
||||
// Create the store processor
|
||||
StoreProcessor storeProcessor = new StoreProcessor(socket, null); // TODO <!!!> : Voir comment on procède get via repo ou ici ?!
|
||||
StoreProcessor storeProcessor = new StoreProcessor(socket, readerResult.getDomain(), null); // TODO <!!!> : Voir comment on procède get via repo ou ici ?!
|
||||
// Add the store processor to its repository
|
||||
|
||||
this.repository.addStore(storeProcessor);
|
||||
} catch (IOException ignore) {
|
||||
ignore.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
|
@ -45,7 +45,6 @@ public class HelloRule extends ProtocolReader {
|
||||
String domain = data[DOMAIN];
|
||||
int port = Integer.parseInt(data[PORT]);
|
||||
|
||||
System.out.printf("Regle Hello avec domain=%s et port=%s\n", domain, port);
|
||||
return new HelloRule.Result(domain, port);
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,9 @@ 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 ;)
|
||||
/**
|
||||
* StoreProcessorRepository
|
||||
@ -21,12 +23,12 @@ import java.util.List;
|
||||
*/
|
||||
public class StoreProcessorRepository implements AutoCloseable, MulticastSPR {
|
||||
// Variables
|
||||
private final List<StoreProcessor> handlers;
|
||||
private final Set<StoreProcessor> handlers;
|
||||
private MulticastServerListener server;
|
||||
|
||||
// Constructor
|
||||
public StoreProcessorRepository() {
|
||||
this.handlers = new ArrayList<>();
|
||||
this.handlers = new HashSet<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,6 +51,7 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR {
|
||||
@Override
|
||||
public void addStore(StoreProcessor store) {
|
||||
this.handlers.add(store);
|
||||
System.out.println(handlers.size());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user