<commit_before>package server;

import java.lang.ClassNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.io.EOFException;
import java.lang.Thread;

import utils.Buffer;
import utils.Log;
import utils.Matrix;
import utils.NetworkNode;
import utils.Request;

public class Server extends NetworkNode {

	private ServerSocket socketServer = null;
	private Socket socket = null;
    private ObjectInputStream inputStream = null;
    private ObjectOutputStream outputStream = null;
	private int BUFFER_SIZE = 5;
	private Buffer<Request> buffer = new Buffer<>(BUFFER_SIZE);
	private boolean receiveFinished = false;

	private long computeTime = 0L;

    public Server(String port) {
        this.setPort(port);
    }

	private Thread t = new Thread(new Runnable() {
		public void run() {
			outputStream = getSocketOutputStream(socket);
			while (! receiveFinished ) {
				if ( ! buffer.isEmpty() ) {
					Request r = buffer.remove();
					Matrix response = compute( r.getMatrix() , r.getExposant() );
					send(new Request(r.getId(), 0, response) , outputStream);
				}
				else {
					Log.print("Buffer is empty... Sleeping for a second.");
					threadSleep(1);
				}
			}
		}
	});


	public void start() {
        Log.print("Server - start()");

		try {
			socketServer = new ServerSocket(this.getPort());
			socket = socketServer.accept();
		} catch (IOException e) {
			Log.error("Server start() - Cannot connect sockets");
		}

        Log.print("Connection established : " + socketServer.getLocalSocketAddress());
        inputStream = getSocketInputStream(socket);
		t.start();
		int i = 1;

		while (true) {
        	Request r = receive(inputStream);
			if (r == null) {
				Log.print("All the data were received...");
				receiveFinished = true;
				break;
			}

			Log.print("Request received: #" + r.getId());

			if( ! buffer.add(r) ) {
				Log.print("Buffer is full");
			}

			i++;
		}

        Log.print("Server - end start()");
	}

    public void stop() {
        try {
            socketServer.close();
            socket.close();
        } catch (IOException e) {
            Log.error("IOException - Server.stop()");
            e.printStackTrace();
        }
        Log.print("Server - end stop()");
    }

	private Matrix compute(Matrix m, int exposant) {
		long startTime = System.nanoTime();
		Matrix result = new Matrix(m.matrixPowered(exposant));
		computeTime += (System.nanoTime() - startTime);
		return result;
	}
}
<commit_msg>ajout condition terminaison envoi serveur<commit_after>package server;

import java.lang.ClassNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.io.EOFException;
import java.lang.Thread;

import utils.Buffer;
import utils.Log;
import utils.Matrix;
import utils.NetworkNode;
import utils.Request;

public class Server extends NetworkNode {

	private ServerSocket socketServer = null;
	private Socket socket = null;
    private ObjectInputStream inputStream = null;
    private ObjectOutputStream outputStream = null;
	private int BUFFER_SIZE = 5;
	private Buffer<Request> buffer = new Buffer<>(BUFFER_SIZE);
	private boolean receiveFinished = false;

	private long computeTime = 0L;

    public Server(String port) {
        this.setPort(port);
    }

	private Thread t = new Thread(new Runnable() {
		public void run() {
			outputStream = getSocketOutputStream(socket);
			while (! receiveFinished || ! buffer.isEmpty() ) {
				if ( ! buffer.isEmpty() ) {
					Request r = buffer.remove();
					Matrix response = compute( r.getMatrix() , r.getExposant() );
					send(new Request(r.getId(), 0, response) , outputStream);
				}
				else {
					Log.print("Buffer is empty... Sleeping for a second.");
					threadSleep(1);
				}
			}
		}
	});


	public void start() {
        Log.print("Server - start()");

		try {
			socketServer = new ServerSocket(this.getPort());
			socket = socketServer.accept();
		} catch (IOException e) {
			Log.error("Server start() - Cannot connect sockets");
		}

        Log.print("Connection established : " + socketServer.getLocalSocketAddress());
        inputStream = getSocketInputStream(socket);
		t.start();
		int i = 1;

		while (true) {
        	Request r = receive(inputStream);
			if (r == null) {
				Log.print("All the data were received...");
				receiveFinished = true;
				break;
			}

			Log.print("Request received: #" + r.getId());

			if( ! buffer.add(r) ) {
				Log.print("Buffer is full");
			}

			i++;
		}

        Log.print("Server - end start()");
	}

    public void stop() {
        try {
            socketServer.close();
            socket.close();
        } catch (IOException e) {
            Log.error("IOException - Server.stop()");
            e.printStackTrace();
        }
        Log.print("Server - end stop()");
    }

	private Matrix compute(Matrix m, int exposant) {
		long startTime = System.nanoTime();
		Matrix result = new Matrix(m.matrixPowered(exposant));
		computeTime += (System.nanoTime() - startTime);
		return result;
	}
}

{'fraction_non_alphanumeric': 0.12921779141104295, 'fraction_numerical': 0.0019171779141104294, 'mean_word_length': 3.0599221789883266, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1676331', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1526, 'n_words': 399}