From e63fd2940be10da7b95b0bfb47f6b780cf22672f Mon Sep 17 00:00:00 2001 From: Elena Dovnar Date: Mon, 18 May 2020 12:28:28 +0300 Subject: [PATCH 1/8] nothing to worry about --- pom.xml | 12 ++++++++++++ .../c9/reader/impl/StreamTextFileReader.java | 1 - src/main/resources/config.properties | 6 ------ 3 files changed, 12 insertions(+), 7 deletions(-) delete mode 100644 src/main/resources/config.properties diff --git a/pom.xml b/pom.xml index 1803dec..7b0e232 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,18 @@ com.solvd.lab.v2.automation autolab2 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 7 + 7 + + + + \ No newline at end of file diff --git a/src/main/java/com/solvd/lab/v2/automation/c9/reader/impl/StreamTextFileReader.java b/src/main/java/com/solvd/lab/v2/automation/c9/reader/impl/StreamTextFileReader.java index 58e0321..cb4db42 100644 --- a/src/main/java/com/solvd/lab/v2/automation/c9/reader/impl/StreamTextFileReader.java +++ b/src/main/java/com/solvd/lab/v2/automation/c9/reader/impl/StreamTextFileReader.java @@ -20,7 +20,6 @@ public String read() throws UnableToReadException{ try(FileInputStream fin = new FileInputStream(this.file)) { // try withou resources byte[] buffer = new byte[fin.available()]; fin.read(buffer, 0, buffer.length); - //return Arrays.toString(buffer); wtf??? return new String(buffer); } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties deleted file mode 100644 index c8f35ae..0000000 --- a/src/main/resources/config.properties +++ /dev/null @@ -1,6 +0,0 @@ -#----------------------------------------------------------------------------# -#--------------------- Common config constants --------------------------# -#----------------------------------------------------------------------------# - -hostname=localhost -port=8080 \ No newline at end of file From 7cc43d04233949beda2d466e89cebbea0452d6f6 Mon Sep 17 00:00:00 2001 From: Elena Dovnar Date: Mon, 18 May 2020 19:01:40 +0300 Subject: [PATCH 2/8] local changes --- .../java/com/solvd/lab/v2/automation/classes/c10/Client.java | 3 +-- .../lab/v2/automation/io/impl/file/StreamTextFileReader.java | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client.java index c8bf952..9085da7 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client.java @@ -1,7 +1,6 @@ package com.solvd.lab.v2.automation.classes.c10; -import com.solvd.lab.v2.automation.classes.c10.bo.ConnectMessage; -import com.solvd.lab.v2.automation.classes.c10.bo.ResponseMessage; +import com.solvd.lab.v2.automation.classes.c10.bo.*; import com.solvd.lab.v2.automation.constant.C10Constant; import com.solvd.lab.v2.automation.io.interfaces.Packable; import com.solvd.lab.v2.automation.util.PropertyUtil; diff --git a/src/main/java/com/solvd/lab/v2/automation/io/impl/file/StreamTextFileReader.java b/src/main/java/com/solvd/lab/v2/automation/io/impl/file/StreamTextFileReader.java index e0fca5d..e861d91 100644 --- a/src/main/java/com/solvd/lab/v2/automation/io/impl/file/StreamTextFileReader.java +++ b/src/main/java/com/solvd/lab/v2/automation/io/impl/file/StreamTextFileReader.java @@ -20,8 +20,8 @@ public StreamTextFileReader(String path) { public String read() throws UnableToReadException{ try(FileInputStream fin = new FileInputStream(this.file)) { // try withou resources byte[] buffer = new byte[fin.available()]; - fin.read(buffer, 0, buffer.length); - return new String(buffer); + fin.read(buffer); + return new String(buffer); } catch (IOException e) { e.printStackTrace(); } From f8a9abe58fa4e92cc4a26460d61cdbf27f72186e Mon Sep 17 00:00:00 2001 From: Elena Dovnar Date: Mon, 18 May 2020 21:20:56 +0300 Subject: [PATCH 3/8] hard hardcode --- .../lab/v2/automation/classes/c10/Client.java | 13 +++-- .../v2/automation/classes/c10/Client2.java | 46 ++++++++++++++++++ .../lab/v2/automation/classes/c10/Server.java | 32 +++++++----- .../io/impl/file/PropertyFileReader.java | 2 - .../v2/automation/util/SerializationUtil.java | 26 +++++++--- src/main/resources/client1 | Bin 0 -> 237 bytes src/main/resources/client2 | Bin 0 -> 234 bytes src/main/resources/serial | Bin 236 -> 237 bytes src/main/resources/serial_response | Bin 244 -> 241 bytes 9 files changed, 94 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java create mode 100644 src/main/resources/client2 diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client.java index 9085da7..11d68e3 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client.java @@ -10,6 +10,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Scanner; /** * 1. object streams @@ -34,15 +35,19 @@ public static void main(String[] args) { e.printStackTrace(); } + while(true){ + connect(HOST, PORT, TOKEN); + System.out.println(((ResponseMessage) getResponse()).getResp()); + } - connect(HOST, PORT, TOKEN); - System.out.println(((ResponseMessage) getResponse()).getResp()); } private static void connect(final String host, final int port, final String token) { - String msg = "Conn"; + Scanner scan = new Scanner(System.in); + System.out.print("you: "); + String msg = scan.next(); Packable pkg = new ConnectMessage(host, port, token, msg); - SerializationUtil.writeObject(pkg); + SerializationUtil.writeObject(pkg, "src/main/resources/client1"); } private static Packable getResponse() { diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java new file mode 100644 index 0000000..b68af70 --- /dev/null +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java @@ -0,0 +1,46 @@ +package com.solvd.lab.v2.automation.classes.c10; + +import com.solvd.lab.v2.automation.classes.c10.bo.ConnectMessage; +import com.solvd.lab.v2.automation.classes.c10.bo.ResponseMessage; +import com.solvd.lab.v2.automation.constant.C10Constant; +import com.solvd.lab.v2.automation.io.interfaces.Packable; +import com.solvd.lab.v2.automation.util.PropertyUtil; +import com.solvd.lab.v2.automation.util.SerializationUtil; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Scanner; + +public class Client2 { + public static void main(String[] args) { + final String HOST = PropertyUtil.getValueByKey(C10Constant.HOSTNAME); + final int PORT = Integer.valueOf(PropertyUtil.getValueByKey(C10Constant.PORT)); + final String TOKEN = PropertyUtil.getValueByKey(C10Constant.TOKEN); + + String path = "src/main/resources/client2"; + Path p = Paths.get(path); + try { + Files.createFile(p); + } catch (IOException e) { + e.printStackTrace(); + } + while(true){ + connect(HOST, PORT, TOKEN); + System.out.println(((ResponseMessage) getResponse()).getResp()); + } + } + + private static void connect(final String host, final int port, final String token) { + Scanner scan = new Scanner(System.in); + System.out.print("you: "); + String msg = scan.next(); + Packable pkg = new ConnectMessage(host, port, token, msg); + SerializationUtil.writeObject(pkg, "src/main/resources/client2"); + } + + private static Packable getResponse() { + return SerializationUtil.readResponse(); + } +} diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java index 6ec3b41..3ac87e1 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java @@ -6,6 +6,8 @@ import com.solvd.lab.v2.automation.io.interfaces.Packable; import com.solvd.lab.v2.automation.util.SerializationUtil; +import javax.print.DocFlavor; +import java.awt.*; import java.util.Arrays; import java.util.List; import java.util.logging.Logger; @@ -15,13 +17,13 @@ public class Server { private static final List AVAILABLE_CLIENTS = Arrays.asList("user"); private static final String HOST = "127.0.0.1"; - private static final int PORT = 8000; + private static final int PORT1 = 8000; + private static final int PORT2 = 7000; public static void main(String[] args) { - LOGGER.info(String.format("Listening on %s:%d", HOST, PORT)); + LOGGER.info(String.format("Listening on %s:%d:%d", HOST, PORT1, PORT2)); while (true) { - try { listen(); Thread.sleep(TimeConstant.TIME_TO_DELAY); @@ -33,19 +35,27 @@ public static void main(String[] args) { // TODO: filter msgs private static void listen() { - Packable obj = SerializationUtil.readObject(); - if (obj != null) { - ConnectMessage msg = ((ConnectMessage) obj); - if (msg.getHost().equals(HOST) && msg.getPort() == PORT && AVAILABLE_CLIENTS.contains(msg.getToken())) { - LOGGER.info(msg.getMessage()); - Packable resp = new ResponseMessage(HOST, PORT, "", "SUCCESS", 200); - sendResponse(resp); - } + Packable obj1 = SerializationUtil.readObject(SerializationUtil.getREADER1()); + Packable obj2 = SerializationUtil.readObject(SerializationUtil.getREADER2()); + Packable[] obje = {obj1, obj2}; + + for(Packable obj:obje){ + if (obj != null) { + ConnectMessage msg = (ConnectMessage) obj; + if (msg.getHost().equals(HOST) && msg.getPort() == PORT1 && AVAILABLE_CLIENTS.contains(msg.getToken())) { + LOGGER.info(msg.getMessage()); + Packable resp = new ResponseMessage(HOST, PORT2, "", "sent", 200); + sendResponse(resp); + + } + } } + } private static void sendResponse(Packable pkg) { SerializationUtil.writeResponse(pkg); } + } diff --git a/src/main/java/com/solvd/lab/v2/automation/io/impl/file/PropertyFileReader.java b/src/main/java/com/solvd/lab/v2/automation/io/impl/file/PropertyFileReader.java index 4c8eaba..b3bdbcf 100644 --- a/src/main/java/com/solvd/lab/v2/automation/io/impl/file/PropertyFileReader.java +++ b/src/main/java/com/solvd/lab/v2/automation/io/impl/file/PropertyFileReader.java @@ -12,11 +12,9 @@ public class PropertyFileReader extends BaseReader implements Reader { private Properties props; - public PropertyFileReader(File file) { super(file); } - public PropertyFileReader(String path) { super(path); } diff --git a/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java b/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java index f6bfa86..45107ee 100644 --- a/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java +++ b/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java @@ -7,28 +7,38 @@ import com.solvd.lab.v2.automation.io.interfaces.Packable; public class SerializationUtil { - private static final String DATA_FILE_PATH = System.getProperty("user.dir") + "/src/main/resources/serial"; + private static final String DATA_FILE_PATH1 = System.getProperty("user.dir") + "/src/main/resources/client1"; + private static final String DATA_FILE_PATH2 = System.getProperty("user.dir") + "/src/main/resources/client2"; private static final String DATA_FILE_PATH_RESPONSE = System.getProperty("user.dir") + "/src/main/resources/serial_response"; - private static final ObjectReader READER = new ObjectReader(DATA_FILE_PATH); + public static ObjectReader getREADER1() { + return READER1; + } + + public static ObjectReader getREADER2() { + return READER2; + } + + private static final ObjectReader READER1 = new ObjectReader(DATA_FILE_PATH1); + private static final ObjectReader READER2 = new ObjectReader(DATA_FILE_PATH2); private static final ObjectReader READER_RESPONSE = new ObjectReader(DATA_FILE_PATH_RESPONSE); - public static void writeObject(Packable obj) { + public static void writeObject(Packable obj, String path) { try { - new ObjectWriter().write(DATA_FILE_PATH, obj); + new ObjectWriter().write(path, obj); } catch (UnableToWriteException e) { e.printStackTrace(); - throw new RuntimeException(String.format("%s is unable to write!", DATA_FILE_PATH)); + throw new RuntimeException(String.format("%s is unable to write!", path)); } } - public static Packable readObject() { + public static Packable readObject(ObjectReader objr) { try { - return READER.read(); + return objr.read(); } catch (UnableToReadException e) { e.printStackTrace(); - throw new RuntimeException(String.format("%s is unable to read!", DATA_FILE_PATH)); + throw new RuntimeException(String.format("%s is unable to read!", objr.getPath())); } } diff --git a/src/main/resources/client1 b/src/main/resources/client1 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..f6e3a0da8f9f734e056ddfbf139694da8d4ecfbb 100644 GIT binary patch literal 237 zcmZ4UmVvdnh`};BKUc3fKc_53FDEfcugpj&nI_O3O2t7??d7SPJrsN_-etGV+T{3K{A^Ro44j5W=6VJ|XjsC)Qd*o^RKmcTk(!f}4*+WsP7?qC literal 0 HcmV?d00001 diff --git a/src/main/resources/client2 b/src/main/resources/client2 new file mode 100644 index 0000000000000000000000000000000000000000..fda85fc6e2f05b3db5838235d57207aba33e2b53 GIT binary patch literal 234 zcmZ4UmVvdnh`};BKUc3fKc_53FDEfcugpj&nI_O3O2t7??d7SPJrsN_-etGV+T{3K{A^Ro44j5W=6VJ|XjsC)Qd*o^RKmcNkqH2T4ouAe literal 0 HcmV?d00001 diff --git a/src/main/resources/serial b/src/main/resources/serial index b4c1bc3f3ea4148d90a34cdb1bf7cb241f412c8b..f6e3a0da8f9f734e056ddfbf139694da8d4ecfbb 100644 GIT binary patch delta 13 UcmaFE_?B_Pb2iqD)SR4r04W6pasU7T delta 12 TcmaFM_=a)9b5<7T{JcB>BN_zi diff --git a/src/main/resources/serial_response b/src/main/resources/serial_response index 90fd0019945de38c21e5cee0b99da5e783fa6914..9334446922b28327871635f495de3c8d81d39c33 100644 GIT binary patch delta 35 mcmeyu_>pnKRT=4s5(Z8~BXd0iAT%st0D%)F3@pW|c_je5> Date: Mon, 18 May 2020 23:04:01 +0300 Subject: [PATCH 4/8] double-trouble --- .../lab/v2/automation/classes/c10/Client.java | 3 ++- .../v2/automation/classes/c10/Client2.java | 5 +++-- .../lab/v2/automation/classes/c10/Server.java | 14 ++++++------ .../v2/automation/constant/TimeConstant.java | 2 +- .../v2/automation/util/SerializationUtil.java | 20 ++++++++++-------- src/main/resources/client1 | Bin 237 -> 0 bytes src/main/resources/client2 | Bin 234 -> 239 bytes src/main/resources/serial_response | Bin 241 -> 244 bytes src/main/resources/serial_response1 | Bin 0 -> 241 bytes src/main/resources/serial_response2 | 0 10 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 src/main/resources/serial_response1 create mode 100644 src/main/resources/serial_response2 diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client.java index 11d68e3..77e4460 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client.java @@ -2,6 +2,7 @@ import com.solvd.lab.v2.automation.classes.c10.bo.*; import com.solvd.lab.v2.automation.constant.C10Constant; +import com.solvd.lab.v2.automation.io.impl.stream.ObjectReader; import com.solvd.lab.v2.automation.io.interfaces.Packable; import com.solvd.lab.v2.automation.util.PropertyUtil; import com.solvd.lab.v2.automation.util.SerializationUtil; @@ -51,6 +52,6 @@ private static void connect(final String host, final int port, final String toke } private static Packable getResponse() { - return SerializationUtil.readResponse(); + return SerializationUtil.readResponse(SerializationUtil.getREADER1()); } } diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java index b68af70..7086b6b 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java @@ -28,7 +28,8 @@ public static void main(String[] args) { } while(true){ connect(HOST, PORT, TOKEN); - System.out.println(((ResponseMessage) getResponse()).getResp()); + String hey = ((ResponseMessage) getResponse()).getResp(); + System.out.println(hey); } } @@ -41,6 +42,6 @@ private static void connect(final String host, final int port, final String toke } private static Packable getResponse() { - return SerializationUtil.readResponse(); + return SerializationUtil.readResponse(SerializationUtil.getREADER2()); } } diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java index 3ac87e1..995e7f4 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java @@ -3,6 +3,7 @@ import com.solvd.lab.v2.automation.classes.c10.bo.ConnectMessage; import com.solvd.lab.v2.automation.classes.c10.bo.ResponseMessage; import com.solvd.lab.v2.automation.constant.TimeConstant; +import com.solvd.lab.v2.automation.io.impl.stream.ObjectReader; import com.solvd.lab.v2.automation.io.interfaces.Packable; import com.solvd.lab.v2.automation.util.SerializationUtil; @@ -45,17 +46,18 @@ private static void listen() { ConnectMessage msg = (ConnectMessage) obj; if (msg.getHost().equals(HOST) && msg.getPort() == PORT1 && AVAILABLE_CLIENTS.contains(msg.getToken())) { LOGGER.info(msg.getMessage()); - Packable resp = new ResponseMessage(HOST, PORT2, "", "sent", 200); - sendResponse(resp); - + Packable resp = new ResponseMessage(HOST, PORT2, "", msg.getMessage(), 200); + if(obj == obje[0]){ + sendResponse(resp, SerializationUtil.getREADER1()); + } else sendResponse(resp, SerializationUtil.getREADER2()); } } } } - private static void sendResponse(Packable pkg) { - SerializationUtil.writeResponse(pkg); + private static void sendResponse(Packable pkg, ObjectReader objr) { + SerializationUtil.writeResponse(pkg, objr); } -} +} \ No newline at end of file diff --git a/src/main/java/com/solvd/lab/v2/automation/constant/TimeConstant.java b/src/main/java/com/solvd/lab/v2/automation/constant/TimeConstant.java index e4aea74..dbde188 100644 --- a/src/main/java/com/solvd/lab/v2/automation/constant/TimeConstant.java +++ b/src/main/java/com/solvd/lab/v2/automation/constant/TimeConstant.java @@ -1,5 +1,5 @@ package com.solvd.lab.v2.automation.constant; public class TimeConstant { - public static final int TIME_TO_DELAY = 10000; + public static final int TIME_TO_DELAY = 1000; } diff --git a/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java b/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java index 45107ee..a62b5d6 100644 --- a/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java +++ b/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java @@ -9,7 +9,9 @@ public class SerializationUtil { private static final String DATA_FILE_PATH1 = System.getProperty("user.dir") + "/src/main/resources/client1"; private static final String DATA_FILE_PATH2 = System.getProperty("user.dir") + "/src/main/resources/client2"; - private static final String DATA_FILE_PATH_RESPONSE = System.getProperty("user.dir") + "/src/main/resources/serial_response"; + private static final String DATA_FILE_PATH_RESPONSE1 = System.getProperty("user.dir") + "/src/main/resources/serial_response1"; + private static final String DATA_FILE_PATH_RESPONSE2 = System.getProperty("user.dir") + "/src/main/resources/serial_response2"; + public static ObjectReader getREADER1() { return READER1; @@ -21,8 +23,8 @@ public static ObjectReader getREADER2() { private static final ObjectReader READER1 = new ObjectReader(DATA_FILE_PATH1); private static final ObjectReader READER2 = new ObjectReader(DATA_FILE_PATH2); - private static final ObjectReader READER_RESPONSE = new ObjectReader(DATA_FILE_PATH_RESPONSE); - + private static final ObjectReader READER_RESPONSE1 = new ObjectReader(DATA_FILE_PATH_RESPONSE1); + private static final ObjectReader READER_RESPONSE2 = new ObjectReader(DATA_FILE_PATH_RESPONSE2); public static void writeObject(Packable obj, String path) { try { @@ -43,22 +45,22 @@ public static Packable readObject(ObjectReader objr) { } - public static Packable readResponse() { + public static Packable readResponse(ObjectReader objr) { try { - return READER_RESPONSE.read(); + return objr.read(); } catch (UnableToReadException e) { e.printStackTrace(); - throw new RuntimeException(String.format("%s is unable to read!", DATA_FILE_PATH_RESPONSE)); + throw new RuntimeException(String.format("%s is unable to read!", objr.getPath())); } } - public static void writeResponse(Packable obj) { + public static void writeResponse(Packable obj, ObjectReader objr) { try { - new ObjectWriter().write(DATA_FILE_PATH_RESPONSE, obj); + new ObjectWriter().write(objr.getPath(), obj); } catch (UnableToWriteException e) { e.printStackTrace(); - throw new RuntimeException(String.format("%s is unable to write!", DATA_FILE_PATH_RESPONSE)); + throw new RuntimeException(String.format("%s is unable to write!", objr.getPath())); } } diff --git a/src/main/resources/client1 b/src/main/resources/client1 index f6e3a0da8f9f734e056ddfbf139694da8d4ecfbb..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 GIT binary patch literal 0 HcmV?d00001 literal 237 zcmZ4UmVvdnh`};BKUc3fKc_53FDEfcugpj&nI_O3O2t7??d7SPJrsN_-etGV+T{3K{A^Ro44j5W=6VJ|XjsC)Qd*o^RKmcTk(!f}4*+WsP7?qC diff --git a/src/main/resources/client2 b/src/main/resources/client2 index fda85fc6e2f05b3db5838235d57207aba33e2b53..c36aa6bb0dc7591ce4d7fc010577cd2b79ee63d9 100644 GIT binary patch delta 87 zcmaFG_@0qt&07Z6;vxpCiTT&iQ$HsmUe2sl~;K>8V-@zfbxwoUCVJVDw>N&xHt1 gjINTBcPL@tG&C~TGXO%v5(bvi;?$xN2BwTm0CtiYf&c&j diff --git a/src/main/resources/serial_response b/src/main/resources/serial_response index 9334446922b28327871635f495de3c8d81d39c33..82ab2118ea2607e14c336b0c45c1aa0a17e3cff5 100644 GIT binary patch delta 15 Wcmey!_=R!88xHpJjKq@S(gFZBtppnK8&;O$)VvY^Bx?mH diff --git a/src/main/resources/serial_response1 b/src/main/resources/serial_response1 new file mode 100644 index 0000000000000000000000000000000000000000..9334446922b28327871635f495de3c8d81d39c33 GIT binary patch literal 241 zcmZ4UmVvdnh`}m3KUc3fKc_53FDEfcugpj+R&oePFc`~ph=clClFt8K>)s!#@`D7)QCF0WUglbgoY&yAaJ6Dfu%S#uLJ;eGf$TQ literal 0 HcmV?d00001 diff --git a/src/main/resources/serial_response2 b/src/main/resources/serial_response2 new file mode 100644 index 0000000..e69de29 From 3ce50081e67de69aa5bcf1bca3ef34e1861d81ea Mon Sep 17 00:00:00 2001 From: Elena Dovnar Date: Mon, 18 May 2020 23:40:09 +0300 Subject: [PATCH 5/8] more logical but sill doesn't work --- .../classes/c10/{Client.java => Client1.java} | 2 +- .../lab/v2/automation/classes/c10/Server.java | 8 ++++---- .../automation/io/impl/stream/ObjectReader.java | 6 +----- .../v2/automation/util/SerializationUtil.java | 7 +++++++ src/main/resources/client2 | Bin 239 -> 233 bytes 5 files changed, 13 insertions(+), 10 deletions(-) rename src/main/java/com/solvd/lab/v2/automation/classes/c10/{Client.java => Client1.java} (98%) diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client1.java similarity index 98% rename from src/main/java/com/solvd/lab/v2/automation/classes/c10/Client.java rename to src/main/java/com/solvd/lab/v2/automation/classes/c10/Client1.java index 77e4460..42861af 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client1.java @@ -21,7 +21,7 @@ * 4. refactoring * 5. fixes */ -public class Client { +public class Client1 { public static void main(String[] args) { final String HOST = PropertyUtil.getValueByKey(C10Constant.HOSTNAME); diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java index 995e7f4..5842e99 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java @@ -19,7 +19,7 @@ public class Server { private static final List AVAILABLE_CLIENTS = Arrays.asList("user"); private static final String HOST = "127.0.0.1"; private static final int PORT1 = 8000; - private static final int PORT2 = 7000; + private static final int PORT2 = 8000; public static void main(String[] args) { @@ -46,10 +46,10 @@ private static void listen() { ConnectMessage msg = (ConnectMessage) obj; if (msg.getHost().equals(HOST) && msg.getPort() == PORT1 && AVAILABLE_CLIENTS.contains(msg.getToken())) { LOGGER.info(msg.getMessage()); - Packable resp = new ResponseMessage(HOST, PORT2, "", msg.getMessage(), 200); + Packable resp = new ResponseMessage(HOST, PORT2, "", "sent", 200); if(obj == obje[0]){ - sendResponse(resp, SerializationUtil.getREADER1()); - } else sendResponse(resp, SerializationUtil.getREADER2()); + sendResponse(resp, SerializationUtil.getReaderResponse2()); + } else sendResponse(resp, SerializationUtil.getReaderResponse1()); } } } diff --git a/src/main/java/com/solvd/lab/v2/automation/io/impl/stream/ObjectReader.java b/src/main/java/com/solvd/lab/v2/automation/io/impl/stream/ObjectReader.java index 2299e1a..3ab6588 100644 --- a/src/main/java/com/solvd/lab/v2/automation/io/impl/stream/ObjectReader.java +++ b/src/main/java/com/solvd/lab/v2/automation/io/impl/stream/ObjectReader.java @@ -7,11 +7,7 @@ import java.io.*; -public class ObjectReader extends BaseReader implements StreamReader { - public ObjectReader(File file) { - super(file); - } - +public class ObjectReader extends BaseReader implements StreamReader, Packable { public ObjectReader(String path) { super(path); } diff --git a/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java b/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java index a62b5d6..d5c9a6a 100644 --- a/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java +++ b/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java @@ -12,6 +12,13 @@ public class SerializationUtil { private static final String DATA_FILE_PATH_RESPONSE1 = System.getProperty("user.dir") + "/src/main/resources/serial_response1"; private static final String DATA_FILE_PATH_RESPONSE2 = System.getProperty("user.dir") + "/src/main/resources/serial_response2"; + public static ObjectReader getReaderResponse1() { + return READER_RESPONSE1; + } + + public static ObjectReader getReaderResponse2() { + return READER_RESPONSE2; + } public static ObjectReader getREADER1() { return READER1; diff --git a/src/main/resources/client2 b/src/main/resources/client2 index c36aa6bb0dc7591ce4d7fc010577cd2b79ee63d9..9ba1dad3cfd908d3e96e0ff1d3c5a5bdea7460a8 100644 GIT binary patch delta 81 zcmaFQ_>z%h&07Z6;vxpii5%L>&iQ$HsmUe2sl~;K>8V-@zfbxwoUCVJVDw>N&xHt1 fjINTDcPL@tG&C~TGXO%v5(bvi;?$xN21X+QTyGfQ delta 87 zcmaFK_@0qt&07Z6;vxpCiTT Date: Tue, 19 May 2020 13:09:36 +0300 Subject: [PATCH 6/8] work but not in the way we want --- .../v2/automation/classes/c10/Client1.java | 20 +++++++++------- .../v2/automation/classes/c10/Client2.java | 22 +++++++++++++++--- .../lab/v2/automation/classes/c10/Server.java | 15 ++++++++---- .../v2/automation/util/SerializationUtil.java | 20 ++++------------ src/main/resources/client1 | Bin 0 -> 5 bytes src/main/resources/client2 | Bin 233 -> 5 bytes src/main/resources/serial_response | Bin 244 -> 0 bytes src/main/resources/serial_response1 | Bin 241 -> 239 bytes src/main/resources/serial_response2 | Bin 0 -> 242 bytes 9 files changed, 45 insertions(+), 32 deletions(-) delete mode 100644 src/main/resources/serial_response diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client1.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client1.java index 42861af..e3c6f05 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client1.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client1.java @@ -2,10 +2,9 @@ import com.solvd.lab.v2.automation.classes.c10.bo.*; import com.solvd.lab.v2.automation.constant.C10Constant; -import com.solvd.lab.v2.automation.io.impl.stream.ObjectReader; +import com.solvd.lab.v2.automation.constant.TimeConstant; import com.solvd.lab.v2.automation.io.interfaces.Packable; -import com.solvd.lab.v2.automation.util.PropertyUtil; -import com.solvd.lab.v2.automation.util.SerializationUtil; +import com.solvd.lab.v2.automation.util.*; import java.io.IOException; import java.nio.file.Files; @@ -27,7 +26,6 @@ public static void main(String[] args) { final String HOST = PropertyUtil.getValueByKey(C10Constant.HOSTNAME); final int PORT = Integer.valueOf(PropertyUtil.getValueByKey(C10Constant.PORT)); final String TOKEN = PropertyUtil.getValueByKey(C10Constant.TOKEN); - String path = "src/main/resources/client1"; Path p = Paths.get(path); try { @@ -37,21 +35,25 @@ public static void main(String[] args) { } while(true){ - connect(HOST, PORT, TOKEN); + try{ + connect(HOST, PORT, TOKEN); + Thread.sleep(TimeConstant.TIME_TO_DELAY+100); + } catch (InterruptedException e) { + e.printStackTrace(); + } System.out.println(((ResponseMessage) getResponse()).getResp()); } - } private static void connect(final String host, final int port, final String token) { Scanner scan = new Scanner(System.in); System.out.print("you: "); - String msg = scan.next(); + String msg = scan.nextLine(); Packable pkg = new ConnectMessage(host, port, token, msg); - SerializationUtil.writeObject(pkg, "src/main/resources/client1"); + SerializationUtil.writeObject(pkg, SerializationUtil.getREADER1().getPath()); } private static Packable getResponse() { - return SerializationUtil.readResponse(SerializationUtil.getREADER1()); + return SerializationUtil.readResponse(SerializationUtil.getReaderResponse1()); } } diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java index 7086b6b..b41514a 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java @@ -3,6 +3,7 @@ import com.solvd.lab.v2.automation.classes.c10.bo.ConnectMessage; import com.solvd.lab.v2.automation.classes.c10.bo.ResponseMessage; import com.solvd.lab.v2.automation.constant.C10Constant; +import com.solvd.lab.v2.automation.constant.TimeConstant; import com.solvd.lab.v2.automation.io.interfaces.Packable; import com.solvd.lab.v2.automation.util.PropertyUtil; import com.solvd.lab.v2.automation.util.SerializationUtil; @@ -27,7 +28,13 @@ public static void main(String[] args) { e.printStackTrace(); } while(true){ - connect(HOST, PORT, TOKEN); + + try { + connect(HOST, PORT, TOKEN); + Thread.sleep(TimeConstant.TIME_TO_DELAY+1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } String hey = ((ResponseMessage) getResponse()).getResp(); System.out.println(hey); } @@ -36,12 +43,21 @@ public static void main(String[] args) { private static void connect(final String host, final int port, final String token) { Scanner scan = new Scanner(System.in); System.out.print("you: "); - String msg = scan.next(); + String msg = scan.nextLine(); Packable pkg = new ConnectMessage(host, port, token, msg); SerializationUtil.writeObject(pkg, "src/main/resources/client2"); + + } + + private static void listen(){ + Packable obj = SerializationUtil.readObject(SerializationUtil.getReaderResponse1()); + if (obj != null) { + ConnectMessage msg = (ConnectMessage) obj; + System.out.println(msg.getMessage()); + } } private static Packable getResponse() { - return SerializationUtil.readResponse(SerializationUtil.getREADER2()); + return SerializationUtil.readResponse(SerializationUtil.getReaderResponse2()); } } diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java index 5842e99..3ec9e17 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java @@ -46,10 +46,13 @@ private static void listen() { ConnectMessage msg = (ConnectMessage) obj; if (msg.getHost().equals(HOST) && msg.getPort() == PORT1 && AVAILABLE_CLIENTS.contains(msg.getToken())) { LOGGER.info(msg.getMessage()); - Packable resp = new ResponseMessage(HOST, PORT2, "", "sent", 200); - if(obj == obje[0]){ - sendResponse(resp, SerializationUtil.getReaderResponse2()); - } else sendResponse(resp, SerializationUtil.getReaderResponse1()); + Packable resp = new ResponseMessage(HOST, PORT2, "", msg.getMessage(), 200); + if (obj == obje[0]){ + SerializationUtil.writeObject(resp,SerializationUtil.getReaderResponse2().getPath()); + clearBuffer(SerializationUtil.getREADER1()); + } else { + SerializationUtil.writeObject(resp,SerializationUtil.getReaderResponse1().getPath()); + clearBuffer(SerializationUtil.getREADER2()); } } } } @@ -60,4 +63,8 @@ private static void sendResponse(Packable pkg, ObjectReader objr) { SerializationUtil.writeResponse(pkg, objr); } + public static void clearBuffer(ObjectReader objr){ + SerializationUtil.writeObject(null, objr.getPath()); + } + } \ No newline at end of file diff --git a/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java b/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java index d5c9a6a..b6b730e 100644 --- a/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java +++ b/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java @@ -12,21 +12,10 @@ public class SerializationUtil { private static final String DATA_FILE_PATH_RESPONSE1 = System.getProperty("user.dir") + "/src/main/resources/serial_response1"; private static final String DATA_FILE_PATH_RESPONSE2 = System.getProperty("user.dir") + "/src/main/resources/serial_response2"; - public static ObjectReader getReaderResponse1() { - return READER_RESPONSE1; - } - - public static ObjectReader getReaderResponse2() { - return READER_RESPONSE2; - } - - public static ObjectReader getREADER1() { - return READER1; - } - - public static ObjectReader getREADER2() { - return READER2; - } + public static ObjectReader getReaderResponse1() { return READER_RESPONSE1; } + public static ObjectReader getReaderResponse2() { return READER_RESPONSE2; } + public static ObjectReader getREADER1() { return READER1; } + public static ObjectReader getREADER2() { return READER2; } private static final ObjectReader READER1 = new ObjectReader(DATA_FILE_PATH1); private static final ObjectReader READER2 = new ObjectReader(DATA_FILE_PATH2); @@ -70,5 +59,4 @@ public static void writeResponse(Packable obj, ObjectReader objr) { throw new RuntimeException(String.format("%s is unable to write!", objr.getPath())); } } - } diff --git a/src/main/resources/client1 b/src/main/resources/client1 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..fafc4f3b042ef346d262a267ce84ed591d917112 100644 GIT binary patch literal 5 McmZ4UmVvbZ00)l(4*&oF literal 0 HcmV?d00001 diff --git a/src/main/resources/client2 b/src/main/resources/client2 index 9ba1dad3cfd908d3e96e0ff1d3c5a5bdea7460a8..fafc4f3b042ef346d262a267ce84ed591d917112 100644 GIT binary patch literal 5 McmZ4UmVvbZ00)l(4*&oF literal 233 zcmZ4UmVvdnh`};BKUc3fKc_53FDEfcugpj&nI_O3O2t7??d7SPJrsN_-etGV+T{3K{A^Ro44j5W=6VJ|XjsC)Qd*o^RKmb$1OPP&Of3Ka diff --git a/src/main/resources/serial_response b/src/main/resources/serial_response deleted file mode 100644 index 82ab2118ea2607e14c336b0c45c1aa0a17e3cff5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 244 zcmZ4UmVvdnh`}m3KUc3fKc_53FDEfcugpj+R&oePFc`~ph=clClFt8K>)s!#@`D7)QCF0WUglbgoY&yAaJ6DfxSEpnKRT=4s5(Z8~BXd0iAT%st0D%)F3@pW|c_je5JqdRJ diff --git a/src/main/resources/serial_response2 b/src/main/resources/serial_response2 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..01b76524fbefed858b7a9d7cf8f3e9a3c5b5c764 100644 GIT binary patch literal 242 zcmZ4UmVvdnh`}m3KUc3fKc_53FDEfcugpj+R&oePFc`~ph=clClFt8K>)s!#@`D7)QCF0WUglbgoY&yAaJ6Dfi)vFCnp~O!NyPC literal 0 HcmV?d00001 From 4c577e2a439389686c32a2bb14fa6e8905e3b9dd Mon Sep 17 00:00:00 2001 From: Elena Dovnar Date: Tue, 19 May 2020 15:54:47 +0300 Subject: [PATCH 7/8] almost done --- .../lab/v2/automation/classes/c10/Chat.java | 31 ++++++++++++++++++ .../v2/automation/classes/c10/Client1.java | 6 ++-- .../v2/automation/classes/c10/Client2.java | 16 +++------ .../lab/v2/automation/classes/c10/Server.java | 23 +++++++++---- .../v2/automation/util/SerializationUtil.java | 5 +-- src/main/resources/client1 | Bin 5 -> 0 bytes src/main/resources/serial_response1 | Bin 239 -> 5 bytes src/main/resources/serial_response2 | Bin 242 -> 5 bytes 8 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 src/main/java/com/solvd/lab/v2/automation/classes/c10/Chat.java diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Chat.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Chat.java new file mode 100644 index 0000000..0d86ed8 --- /dev/null +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Chat.java @@ -0,0 +1,31 @@ +package com.solvd.lab.v2.automation.classes.c10; + +import com.solvd.lab.v2.automation.classes.c10.bo.ConnectMessage; +import com.solvd.lab.v2.automation.classes.c10.bo.ResponseMessage; +import com.solvd.lab.v2.automation.constant.TimeConstant; +import com.solvd.lab.v2.automation.io.interfaces.Packable; +import com.solvd.lab.v2.automation.util.SerializationUtil; + +public class Chat { + public static void main(String[] args) { + while (true) { + Packable obj1 = SerializationUtil.readObject(SerializationUtil.getREADER_RESPONSE1()); + Packable obj2 = SerializationUtil.readObject(SerializationUtil.getREADER_RESPONSE2()); + Packable[] obje = {obj1, obj2}; + for(Packable obj:obje){ + if(obj == null) System.out.println("Stop!"); + if (obj != null) { + try { + Thread.sleep(TimeConstant.TIME_TO_DELAY+1000); + if(obj == obje[0]){ + System.out.println(((ResponseMessage) Client1.getResponse()).getResp()); + } else System.out.println(((ResponseMessage) Client2.getResponse()).getResp()); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + } + } +} diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client1.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client1.java index e3c6f05..b261757 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client1.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client1.java @@ -41,7 +41,7 @@ public static void main(String[] args) { } catch (InterruptedException e) { e.printStackTrace(); } - System.out.println(((ResponseMessage) getResponse()).getResp()); +// System.out.println(((ResponseMessage) getResponse()).getResp()); } } @@ -53,7 +53,7 @@ private static void connect(final String host, final int port, final String toke SerializationUtil.writeObject(pkg, SerializationUtil.getREADER1().getPath()); } - private static Packable getResponse() { - return SerializationUtil.readResponse(SerializationUtil.getReaderResponse1()); + public static Packable getResponse() { + return SerializationUtil.readResponse(SerializationUtil.getREADER_RESPONSE1()); } } diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java index b41514a..5db84e2 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java @@ -35,8 +35,8 @@ public static void main(String[] args) { } catch (InterruptedException e) { e.printStackTrace(); } - String hey = ((ResponseMessage) getResponse()).getResp(); - System.out.println(hey); + // String hey = ((ResponseMessage) getResponse()).getResp(); + // System.out.println(hey); } } @@ -49,15 +49,7 @@ private static void connect(final String host, final int port, final String toke } - private static void listen(){ - Packable obj = SerializationUtil.readObject(SerializationUtil.getReaderResponse1()); - if (obj != null) { - ConnectMessage msg = (ConnectMessage) obj; - System.out.println(msg.getMessage()); - } - } - - private static Packable getResponse() { - return SerializationUtil.readResponse(SerializationUtil.getReaderResponse2()); + public static Packable getResponse() { + return SerializationUtil.readResponse(SerializationUtil.getREADER_RESPONSE2()); } } diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java index 3ec9e17..cda2c8a 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java @@ -48,21 +48,30 @@ private static void listen() { LOGGER.info(msg.getMessage()); Packable resp = new ResponseMessage(HOST, PORT2, "", msg.getMessage(), 200); if (obj == obje[0]){ - SerializationUtil.writeObject(resp,SerializationUtil.getReaderResponse2().getPath()); + SerializationUtil.writeObject(resp,SerializationUtil.getREADER_RESPONSE2().getPath()); clearBuffer(SerializationUtil.getREADER1()); + try { + Thread.sleep(TimeConstant.TIME_TO_DELAY+1500); + clearBuffer(SerializationUtil.getREADER_RESPONSE2()); + } catch (InterruptedException e) { + e.printStackTrace(); + } } else { - SerializationUtil.writeObject(resp,SerializationUtil.getReaderResponse1().getPath()); - clearBuffer(SerializationUtil.getREADER2()); } + SerializationUtil.writeObject(resp,SerializationUtil.getREADER_RESPONSE1().getPath()); + clearBuffer(SerializationUtil.getREADER2()); + try { + Thread.sleep(TimeConstant.TIME_TO_DELAY+1500); + clearBuffer(SerializationUtil.getREADER_RESPONSE1()); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } } } } } - private static void sendResponse(Packable pkg, ObjectReader objr) { - SerializationUtil.writeResponse(pkg, objr); - } - public static void clearBuffer(ObjectReader objr){ SerializationUtil.writeObject(null, objr.getPath()); } diff --git a/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java b/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java index b6b730e..50c1fd9 100644 --- a/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java +++ b/src/main/java/com/solvd/lab/v2/automation/util/SerializationUtil.java @@ -12,8 +12,9 @@ public class SerializationUtil { private static final String DATA_FILE_PATH_RESPONSE1 = System.getProperty("user.dir") + "/src/main/resources/serial_response1"; private static final String DATA_FILE_PATH_RESPONSE2 = System.getProperty("user.dir") + "/src/main/resources/serial_response2"; - public static ObjectReader getReaderResponse1() { return READER_RESPONSE1; } - public static ObjectReader getReaderResponse2() { return READER_RESPONSE2; } + + public static ObjectReader getREADER_RESPONSE1() { return READER_RESPONSE1; } + public static ObjectReader getREADER_RESPONSE2() { return READER_RESPONSE2; } public static ObjectReader getREADER1() { return READER1; } public static ObjectReader getREADER2() { return READER2; } diff --git a/src/main/resources/client1 b/src/main/resources/client1 index fafc4f3b042ef346d262a267ce84ed591d917112..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 GIT binary patch literal 0 HcmV?d00001 literal 5 McmZ4UmVvbZ00)l(4*&oF diff --git a/src/main/resources/serial_response1 b/src/main/resources/serial_response1 index ebd6d2449022b7914303f3d60ff3b89ccda5f924..fafc4f3b042ef346d262a267ce84ed591d917112 100644 GIT binary patch literal 5 McmZ4UmVvbZ00)l(4*&oF literal 239 zcmZ4UmVvdnh`}m3KUc3fKc_53FDEfcugpj+R&oePFc`~ph=clClFt8K>)s!#@`D7)QCF0WUglbgoY&yAaJ6DfvGqj0MmX>sQ>@~ diff --git a/src/main/resources/serial_response2 b/src/main/resources/serial_response2 index 01b76524fbefed858b7a9d7cf8f3e9a3c5b5c764..fafc4f3b042ef346d262a267ce84ed591d917112 100644 GIT binary patch literal 5 McmZ4UmVvbZ00)l(4*&oF literal 242 zcmZ4UmVvdnh`}m3KUc3fKc_53FDEfcugpj+R&oePFc`~ph=clClFt8K>)s!#@`D7)QCF0WUglbgoY&yAaJ6Dfi)vFCnp~O!NyPC From 1cd7846d3af39612d21fdea23f09bcd02a71fa9c Mon Sep 17 00:00:00 2001 From: Elena Dovnar Date: Tue, 19 May 2020 16:23:30 +0300 Subject: [PATCH 8/8] done (horey!) --- .../lab/v2/automation/classes/c10/Chat.java | 17 ++++++++-------- .../v2/automation/classes/c10/Client1.java | 6 ------ .../v2/automation/classes/c10/Client2.java | 8 -------- .../lab/v2/automation/classes/c10/Server.java | 19 +----------------- src/main/resources/client1 | 0 src/main/resources/client2 | Bin 5 -> 0 bytes src/main/resources/serial_response1 | Bin 5 -> 0 bytes src/main/resources/serial_response2 | Bin 5 -> 0 bytes 8 files changed, 9 insertions(+), 41 deletions(-) delete mode 100644 src/main/resources/client1 delete mode 100644 src/main/resources/client2 diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Chat.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Chat.java index 0d86ed8..95e8281 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Chat.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Chat.java @@ -3,26 +3,25 @@ import com.solvd.lab.v2.automation.classes.c10.bo.ConnectMessage; import com.solvd.lab.v2.automation.classes.c10.bo.ResponseMessage; import com.solvd.lab.v2.automation.constant.TimeConstant; +import com.solvd.lab.v2.automation.io.impl.stream.ObjectReader; import com.solvd.lab.v2.automation.io.interfaces.Packable; import com.solvd.lab.v2.automation.util.SerializationUtil; public class Chat { - public static void main(String[] args) { + public static void main(String[] args) throws InterruptedException { while (true) { Packable obj1 = SerializationUtil.readObject(SerializationUtil.getREADER_RESPONSE1()); Packable obj2 = SerializationUtil.readObject(SerializationUtil.getREADER_RESPONSE2()); Packable[] obje = {obj1, obj2}; for(Packable obj:obje){ - if(obj == null) System.out.println("Stop!"); if (obj != null) { - try { - Thread.sleep(TimeConstant.TIME_TO_DELAY+1000); if(obj == obje[0]){ - System.out.println(((ResponseMessage) Client1.getResponse()).getResp()); - } else System.out.println(((ResponseMessage) Client2.getResponse()).getResp()); - } catch (InterruptedException e) { - e.printStackTrace(); - } + System.out.println("client 2: "+((ResponseMessage) Client1.getResponse()).getResp()); + SerializationUtil.writeObject(null, SerializationUtil.getREADER_RESPONSE1().getPath()); + } else { + System.out.println("client 1: "+((ResponseMessage) Client2.getResponse()).getResp()); + SerializationUtil.writeObject(null, SerializationUtil.getREADER_RESPONSE2().getPath()); + } } } diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client1.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client1.java index b261757..97acccb 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client1.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client1.java @@ -35,13 +35,7 @@ public static void main(String[] args) { } while(true){ - try{ connect(HOST, PORT, TOKEN); - Thread.sleep(TimeConstant.TIME_TO_DELAY+100); - } catch (InterruptedException e) { - e.printStackTrace(); - } -// System.out.println(((ResponseMessage) getResponse()).getResp()); } } diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java index 5db84e2..f87d106 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Client2.java @@ -28,15 +28,7 @@ public static void main(String[] args) { e.printStackTrace(); } while(true){ - - try { connect(HOST, PORT, TOKEN); - Thread.sleep(TimeConstant.TIME_TO_DELAY+1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - // String hey = ((ResponseMessage) getResponse()).getResp(); - // System.out.println(hey); } } diff --git a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java index cda2c8a..3d87ff7 100644 --- a/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java +++ b/src/main/java/com/solvd/lab/v2/automation/classes/c10/Server.java @@ -25,12 +25,7 @@ public class Server { public static void main(String[] args) { LOGGER.info(String.format("Listening on %s:%d:%d", HOST, PORT1, PORT2)); while (true) { - try { - listen(); - Thread.sleep(TimeConstant.TIME_TO_DELAY); - } catch (InterruptedException e) { - e.printStackTrace(); - } + listen(); } } @@ -50,21 +45,9 @@ private static void listen() { if (obj == obje[0]){ SerializationUtil.writeObject(resp,SerializationUtil.getREADER_RESPONSE2().getPath()); clearBuffer(SerializationUtil.getREADER1()); - try { - Thread.sleep(TimeConstant.TIME_TO_DELAY+1500); - clearBuffer(SerializationUtil.getREADER_RESPONSE2()); - } catch (InterruptedException e) { - e.printStackTrace(); - } } else { SerializationUtil.writeObject(resp,SerializationUtil.getREADER_RESPONSE1().getPath()); clearBuffer(SerializationUtil.getREADER2()); - try { - Thread.sleep(TimeConstant.TIME_TO_DELAY+1500); - clearBuffer(SerializationUtil.getREADER_RESPONSE1()); - } catch (InterruptedException e) { - e.printStackTrace(); - } } } } diff --git a/src/main/resources/client1 b/src/main/resources/client1 deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/resources/client2 b/src/main/resources/client2 deleted file mode 100644 index fafc4f3b042ef346d262a267ce84ed591d917112..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5 McmZ4UmVvbZ00)l(4*&oF diff --git a/src/main/resources/serial_response1 b/src/main/resources/serial_response1 index fafc4f3b042ef346d262a267ce84ed591d917112..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 GIT binary patch literal 0 HcmV?d00001 literal 5 McmZ4UmVvbZ00)l(4*&oF diff --git a/src/main/resources/serial_response2 b/src/main/resources/serial_response2 index fafc4f3b042ef346d262a267ce84ed591d917112..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 GIT binary patch literal 0 HcmV?d00001 literal 5 McmZ4UmVvbZ00)l(4*&oF