diff --git a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java index 8fb1316..158f308 100644 --- a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java @@ -45,7 +45,6 @@ public class StoreProcessor extends Thread implements AutoCloseable { this.store = socket; this.protocolRep = protocolRep; this.client_run = false; - initStore(); } /** @@ -55,7 +54,7 @@ public class StoreProcessor extends Thread implements AutoCloseable { * @see PrintWriter * @since 1.0 */ - private void initStore() { + public void startStore() { try { this.reader = new BufferedReader(new InputStreamReader( this.store.getInputStream(), diff --git a/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java index 96342f0..fe4b12a 100644 --- a/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java +++ b/app/src/main/java/lightcontainer/domains/server/MulticastServerListener.java @@ -70,13 +70,15 @@ public class MulticastServerListener implements Runnable { HelloRule.Result readerResult = protocolRep.executeReader(null, data); System.out.printf("Nouveau SBE : Domain=%s | Port=%d\n", readerResult.getDomain(), readerResult.getPort()); - Socket socket = new Socket(packet.getAddress(), readerResult.getPort()); + if (!this.repository.hasDomain(readerResult.getDomain())){ + Socket socket = new Socket(packet.getAddress(), readerResult.getPort()); - // Create the store processor - StoreProcessor storeProcessor = new StoreProcessor(socket, readerResult.getDomain(), ffe, protocolRep); // TODO : Voir comment on procède get via repo ou ici ?! + // Create the store processor + StoreProcessor storeProcessor = new StoreProcessor(socket, readerResult.getDomain(), ffe, protocolRep); // TODO : Voir comment on procède get via repo ou ici ?! - // Add the store processor to its repository - this.repository.addStore(storeProcessor); + // Add the store processor to its repository + this.repository.addStore(storeProcessor); + } } catch (IOException ignore) { ignore.printStackTrace(); } diff --git a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java index 5565835..385d556 100644 --- a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java +++ b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java @@ -19,7 +19,7 @@ public interface MulticastSPR { * Add a StorePorcessor. * @param store Store processor to add. */ - void addStore(StoreProcessor store); + boolean addStore(StoreProcessor store); String findDomain(Task task); diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java index e798e27..f5219aa 100644 --- a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java +++ b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java @@ -50,9 +50,12 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { * @since 1.0 */ @Override - public void addStore(StoreProcessor store) { - this.handlers.add(store); - + public boolean addStore(StoreProcessor store) { + if (!this.hasDomain(store.getDomain())) { + store.startStore(); + return this.handlers.add(store); + } + return false; } @Override