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) { }
}
}
public String getLogin() {
return this.login;
}
}

View File

@ -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
}
}

View File

@ -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);
}

View File

@ -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;
}
}
}

View File

@ -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);
}
}

View File

@ -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.