From e77076002912cb6996b52e39a29e8e0588e2434b Mon Sep 17 00:00:00 2001 From: EndMove Date: Sat, 26 Feb 2022 12:25:03 +0100 Subject: [PATCH 01/10] =?UTF-8?q?Id=C3=A9e=20test=20synchronisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lightcontainer/domains/Task.java | 2 +- .../interfaces/StoreProcessorFFE.java | 9 +++++++ .../repository/FileFrontEnd.java | 27 +++++++++++++++++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/lightcontainer/domains/Task.java b/app/src/main/java/lightcontainer/domains/Task.java index 6cd8fc0..45494c8 100644 --- a/app/src/main/java/lightcontainer/domains/Task.java +++ b/app/src/main/java/lightcontainer/domains/Task.java @@ -9,7 +9,7 @@ public class Task { private TaskStatus status; private String command; private String client; - private String store; + private String storeDomain; public Task() { diff --git a/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java b/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java index e6fde95..7a5ffb6 100644 --- a/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java +++ b/app/src/main/java/lightcontainer/interfaces/StoreProcessorFFE.java @@ -1,4 +1,13 @@ package lightcontainer.interfaces; +import lightcontainer.domains.StoreProcessor; + public interface StoreProcessorFFE { + + /** + * Permet à un {@link StoreProcessor} d'avertir le FFE qu'il est disponible + * @param store + */ + void onStoreAvailable(StoreProcessor store); + } diff --git a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java index b4db479..d7dfde2 100644 --- a/app/src/main/java/lightcontainer/repository/FileFrontEnd.java +++ b/app/src/main/java/lightcontainer/repository/FileFrontEnd.java @@ -1,20 +1,43 @@ package lightcontainer.repository; +import lightcontainer.domains.ClientHandler; +import lightcontainer.domains.StoreProcessor; import lightcontainer.domains.Task; import lightcontainer.interfaces.ClientHandlerFFE; import lightcontainer.interfaces.StoreProcessorFFE; +import java.util.Collections; import java.util.Deque; import java.util.LinkedList; +import java.util.concurrent.ConcurrentLinkedDeque; public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE { // Variables - private Deque tasks = new LinkedList<>(); + private Deque tasks = new ConcurrentLinkedDeque<>(); private ClientHandlerRepository clientRepository; // TODO -> pourquoi pas une interface ? end private StoreProcessorRepository storeRepository; // TODO -> pourquoi pas une interface ? end // Constructor - public FileFrontEnd() { + public FileFrontEnd(ClientHandlerRepository clientRepo, StoreProcessorRepository storeRepo) { + this.clientRepository = clientRepo; + this.storeRepository = storeRepo; + } + + /** + * Appelé quand nouvelle tâche + */ + public void alertStoreProcessors(Task task) { + // On avertit les stor processors d'une nouvelle tâche + + } + + /** + * Permet à un {@link StoreProcessor} d'avertir le FFE qu'il est disponible + * + * @param store + */ + @Override + public void onStoreAvailable(StoreProcessor store) { } } From d7b66f092f2128dfc88e82b137f07393eac59c4f Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 12:42:13 +0100 Subject: [PATCH 02/10] =?UTF-8?q?Ajout=20event=20qui=20permet=20aux=20Stor?= =?UTF-8?q?Processor=20de=20pr=C3=A9ciser=20qu'ils=20sont=20disponibles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/lightcontainer/domains/StoreProcessor.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/lightcontainer/domains/StoreProcessor.java b/app/src/main/java/lightcontainer/domains/StoreProcessor.java index fb8ea2c..fc4f721 100644 --- a/app/src/main/java/lightcontainer/domains/StoreProcessor.java +++ b/app/src/main/java/lightcontainer/domains/StoreProcessor.java @@ -67,12 +67,18 @@ public class StoreProcessor implements Runnable, AutoCloseable { public void run() { while (true) { try { + // Envoie donnée au StoreBackEnd String command = this.reader.readLine(); // TODO gestion de la réception de commandes, fichier, ... if (command != null) System.out.println("StoreBackEnd: " + command); + + // Réception donnée du StoreBackEnd } catch (IOException e) { e.printStackTrace(); } + + // Alerter le FileFrontEnd que ce store processor est disponible pour gérer de nouvelle demande + fileFrontEnd.onStoreAvailable(this); } } From ca961c04a7056477207963ea54e2791a4607a604 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 13:08:42 +0100 Subject: [PATCH 03/10] =?UTF-8?q?Cr=C3=A9ation=20interface=20pour=20les=20?= =?UTF-8?q?r=C3=A8gles=20de=20lecture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/ProtocolReader.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 app/src/main/java/lightcontainer/protocol/ProtocolReader.java diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java new file mode 100644 index 0000000..307847d --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java @@ -0,0 +1,24 @@ +package lightcontainer.protocol; + +public interface ProtocolReader { + + + /** + * Permet de récupérer le nom de la commande (ex. FILELIST, SENDRESULT) + */ + String getCmd(); + + /** + * Permet de lancer la décomposition d'une commande pour en extraire les données + * @param data Contenu de la commande + */ + void execute(String data); + + /** + * Permet de demander au protocol s'il capable de décomposer/gérer cette commande + * @param data Commande ("GETFILE" bl filename line) + * @return TRUE si ce protocol peut gérer + */ + boolean match(String data); + +} From c7af99a876d1bb4ab8694ea65d883909482cf780 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 13:27:00 +0100 Subject: [PATCH 04/10] =?UTF-8?q?Cr=C3=A9ation=20r=C3=A8gle=20de=20lecture?= =?UTF-8?q?=20HelloRule.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/HelloRule.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 app/src/main/java/lightcontainer/protocol/rules/HelloRule.java diff --git a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java new file mode 100644 index 0000000..6edb27d --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java @@ -0,0 +1,18 @@ +package lightcontainer.protocol.rules; + +import lightcontainer.protocol.ProtocolReader; + +public class HelloRule extends ProtocolReader { + private static final String PATTERN = "^HELLO ([A-Za-z0-9]{5,20}) ([0-9]{1,5})\r\n$"; + + public HelloRule() { + super(PATTERN); + } + + + @Override + protected void onExecuted(String[] data) { + + } + +} From c1fe6a0a966422604f09259c808ee091f375f694 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 13:37:38 +0100 Subject: [PATCH 05/10] =?UTF-8?q?Modification=20du=20syst=C3=A8me=20de=20P?= =?UTF-8?q?rotocolReader.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/ProtocolReader.java | 36 +++++++++++++------ .../protocol/rules/HelloRule.java | 5 ++- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java index 307847d..472dc0a 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java @@ -1,24 +1,40 @@ package lightcontainer.protocol; -public interface ProtocolReader { +import java.util.regex.Matcher; +import java.util.regex.Pattern; +public abstract class ProtocolReader { - /** - * Permet de récupérer le nom de la commande (ex. FILELIST, SENDRESULT) - */ - String getCmd(); + private final Pattern rulePattern; + + protected ProtocolReader(String pattern) { + this.rulePattern = Pattern.compile(pattern); + } /** * Permet de lancer la décomposition d'une commande pour en extraire les données * @param data Contenu de la commande */ - void execute(String data); + public boolean execute(String data) { + Matcher ruleMatcher = this.rulePattern.matcher(data); + + if (ruleMatcher.matches()) { + String[] groups = new String[ruleMatcher.groupCount()]; + + for (int i= 0; i < groups.length; ++i) + groups[i] = ruleMatcher.group(i); + + onExecuted(groups); + return true; + } + + return false; + } /** - * Permet de demander au protocol s'il capable de décomposer/gérer cette commande - * @param data Commande ("GETFILE" bl filename line) - * @return TRUE si ce protocol peut gérer + * Cette méthode est appelée lors de l'exécution de la règle + * @param data */ - boolean match(String data); + protected abstract void onExecuted(String... data); } diff --git a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java index 6edb27d..529f8f7 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java @@ -11,8 +11,11 @@ public class HelloRule extends ProtocolReader { @Override - protected void onExecuted(String[] data) { + protected void onExecuted(String... data) { + String domain = data[0]; + String port = data[1]; + System.out.printf("Règle Hello avec domain=%s et port=%s", domain, port); } } From d6751210341b6a5ea61d2e22f0949b1882168a5d Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 13:48:46 +0100 Subject: [PATCH 06/10] =?UTF-8?q?Cr=C3=A9ation=20d'un=20test=20pour=20la?= =?UTF-8?q?=20r=C3=A8gle=20HelloRule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/rules/HelloRuleTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java diff --git a/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java b/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java new file mode 100644 index 0000000..8305c90 --- /dev/null +++ b/app/src/test/java/lightcontainer/protocol/rules/HelloRuleTest.java @@ -0,0 +1,20 @@ +package lightcontainer.protocol.rules; + +import lightcontainer.protocol.ProtocolReader; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class HelloRuleTest { + + @Test + public void whenRuleIsRightThenIsExecute() { + // GIVEN + ProtocolReader protocolReader = new HelloRule(); + String request = "HELLO bento 42890\r\n"; + + // EXPECT + assertTrue(protocolReader.execute(request)); + } + +} \ No newline at end of file From 978ba57237bbc1a9c7d2f7ce65eb81e47ee0eadd Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 13:50:36 +0100 Subject: [PATCH 07/10] =?UTF-8?q?-=20HelloRule.java=20:=20Ajout=20retour?= =?UTF-8?q?=20=C3=A0=20la=20ligne=20-=20ProtocolReader.java=20:=20patch=20?= =?UTF-8?q?ajout=20des=20group=20dans=20le=20tableau=20donn=C3=A9=20=C3=A0?= =?UTF-8?q?=20la=20r=C3=A8gle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/protocol/ProtocolReader.java | 4 ++-- .../main/java/lightcontainer/protocol/rules/HelloRule.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java index 472dc0a..1d45c83 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java @@ -21,8 +21,8 @@ public abstract class ProtocolReader { if (ruleMatcher.matches()) { String[] groups = new String[ruleMatcher.groupCount()]; - for (int i= 0; i < groups.length; ++i) - groups[i] = ruleMatcher.group(i); + for (int i = 1; i <= groups.length; ++i) + groups[i - 1] = ruleMatcher.group(i); onExecuted(groups); return true; diff --git a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java index 529f8f7..f4b6c8a 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java @@ -15,7 +15,7 @@ public class HelloRule extends ProtocolReader { String domain = data[0]; String port = data[1]; - System.out.printf("Règle Hello avec domain=%s et port=%s", domain, port); + System.out.printf("Règle Hello avec domain=%s et port=%s\n", domain, port); } } From 90ef2d450e5a4a0114ce68d6572a934f36e67143 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 13:54:16 +0100 Subject: [PATCH 08/10] =?UTF-8?q?-=20HelloRule.java=20:=20Ajout=20constant?= =?UTF-8?q?e=20pour=20position=20des=20donn=C3=A9es=20dans=20le=20tableau?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lightcontainer/protocol/rules/HelloRule.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java index f4b6c8a..589473e 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java @@ -3,8 +3,15 @@ package lightcontainer.protocol.rules; import lightcontainer.protocol.ProtocolReader; public class HelloRule extends ProtocolReader { + private static final String PATTERN = "^HELLO ([A-Za-z0-9]{5,20}) ([0-9]{1,5})\r\n$"; + // Index du domain dans le tableau de donnée + private static final int DOMAIN = 0; + + //Index du port dans le tableau de donnée + private static final int PORT = 1; + public HelloRule() { super(PATTERN); } @@ -12,8 +19,8 @@ public class HelloRule extends ProtocolReader { @Override protected void onExecuted(String... data) { - String domain = data[0]; - String port = data[1]; + String domain = data[DOMAIN]; + String port = data[PORT]; System.out.printf("Règle Hello avec domain=%s et port=%s\n", domain, port); } From baa13b8aa220231430bb31437c3b1fa59a2e5c39 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 13:59:41 +0100 Subject: [PATCH 09/10] =?UTF-8?q?-=20HelloRule.java=20:=20Compression=20r?= =?UTF-8?q?=C3=A9cup=C3=A9ration=20data=20-=20Suppression=20de=20l'ancienn?= =?UTF-8?q?e=20r=C3=A8gle=20HelloRule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/lightcontainer/protocol/rules/HelloRule.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java index 589473e..30acdb9 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/HelloRule.java @@ -19,8 +19,7 @@ public class HelloRule extends ProtocolReader { @Override protected void onExecuted(String... data) { - String domain = data[DOMAIN]; - String port = data[PORT]; + String domain = data[DOMAIN], port = data[PORT]; System.out.printf("Règle Hello avec domain=%s et port=%s\n", domain, port); } From 780c56df11a38953152b894572b123c3b46d57ef Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Feb 2022 14:00:40 +0100 Subject: [PATCH 10/10] =?UTF-8?q?-=20Suppression=20de=20l'ancienne=20r?= =?UTF-8?q?=C3=A8gle=20HelloRule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lightcontainer/protocol/HelloRule.java | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 app/src/main/java/lightcontainer/protocol/HelloRule.java diff --git a/app/src/main/java/lightcontainer/protocol/HelloRule.java b/app/src/main/java/lightcontainer/protocol/HelloRule.java deleted file mode 100644 index c9c2b94..0000000 --- a/app/src/main/java/lightcontainer/protocol/HelloRule.java +++ /dev/null @@ -1,31 +0,0 @@ -package lightcontainer.protocol; - -public class HelloRule extends Protocol { - // Variables - - // Constructor - protected HelloRule() { - super("HELLO", "HELLO "); // TODO : add the regex here (sbe_hello = "HELLO bl domain bl port line") - } - - /** - * Execute the rule on a command. - * - * This function allows you to check a command and process those groups (parameters) - * use the utility functions of {@link Protocol} to facilitate processing, see @see. - * - * @param cmd Command on which to execute the rule. - * @see Protocol#execute(String) - * @see #matcherCheck(String) - * @see #matcherGetGroups() - * @since 1.0 - */ - @Override - public void execute(String cmd) { - if (matcherCheck(cmd)) { - System.out.println("Good rule ;-) !"); - } else { - System.out.println("OUPPS unknown rule !"); - } - } -}