Trompé en allant sur dev

This commit is contained in:
Benjamin 2022-03-08 08:42:34 +01:00
parent c6f8025d4b
commit b10f1edf54
6 changed files with 31 additions and 1 deletions

View File

@ -178,4 +178,8 @@ public class ClientHandler implements Runnable, AutoCloseable {
} catch (IOException ignored) { } } catch (IOException ignored) { }
} }
} }
public String getLogin() {
return this.login;
}
} }

View File

@ -1,5 +1,6 @@
package lightcontainer.domains.client; package lightcontainer.domains.client;
import lightcontainer.domains.Task;
import lightcontainer.interfaces.ProtocolRepository; import lightcontainer.interfaces.ProtocolRepository;
import lightcontainer.interfaces.StoreProcessorFFE; import lightcontainer.interfaces.StoreProcessorFFE;
import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.ProtocolReader;
@ -170,4 +171,8 @@ public class StoreProcessor extends Thread implements AutoCloseable {
public int hashCode() { public int hashCode() {
return Objects.hash(domain); return Objects.hash(domain);
} }
public boolean canProcessTask(Task task) {
return this.currentCommand == null; // Vérifier si tâche veut ce SBE
}
} }

View File

@ -1,5 +1,6 @@
package lightcontainer.interfaces; package lightcontainer.interfaces;
import lightcontainer.domains.Task;
import lightcontainer.domains.client.StoreProcessor; import lightcontainer.domains.client.StoreProcessor;
import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.domains.server.MulticastServerListener;
import lightcontainer.repository.StoreProcessorRepository; import lightcontainer.repository.StoreProcessorRepository;
@ -19,4 +20,6 @@ public interface MulticastSPR {
* @param store Store processor to add. * @param store Store processor to add.
*/ */
void addStore(StoreProcessor store); void addStore(StoreProcessor store);
String findSBE(Task task);
} }

View File

@ -58,7 +58,10 @@ public class ClientHandlerRepository implements AutoCloseable, UnicastCHR {
@Override @Override
public void respondToClient(String login, ProtocolWriter.ProtocolResult response) { public void respondToClient(String login, ProtocolWriter.ProtocolResult response) {
for (ClientHandler client : handlers) { for (ClientHandler client : handlers) {
if (client.getLogin().equals(login)) {
client.respond(response); client.respond(response);
break;
}
} }
} }

View File

@ -30,6 +30,7 @@ public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
*/ */
public void alertStoreProcessors(Task task) { public void alertStoreProcessors(Task task) {
// On avertit les stor processors d'une nouvelle tâche // 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 // TODO : Ajouter la tâche - Alerter les StorBackEnds
Task task = Task.newInstance(command, client); Task task = Task.newInstance(command, client);
tasks.add(task); tasks.add(task);
alertStoreProcessors(task);
} }
} }

View File

@ -1,5 +1,6 @@
package lightcontainer.repository; package lightcontainer.repository;
import lightcontainer.domains.Task;
import lightcontainer.domains.client.StoreProcessor; import lightcontainer.domains.client.StoreProcessor;
import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.domains.server.MulticastServerListener;
import lightcontainer.interfaces.MulticastSPR; import lightcontainer.interfaces.MulticastSPR;
@ -53,6 +54,18 @@ public class StoreProcessorRepository implements AutoCloseable, MulticastSPR {
this.handlers.add(store); 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 * AutoClosable Function
* Closes all StoreProcessor stored in this repository and deallocates all resources. * Closes all StoreProcessor stored in this repository and deallocates all resources.