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