Mise en place d'un système pour autoclose le ClientHandler et StoreProcessor + quelques corrections + avancée mineures
This commit is contained in:
parent
306a10c441
commit
083586682f
@ -6,13 +6,24 @@ import java.io.*;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
/**TODO
|
/**
|
||||||
* Connexion avec le client. (type server)
|
* ClientHandler
|
||||||
|
*
|
||||||
|
* Class communicating with the client, and
|
||||||
|
* intercepting and sending files to the client.
|
||||||
|
*
|
||||||
|
* @version 1.0
|
||||||
|
* @since 1.0
|
||||||
|
*
|
||||||
|
* @see Runnable
|
||||||
|
* @see AutoCloseable
|
||||||
|
* @author Jérémi NIHART <j.nihart@student.helmo.be>
|
||||||
*/
|
*/
|
||||||
public class ClientHandler implements Runnable {
|
public class ClientHandler implements Runnable, AutoCloseable {
|
||||||
// Variables
|
// Variables
|
||||||
private ClientHandlerFFE fileFrontEnd;
|
private ClientHandlerFFE fileFrontEnd;
|
||||||
private final Socket client;
|
private final Socket client;
|
||||||
|
|
||||||
private BufferedReader reader;
|
private BufferedReader reader;
|
||||||
private PrintWriter writer;
|
private PrintWriter writer;
|
||||||
|
|
||||||
@ -24,7 +35,12 @@ public class ClientHandler implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes socket input/output
|
* Initialise the Client's Reader and Writer.
|
||||||
|
*
|
||||||
|
* @since 1.0
|
||||||
|
*
|
||||||
|
* @see BufferedReader
|
||||||
|
* @see PrintWriter
|
||||||
*/
|
*/
|
||||||
private void initClient() {
|
private void initClient() {
|
||||||
try {
|
try {
|
||||||
@ -41,17 +57,33 @@ public class ClientHandler implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Thread Function
|
/**
|
||||||
|
* Thread Function
|
||||||
|
* Start the dialogue with the client.
|
||||||
|
*
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
String command = this.reader.readLine();
|
String command = this.reader.readLine();
|
||||||
// TODO gestion de la réception de commandes, fichier, ...
|
// TODO gestion de la réception de commandes, fichier, ...
|
||||||
if (command != null) System.out.println(command);
|
if (command != null) System.out.println("Client: " + command);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AutoClosable Function
|
||||||
|
* Close the Client thread and resources.
|
||||||
|
*
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ public class StoreMulticastRunnable implements Runnable {
|
|||||||
while(true) {
|
while(true) {
|
||||||
listener.receive(packet);
|
listener.receive(packet);
|
||||||
String data = new String(packet.getData(), 0, packet.getLength());
|
String data = new String(packet.getData(), 0, packet.getLength());
|
||||||
|
|
||||||
System.out.println(data); // TODO ajouter un controller et lui signaler qu'il y a un nouveau StoreBackEnd
|
System.out.println(data); // TODO ajouter un controller et lui signaler qu'il y a un nouveau StoreBackEnd
|
||||||
}
|
}
|
||||||
} catch (Exception ignore) { }
|
} catch (Exception ignore) { }
|
||||||
|
@ -2,7 +2,9 @@ package lightcontainer.domains;
|
|||||||
|
|
||||||
import lightcontainer.interfaces.StoreProcessorFFE;
|
import lightcontainer.interfaces.StoreProcessorFFE;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StoreProcessor
|
* StoreProcessor
|
||||||
@ -14,24 +16,74 @@ import java.net.Socket;
|
|||||||
* @since 1.0
|
* @since 1.0
|
||||||
*
|
*
|
||||||
* @see Runnable
|
* @see Runnable
|
||||||
|
* @see AutoCloseable
|
||||||
* @author Jérémi NIHART <j.nihart@student.helmo.be>
|
* @author Jérémi NIHART <j.nihart@student.helmo.be>
|
||||||
*/
|
*/
|
||||||
public class StoreProcessor implements Runnable {
|
public class StoreProcessor implements Runnable, AutoCloseable {
|
||||||
// Variables
|
// Variables
|
||||||
private StoreProcessorFFE fileFrontEnd;
|
private final StoreProcessorFFE fileFrontEnd;
|
||||||
|
private final Socket store;
|
||||||
|
|
||||||
|
private BufferedReader reader;
|
||||||
|
private PrintWriter writer;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
public StoreProcessor(Socket socket, StoreProcessorFFE fileFrontEnd) {
|
public StoreProcessor(Socket socket, StoreProcessorFFE ffe) {
|
||||||
this.fileFrontEnd = fileFrontEnd;
|
this.fileFrontEnd = ffe;
|
||||||
|
this.store = socket;
|
||||||
|
initStore();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Initialise the Store's Reader and Writer.
|
||||||
|
*
|
||||||
|
* @since 1.0
|
||||||
|
*
|
||||||
|
* @see BufferedReader
|
||||||
|
* @see PrintWriter
|
||||||
|
*/
|
||||||
|
private void initStore() {
|
||||||
|
try {
|
||||||
|
this.reader = new BufferedReader(new InputStreamReader(
|
||||||
|
this.store.getInputStream(),
|
||||||
|
StandardCharsets.UTF_8
|
||||||
|
));
|
||||||
|
this.writer = new PrintWriter(new OutputStreamWriter(
|
||||||
|
this.store.getOutputStream(),
|
||||||
|
StandardCharsets.UTF_8
|
||||||
|
), true);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thread Function
|
||||||
* Start the dialogue with the storebackend.
|
* Start the dialogue with the storebackend.
|
||||||
*
|
*
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
String command = this.reader.readLine();
|
||||||
|
// TODO gestion de la réception de commandes, fichier, ...
|
||||||
|
if (command != null) System.out.println("StoreBackEnd: " + command);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AutoClosable Function
|
||||||
|
* Close the Storage thread and resources.
|
||||||
|
*
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ import java.util.LinkedList;
|
|||||||
public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
|
public class FileFrontEnd implements ClientHandlerFFE, StoreProcessorFFE {
|
||||||
// Variables
|
// Variables
|
||||||
private Deque<Task> tasks = new LinkedList<>();
|
private Deque<Task> tasks = new LinkedList<>();
|
||||||
|
private ClientHandlerRepository clientRepository; // TODO -> pourquoi pas une interface ? end
|
||||||
|
private StoreProcessorRepository storeRepository; // TODO -> pourquoi pas une interface ? end
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
public FileFrontEnd() {
|
public FileFrontEnd() {
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
package lightcontainer.repository;
|
|
||||||
|
|
||||||
public class StoreProcessingRepository {
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,5 @@
|
|||||||
|
package lightcontainer.repository;
|
||||||
|
|
||||||
|
public class StoreProcessorRepository {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user