diff --git a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java index b75ade2..5cda294 100644 --- a/app/src/main/java/lightcontainer/domains/client/ClientHandler.java +++ b/app/src/main/java/lightcontainer/domains/client/ClientHandler.java @@ -178,4 +178,8 @@ public class ClientHandler implements Runnable, AutoCloseable { } catch (IOException ignored) { } } } + + public String getLogin() { + return this.login; + } } diff --git a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java index 450eb35..b18f7c7 100644 --- a/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/client/StoreProcessor.java @@ -1,5 +1,6 @@ package lightcontainer.domains.client; +import lightcontainer.domains.Task; import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.interfaces.StoreProcessorFFE; import lightcontainer.protocol.ProtocolReader; @@ -170,4 +171,8 @@ public class StoreProcessor extends Thread implements AutoCloseable { public int hashCode() { return Objects.hash(domain); } + + public boolean canProcessTask(Task task) { + return this.currentCommand == null; // Vérifier si tâche veut ce SBE + } } diff --git a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java index b2108ec..cdd97dc 100644 --- a/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java +++ b/app/src/main/java/lightcontainer/interfaces/MulticastSPR.java @@ -1,5 +1,6 @@ package lightcontainer.interfaces; +import lightcontainer.domains.Task; import lightcontainer.domains.client.StoreProcessor; import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.repository.StoreProcessorRepository; @@ -19,4 +20,6 @@ public interface MulticastSPR { * @param store Store processor to add. */ void addStore(StoreProcessor store); + + String findSBE(Task task); } diff --git a/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java index db1462d..416988c 100644 --- a/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java +++ b/app/src/main/java/lightcontainer/repository/ClientHandlerRepository.java @@ -58,7 +58,10 @@ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR { @Override public void respondToClient(String login, ProtocolWriter.ProtocolResult response) { for (ClientHandler client : handlers) { - client.respond(response); + if (client.getLogin().equals(login)) { + client.respond(response); + break; + } } } diff --git a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java index bcd226e..e29eb18 100644 --- a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java +++ b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java @@ -30,6 +30,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { */ public void alertStoreProcessors(Task task) { // On avertit les stor processors d'une nouvelle tâche + String stor = storeRepository.findSBE(task); } @@ -58,5 +59,6 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { // TODO : Ajouter la tâche - Alerter les StorBackEnds Task task = Task.newInstance(command, client); tasks.add(task); + alertStoreProcessors(task); } } diff --git a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java index 7132a74..e0bfea6 100644 --- a/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java +++ b/app/src/main/java/lightcontainer/repository/StoreProcessorRepository.java @@ -1,5 +1,6 @@ package lightcontainer.repository; +import lightcontainer.domains.Task; import lightcontainer.domains.client.StoreProcessor; import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.interfaces.MulticastSPR; @@ -53,6 +54,18 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR { this.handlers.add(store); } + @Override + public String findSBE(Task task) { + + for (StoreProcessor handler : handlers) { + if (handler.canProcessTask(task)) { + return handler.getName(); + } + } + + return null; + } + /** * AutoClosable Function * Closes all StoreProcessor stored in this repository and deallocates all resources.