TD2: code cleanup in the client part.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 12 Mar 2018 14:40:19 +0000 (15:40 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 12 Mar 2018 14:40:19 +0000 (15:40 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
TD1/exo3/Main.java
TD2/client/ClientSimplifie.java [moved from TD2/ClientSimplifie.java with 100% similarity]
TD2/client/Main.java [moved from TD2/Main.java with 56% similarity]
TD2/client/Makefile [moved from TD2/Makefile with 99% similarity]
TD2/client/SocketClient.java [moved from TD2/SocketClient.java with 97% similarity]
TD2/client/ThreadClientReceive.java [moved from TD2/ThreadClientReceive.java with 91% similarity]
TD2/client/ThreadClientSend.java [moved from TD2/ThreadClientSend.java with 86% similarity]
TD2/client/concurrent_access.txt [moved from TD2/concurrent_access.txt with 100% similarity]

index af0ba12ee84f810585cdc533d754c19a97c7f7f8..9b34b058db0f9bd0478733db82f6c3a4061e2064 100644 (file)
@@ -6,6 +6,7 @@ public class Main {
 
 
        public static void main (String[] args) {
+               //FIXME: Implement the args parsing to set this tree values dynamically
                final int BUFFER_SIZE = 1;
                final int PROD_NUMBER = 20;
                final int CONS_NUMBER = 20;
similarity index 56%
rename from TD2/Main.java
rename to TD2/client/Main.java
index e7bd9638d3ce91f39700834fe09ee9679c407839..cc47bb7bd499c54bf3822ccc7fbaea975795df27 100644 (file)
@@ -3,11 +3,14 @@ import java.io.*;
 
 public class Main {
 
+       /**
+        * Main for testing ClientSimplifie
+        */
        private static void main1() {
                SocketClient client = new SocketClient();
 
                try {
-                       client.sendMsg("Line 1 Line 2");
+                       client.sendMsg("Line1");
                        String msg = client.receiveMsg();
                        System.out.println(msg);
                }
@@ -21,24 +24,28 @@ public class Main {
 
 
        public static void main (String[] args) {
+               SocketClient client = new SocketClient();
 
-               try {
-                       SocketClient client = new SocketClient();
+               // try {
                        ThreadClientSend thCS = new ThreadClientSend(client);
-                       thCS.setMsg("Line1 Line2");
+                       //FIXME: Implement a loop based on user input to set dynamically the message to sent.
+                       //for (int i = 0; i < 10; i++) {
+                       //      thCS.setMsg("Line" + i);
+                       //}
+                       thCS.setMsg("Line1");
                        Thread thS = new Thread(thCS);
                        Thread thR = new Thread(new ThreadClientReceive(client));
                        thS.setName("thS");
                        thS.start();
                        thR.setName("thR");
                        thR.start();
-               }
-               catch (Exception e) {
-                       System.err.println("Exception: " + e);
-               }
-               finally {
-                       client.closeRWIO();
-               }
+               // }
+               // catch (Exception e) {
+               //      System.err.println("Exception: " + e);
+               // }
+               // finally {
+               //      client.closeRWIO();
+               // }
 
        }
 
similarity index 99%
rename from TD2/Makefile
rename to TD2/client/Makefile
index 5c0e12fce80edea360f8482d434ab6ed0f1f40dc..5a7491f47b8648d2952aed6b639bec37e630d026 100644 (file)
@@ -47,7 +47,7 @@ JVM = java
 
 CLASSES = \
                ClientSimplifie.java \
-               Client.java \
+               SocketClient.java \
                ThreadClientSend.java \
                ThreadClientReceive.java \
                Main.java
similarity index 97%
rename from TD2/SocketClient.java
rename to TD2/client/SocketClient.java
index c4e74a3ad442d456c86259856fd90b4d6acd2c09..48a93eb75964660931a2f0cb16f18f082e51167d 100644 (file)
@@ -54,6 +54,7 @@ public class SocketClient {
      * @param msg a string containing the message to send
      */
     public synchronized void sendMsg(String msg) {
+        //NOTE: it's not really required with one socket writer thread.
         while (msg.isEmpty()) {
             try {
                 wait();
similarity index 91%
rename from TD2/ThreadClientReceive.java
rename to TD2/client/ThreadClientReceive.java
index 7cdb21a46fd74527a5e50553f651ad58f292b1e7..42f5d918dec13672e1acdbefcb1cc233e108a656 100644 (file)
@@ -30,9 +30,6 @@ public class ThreadClientReceive implements Runnable {
             catch (Exception e) {
                 System.err.println("Exception: " + e);
             }
-            //finally {
-            //    client.closeRWIO();
-            //}
         }
     }
 }
similarity index 86%
rename from TD2/ThreadClientSend.java
rename to TD2/client/ThreadClientSend.java
index 2ad2bcb1a922e8063bd4554a93d33a656917c8c3..69cd51a445a3879caa270103dd8a7056dd08c9f6 100644 (file)
@@ -9,8 +9,8 @@ public class ThreadClientSend implements Runnable {
     }
 
     /**
-     * [setMsg description]
-     * @param m [description]
+     * Message to sent setter
+     * @param m the text message to sent
      */
     public void setMsg(String m) {
         msg = m;
@@ -31,9 +31,6 @@ public class ThreadClientSend implements Runnable {
             catch (Exception e) {
                 System.err.println("Exception: " + e);
             }
-            //finally {
-            //    client.closeRWIO();
-            //}
         }
     }
 }