Made socket comply with new version of gclc. Fixed piped console manager

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
2016-11-30 20:00:36 -05:00
parent d432914828
commit e602a269f8
12 changed files with 291 additions and 291 deletions

View File

@@ -159,6 +159,12 @@ public final class PipedConsoleManager
return reading.getMessage();
}
/** @return the content of the next line written by the application
* @throws IOException if the reading failed */
public boolean available() throws IOException {
return reading.hasMessage();
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleManager#interruptPrompt() */
@Override

View File

@@ -65,6 +65,7 @@ public class ReadingRunnable implements Runnable {
/** Synchro object */
private final Object lock = new Object();
private boolean waiting;
/** @param reader the input to read from */
public ReadingRunnable(BufferedReader reader) {
@@ -93,6 +94,7 @@ public class ReadingRunnable implements Runnable {
}
} catch (InterruptedIOException e) {
LOGGER.log(Level.INFO, "Reading interrupted", e); //$NON-NLS-1$
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Unable to read from stream", e); //$NON-NLS-1$
running = false;
@@ -122,6 +124,7 @@ public class ReadingRunnable implements Runnable {
if (!running) {
throw new IOException("Closed pipe"); //$NON-NLS-1$
}
waiting = true;
while (messages.isEmpty()) {
try {
lock.wait(TIMEOUT);
@@ -134,6 +137,7 @@ public class ReadingRunnable implements Runnable {
}
}
LOGGER.finest("Polled: " + messages.peek()); //$NON-NLS-1$
waiting = false;
return messages.poll();
}
}
@@ -151,4 +155,27 @@ public class ReadingRunnable implements Runnable {
return running;
}
}
/** @return if a message is waiting
* @throws IOException if the pipe is closed */
public boolean hasMessage() throws IOException {
synchronized (lock) {
if (!running) {
throw new IOException("Closed pipe"); //$NON-NLS-1$
}
return !messages.isEmpty();
}
}
/**
*
*/
public void interrupt() {
synchronized (lock) {
if (waiting) {
messages.offer("");
lock.notify();
}
}
}
}

View File

@@ -170,7 +170,7 @@ public final class SystemConsoleManager implements ConsoleManager { // NOSONAR
* @see fr.bigeon.gclc.manager.ConsoleManager#interruptPrompt() */
@Override
public void interruptPrompt() {
promptThread.interrupt();
reading.interrupt();
}
}

View File

@@ -39,7 +39,7 @@
package fr.bigeon.gclc.manager;
import java.io.IOException;
import java.io.PipedOutputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.ArrayDeque;
@@ -62,7 +62,7 @@ public class WritingRunnable implements Runnable {
/** Messages to write */
private final Deque<String> messages = new ArrayDeque<>();
/** Stream to write to */
private final PipedOutputStream outPrint;
private final OutputStream outPrint;
/** The charset */
private final Charset charset;
/** Runnable state */
@@ -73,7 +73,7 @@ public class WritingRunnable implements Runnable {
/** @param outPrint the output to print to
* @param charset the charset of the stream */
public WritingRunnable(PipedOutputStream outPrint, Charset charset) {
public WritingRunnable(OutputStream outPrint, Charset charset) {
super();
this.outPrint = outPrint;
this.charset = charset;