Compare commits
4 Commits
gclc-socke
...
gclc-socke
| Author | SHA1 | Date | |
|---|---|---|---|
| 7de2dadbe0 | |||
| 50395ba852 | |||
| 248c82cf50 | |||
| 6289ca1db9 |
@@ -70,7 +70,7 @@ of Emmanuel Bigeon. -->
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>gclc-socket</artifactId>
|
<artifactId>gclc-socket</artifactId>
|
||||||
<version>1.1.5</version>
|
<version>1.1.6</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<url>http://www.bigeon.fr/emmanuel</url>
|
<url>http://www.bigeon.fr/emmanuel</url>
|
||||||
<properties>
|
<properties>
|
||||||
@@ -78,12 +78,6 @@ of Emmanuel Bigeon. -->
|
|||||||
<project.scm.id>git.bigeon.net</project.scm.id>
|
<project.scm.id>git.bigeon.net</project.scm.id>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>4.11</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>fr.bigeon</groupId>
|
<groupId>fr.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
@@ -104,6 +98,6 @@ of Emmanuel Bigeon. -->
|
|||||||
<description>Socket implementation of GCLC</description>
|
<description>Socket implementation of GCLC</description>
|
||||||
<scm>
|
<scm>
|
||||||
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
||||||
<tag>gclc-socket-1.1.5</tag>
|
<tag>gclc-socket-1.1.6</tag>
|
||||||
</scm>
|
</scm>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -95,12 +95,12 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
while (!socket.isOutputShutdown()) {
|
while (!socket.isClosed()) {
|
||||||
while (!socket.isOutputShutdown() &&
|
while (!socket.isClosed() &&
|
||||||
!consoleManager.available()) {
|
!consoleManager.available()) {
|
||||||
waitASec();
|
waitASec();
|
||||||
}
|
}
|
||||||
if (socket.isOutputShutdown()) {
|
if (socket.isClosed()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String m = consoleManager.readNextLine();
|
String m = consoleManager.readNextLine();
|
||||||
@@ -266,7 +266,6 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
|
|||||||
communicateOnce(socket, in);
|
communicateOnce(socket, in);
|
||||||
} else {
|
} else {
|
||||||
communicateLoop(socket, in);
|
communicateLoop(socket, in);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,8 +278,21 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
|
|||||||
Thread th = new Thread(reading, "gclcToApp"); //$NON-NLS-1$
|
Thread th = new Thread(reading, "gclcToApp"); //$NON-NLS-1$
|
||||||
th.start();
|
th.start();
|
||||||
communicationContent(reading);
|
communicationContent(reading);
|
||||||
|
doEndCommunication(reading);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param reading the reading runnable
|
||||||
|
* @throws IOException if the end of communication failed */
|
||||||
|
private void doEndCommunication(ReadingRunnable reading) throws IOException {
|
||||||
reading.setRunning(false);
|
reading.setRunning(false);
|
||||||
socket.shutdownOutput();
|
Thread wait = consoleManager.getWaitForDelivery("Bye."); //$NON-NLS-1$
|
||||||
|
consoleManager.println("Bye."); //$NON-NLS-1$
|
||||||
|
try {
|
||||||
|
wait.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
LOGGER.warning("The Bye wait was interrupted."); //$NON-NLS-1$
|
||||||
|
LOGGER.log(Level.FINE, "An interruption occured", e); //$NON-NLS-1$
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param socket the socket
|
/** @param socket the socket
|
||||||
@@ -294,12 +306,7 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
|
|||||||
while (app.isRunning() && communicationContent(reading)) {
|
while (app.isRunning() && communicationContent(reading)) {
|
||||||
// keep on going
|
// keep on going
|
||||||
}
|
}
|
||||||
reading.setRunning(false);
|
doEndCommunication(reading);
|
||||||
while (consoleManager.available()) {
|
|
||||||
waitASec();
|
|
||||||
}
|
|
||||||
socket.shutdownOutput();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param reading the reading
|
/** @param reading the reading
|
||||||
@@ -322,14 +329,6 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
|
|||||||
}
|
}
|
||||||
String ln = reading.getMessage();
|
String ln = reading.getMessage();
|
||||||
if (ln.equals(close)) {
|
if (ln.equals(close)) {
|
||||||
Thread wait = consoleManager.getWaitForDelivery("Bye."); //$NON-NLS-1$
|
|
||||||
consoleManager.println("Bye."); //$NON-NLS-1$
|
|
||||||
try {
|
|
||||||
wait.join();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
LOGGER.warning("The Bye wait was interrupted."); //$NON-NLS-1$
|
|
||||||
LOGGER.log(Level.FINE, "An interruption occured", e); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Pass command to application
|
// Pass command to application
|
||||||
|
|||||||
@@ -89,17 +89,10 @@ public class SocketConsoleApplicationTest {
|
|||||||
String[] cmds = {"help", "toto", "test", "bye"};
|
String[] cmds = {"help", "toto", "test", "bye"};
|
||||||
while ((fromServer = in.readLine()) != null) {
|
while ((fromServer = in.readLine()) != null) {
|
||||||
i++;
|
i++;
|
||||||
LOGGER.fine("Server: \n" + fromServer);
|
fromServer = consumeToPrompt(fromServer, in);
|
||||||
if (fromServer.equals("Bye.")) {
|
if (fromServer == null || fromServer.equals("Bye.")) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
while (fromServer != null && !fromServer.equals("> ")) {
|
|
||||||
fromServer = in.readLine();
|
|
||||||
LOGGER.fine("Server: \n" + fromServer);
|
|
||||||
}
|
|
||||||
if (fromServer == null) {
|
|
||||||
fail("Null pointer");
|
|
||||||
}
|
|
||||||
|
|
||||||
final String fromUser = cmds[i];
|
final String fromUser = cmds[i];
|
||||||
if (fromUser != null) {
|
if (fromUser != null) {
|
||||||
@@ -123,19 +116,15 @@ public class SocketConsoleApplicationTest {
|
|||||||
String[] cmds = {"help", "toto", "test",
|
String[] cmds = {"help", "toto", "test",
|
||||||
ConsoleTestApplication.EXIT};
|
ConsoleTestApplication.EXIT};
|
||||||
while ((fromServer = in.readLine()) != null) {
|
while ((fromServer = in.readLine()) != null) {
|
||||||
LOGGER.fine("Server: \n" + fromServer);
|
fromServer = consumeToPrompt(fromServer, in);
|
||||||
while (fromServer != null && !fromServer.equals("> ")) {
|
if (fromServer == null || fromServer.equals("Bye.")) {
|
||||||
LOGGER.fine("Server: \n" + fromServer);
|
|
||||||
fromServer = in.readLine();
|
|
||||||
}
|
|
||||||
if (fromServer == null) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
LOGGER.fine("Server: \n" + fromServer);
|
LOGGER.info("Server: \n" + fromServer);
|
||||||
|
|
||||||
final String fromUser = cmds[i];
|
final String fromUser = cmds[i];
|
||||||
if (fromUser != null) {
|
if (fromUser != null) {
|
||||||
LOGGER.fine("Client: " + fromUser);
|
LOGGER.info("Client: " + fromUser);
|
||||||
out.println(fromUser);
|
out.println(fromUser);
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
@@ -161,11 +150,8 @@ public class SocketConsoleApplicationTest {
|
|||||||
String[] cmds = {"help", "toto", "test",
|
String[] cmds = {"help", "toto", "test",
|
||||||
ConsoleTestApplication.EXIT};
|
ConsoleTestApplication.EXIT};
|
||||||
while ((fromServer = in.readLine()) != null) {
|
while ((fromServer = in.readLine()) != null) {
|
||||||
while (fromServer != null && !fromServer.equals("> ")) {
|
fromServer = consumeToPrompt(fromServer, in);
|
||||||
fromServer = in.readLine();
|
if (fromServer == null || fromServer.equals("Bye.")) {
|
||||||
LOGGER.fine("Server: \n" + fromServer);
|
|
||||||
}
|
|
||||||
if (fromServer == null) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,17 +193,11 @@ public class SocketConsoleApplicationTest {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
String[] cmds = {"help", "test", "close"};
|
String[] cmds = {"help", "test", "close"};
|
||||||
while ((fromServer = in.readLine()) != null) {
|
while ((fromServer = in.readLine()) != null) {
|
||||||
assertTrue(i < 1);
|
fromServer = consumeToPrompt(fromServer, in);
|
||||||
while (fromServer != null && !fromServer.equals("> ") &&
|
if (fromServer == null || fromServer.equals("Bye.")) {
|
||||||
!fromServer.equals("See you")) {
|
|
||||||
fromServer = in.readLine();
|
|
||||||
LOGGER.fine("Server: \n" + fromServer);
|
|
||||||
}
|
|
||||||
if (fromServer == null || fromServer.equals("Bye.") ||
|
|
||||||
fromServer.equals("See you")) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
assertTrue(i < 1);
|
||||||
final String fromUser = cmds[i];
|
final String fromUser = cmds[i];
|
||||||
if (fromUser != null) {
|
if (fromUser != null) {
|
||||||
LOGGER.fine("Client: " + fromUser);
|
LOGGER.fine("Client: " + fromUser);
|
||||||
@@ -243,4 +223,19 @@ public class SocketConsoleApplicationTest {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param in the input
|
||||||
|
* @return the string
|
||||||
|
* @throws IOException if the input reading failed */
|
||||||
|
private String consumeToPrompt(String server,
|
||||||
|
BufferedReader in) throws IOException {
|
||||||
|
String fromServer = server;
|
||||||
|
LOGGER.fine("Server: \n" + fromServer);
|
||||||
|
while (fromServer != null && !fromServer.equals("Bye.") &&
|
||||||
|
!fromServer.equals("> ")) {
|
||||||
|
fromServer = in.readLine();
|
||||||
|
LOGGER.fine("Server: \n" + fromServer);
|
||||||
|
}
|
||||||
|
return fromServer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>fr.bigeon</groupId>
|
<groupId>fr.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>1.3.2</version>
|
<version>1.3.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>fr.bigeon</groupId>
|
<groupId>fr.bigeon</groupId>
|
||||||
|
|||||||
Reference in New Issue
Block a user