94 lines
2.6 KiB
Java
94 lines
2.6 KiB
Java
package lightcontainer.domains;
|
|
|
|
import lightcontainer.domains.client.Context;
|
|
import lightcontainer.enumerations.TaskStatus;
|
|
import lightcontainer.protocol.ProtocolWriter;
|
|
|
|
/**
|
|
* Une tâche exécutable
|
|
*/
|
|
public class Task {
|
|
// Variables
|
|
private TaskStatus status;
|
|
private final ProtocolWriter.ProtocolResult command;
|
|
|
|
|
|
/**
|
|
* Défini le context courant dans laquelle la tâche opère
|
|
*/
|
|
private final Context context;
|
|
|
|
public Task(Context context, TaskStatus status, ProtocolWriter.ProtocolResult command, String requestDomain) {
|
|
this.context = context;
|
|
this.status = status;
|
|
this.command = command;
|
|
context.setDomain(requestDomain); // Domaine requis
|
|
}
|
|
|
|
/**
|
|
* Permet de créer une instance de la class {@link Task}
|
|
*
|
|
* @param context Context à utiliser pour cette tâche
|
|
* @param command Commande à exécuter
|
|
* @return L'instance de la tâche créée
|
|
*/
|
|
public static Task newInstance(Context context, ProtocolWriter.ProtocolResult command, String requestDomain) {
|
|
return new Task(context, TaskStatus.PENDING, command, requestDomain);
|
|
}
|
|
|
|
/**
|
|
* Permet de savoir si la réponse est destinée au client
|
|
*
|
|
* @param storeDomain Nom du store back end fournissant la réponse.
|
|
* @return TRUE si le client doit recevoir cette réponse.
|
|
*/
|
|
public boolean isResponseOfClient(String storeDomain) {
|
|
return (status == TaskStatus.PROCESSING && context.getDomain().equals(storeDomain));
|
|
}
|
|
|
|
/**
|
|
* Permet de récupérer le login du client associé à la tâche
|
|
*
|
|
* @return Login du client
|
|
*/
|
|
public String getClient() {
|
|
return context.getLogin();
|
|
}
|
|
|
|
/**
|
|
* Permet de récupérer la commande à executer
|
|
*
|
|
* @return Commande à exécuter
|
|
*/
|
|
public ProtocolWriter.ProtocolResult getCommand() {
|
|
return this.command;
|
|
}
|
|
|
|
/**
|
|
* Permet de définir le StorBackEnd à utiliser pour cette tâche
|
|
*
|
|
* @param storeDomain Le StorBackEnd à utiliser
|
|
*/
|
|
public void setDomain(String storeDomain) {
|
|
context.setDomain(storeDomain);
|
|
if (storeDomain != null) {
|
|
this.status = TaskStatus.PROCESSING;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Défini le context courrant dans laquelle la tâche opère
|
|
*/
|
|
public Context getContext() {
|
|
return this.context;
|
|
}
|
|
|
|
/**
|
|
* Le domaine actuellement utilisé OU requis, null si aucune domaine requis/associé
|
|
* @return
|
|
*/
|
|
public String getDomain() {
|
|
return context.getDomain();
|
|
}
|
|
}
|