Compare commits
2 Commits
gclc-swt-1
...
gclc-1.2.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 2dbdf55694 | |||
| 3ac978bdc1 |
@@ -144,9 +144,6 @@ public class SocketConsoleApplicationShell implements Runnable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try (ServerSocket actualServerSocket = new ServerSocket(port)) {
|
try (ServerSocket actualServerSocket = new ServerSocket(port)) {
|
||||||
this.serverSocket = actualServerSocket;
|
this.serverSocket = actualServerSocket;
|
||||||
final ConsoleRunnable runnable = new ConsoleRunnable(app,
|
|
||||||
promptingLock);
|
|
||||||
final Thread appTh = new Thread(runnable);
|
|
||||||
running = true;
|
running = true;
|
||||||
try (PipedOutputStream outStream = new PipedOutputStream();
|
try (PipedOutputStream outStream = new PipedOutputStream();
|
||||||
BufferedWriter writer = new BufferedWriter(
|
BufferedWriter writer = new BufferedWriter(
|
||||||
@@ -156,11 +153,13 @@ public class SocketConsoleApplicationShell implements Runnable {
|
|||||||
consoleInput);
|
consoleInput);
|
||||||
BufferedReader inBuf = new BufferedReader(isr);) {
|
BufferedReader inBuf = new BufferedReader(isr);) {
|
||||||
consoleManager.setInput(inBuf);
|
consoleManager.setInput(inBuf);
|
||||||
runSokectServer(appTh, writer);
|
runSokectServer(writer);
|
||||||
// Close the application
|
// Close the application
|
||||||
// Pass command to application
|
// Pass command to application
|
||||||
writer.write(applicationShutdown + EOL);
|
if (app.isRunning()) {
|
||||||
writer.flush();
|
writer.write(applicationShutdown + EOL);
|
||||||
|
writer.flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
@@ -172,20 +171,27 @@ public class SocketConsoleApplicationShell implements Runnable {
|
|||||||
/** @param appTh the application thread
|
/** @param appTh the application thread
|
||||||
* @param writer the writer to the application
|
* @param writer the writer to the application
|
||||||
* @throws IOException if the communication with the client failed */
|
* @throws IOException if the communication with the client failed */
|
||||||
private void runSokectServer(Thread appTh,
|
private void runSokectServer(BufferedWriter writer) throws IOException {
|
||||||
BufferedWriter writer) throws IOException {
|
final ConsoleRunnable runnable = new ConsoleRunnable(app,
|
||||||
|
promptingLock);
|
||||||
|
Thread appThOld = null;
|
||||||
|
Thread appThNext = new Thread(runnable);
|
||||||
while (running) {
|
while (running) {
|
||||||
try (Socket clientSocket = serverSocket.accept();
|
try (Socket clientSocket = serverSocket.accept();
|
||||||
PrintWriter out = new PrintWriter(
|
PrintWriter out = new PrintWriter(
|
||||||
clientSocket.getOutputStream(), true);
|
clientSocket.getOutputStream(), true);
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(
|
InputStreamReader isr = new InputStreamReader(
|
||||||
clientSocket.getInputStream()));) {
|
clientSocket.getInputStream());
|
||||||
|
BufferedReader in = new BufferedReader(isr);) {
|
||||||
// this is not threaded to avoid several clients at the same
|
// this is not threaded to avoid several clients at the same
|
||||||
// time
|
// time
|
||||||
consoleManager.setOutput(out);
|
consoleManager.setOutput(out);
|
||||||
// Initiate application
|
// Initiate application
|
||||||
if (!appTh.isAlive()) {
|
if (appThOld == null || !appThOld.isAlive()) {
|
||||||
appTh.start();
|
appThNext.start();
|
||||||
|
// Prepare next start
|
||||||
|
appThOld = appThNext;
|
||||||
|
appThNext = new Thread(runnable);
|
||||||
} else {
|
} else {
|
||||||
out.println("Reconnected"); //$NON-NLS-1$
|
out.println("Reconnected"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
@@ -249,7 +255,7 @@ public class SocketConsoleApplicationShell implements Runnable {
|
|||||||
private void communicateLoop(BufferedReader in,
|
private void communicateLoop(BufferedReader in,
|
||||||
BufferedWriter writer) throws IOException {
|
BufferedWriter writer) throws IOException {
|
||||||
String ln;
|
String ln;
|
||||||
while (running && (ln = in.readLine()) != null) {
|
while (app.isRunning() && (ln = in.readLine()) != null) {
|
||||||
if (ln.equals(close)) {
|
if (ln.equals(close)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,23 @@ public class ConsoleTestApplication extends ConsoleApplication {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
add(new Command("long") {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String tip() {
|
||||||
|
return "A long run test command";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(String... args) throws CommandRunException {
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
manager.println("Test command ran fine");
|
||||||
|
} catch (IOException | InterruptedException e) {
|
||||||
|
throw new CommandRunException("manager closed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (final InvalidCommandName e) {
|
} catch (final InvalidCommandName e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class SocketConsoleApplicationTest {
|
|||||||
|
|
||||||
String fromServer;
|
String fromServer;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
String[] cmds = {"help", "test", "close"};
|
String[] cmds = {"help", "toto", "test", "close"};
|
||||||
while ((fromServer = in.readLine()) != null) {
|
while ((fromServer = in.readLine()) != null) {
|
||||||
System.out.println("Server: \n" + ENCODER.decode(fromServer));
|
System.out.println("Server: \n" + ENCODER.decode(fromServer));
|
||||||
if (fromServer.equals("Bye.")) {
|
if (fromServer.equals("Bye.")) {
|
||||||
|
|||||||
@@ -32,12 +32,10 @@
|
|||||||
<!-- The fact that you are presently reading this means that you have had -->
|
<!-- The fact that you are presently reading this means that you have had -->
|
||||||
<!-- knowledge of the CeCILL license and that you accept its terms. -->
|
<!-- knowledge of the CeCILL license and that you accept its terms. -->
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<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">
|
||||||
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-swt</artifactId>
|
<artifactId>gclc-swt</artifactId>
|
||||||
<version>1.0.2-SNAPSHOT</version>
|
<version>1.0.3-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<url>http://www.bigeon.fr/emmanuel</url>
|
<url>http://www.bigeon.fr/emmanuel</url>
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public class CommandProvider implements ICommandProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new CommandRunException(
|
throw new CommandRunException(
|
||||||
Messages.getString("CommandProvider.unrecognized0", cmd)); //$NON-NLS-1$
|
Messages.getString("CommandProvider.unrecognized", cmd)); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
CommandProvider.unrecognized=Unrecognized command '{0}'
|
CommandProvider.unrecognized=Unrecognized command "{0}"
|
||||||
ConsoleApplication.cmd.failed=The command '{0}' failed due to :
|
ConsoleApplication.cmd.failed=The command "{0}" failed due to :
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public class ConsoleApplicationTest {
|
|||||||
final PipedInputStream snk = new PipedInputStream();
|
final PipedInputStream snk = new PipedInputStream();
|
||||||
PrintStream out = new PrintStream(new PipedOutputStream(snk));
|
PrintStream out = new PrintStream(new PipedOutputStream(snk));
|
||||||
final ConsoleTestApplication app = new ConsoleTestApplication(
|
final ConsoleTestApplication app = new ConsoleTestApplication(
|
||||||
new SystemConsoleManager(out, in));
|
new SystemConsoleManager(System.out, in));
|
||||||
Thread th = new Thread(new Runnable() {
|
Thread th = new Thread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -93,6 +93,7 @@ public class ConsoleApplicationTest {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try (PrintWriter writer = new PrintWriter(src, true)) {
|
try (PrintWriter writer = new PrintWriter(src, true)) {
|
||||||
writer.println("test");
|
writer.println("test");
|
||||||
|
writer.println("toto");
|
||||||
writer.println("long");
|
writer.println("long");
|
||||||
writer.println("exit");
|
writer.println("exit");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user