Factor constant string and comments added to ReadingRunnable

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
Emmanuel Bigeon 2016-11-30 20:07:28 -05:00
parent e602a269f8
commit d4f428d311

View File

@ -51,6 +51,8 @@ import java.util.logging.Logger;
* @author Emmanuel Bigeon */
public class ReadingRunnable implements Runnable {
/** The closed pipe message */
private static final String CLOSED_PIPE = "Closed pipe"; //$NON-NLS-1$
/** Wait timeout */
private static final long TIMEOUT = 1000;
/** Class logger */
@ -65,6 +67,7 @@ public class ReadingRunnable implements Runnable {
/** Synchro object */
private final Object lock = new Object();
/** The waiting status for a message */
private boolean waiting;
/** @param reader the input to read from */
@ -122,7 +125,7 @@ public class ReadingRunnable implements Runnable {
public String getMessage() throws IOException {
synchronized (lock) {
if (!running) {
throw new IOException("Closed pipe"); //$NON-NLS-1$
throw new IOException(CLOSED_PIPE);
}
waiting = true;
while (messages.isEmpty()) {
@ -133,7 +136,7 @@ public class ReadingRunnable implements Runnable {
e);
}
if (messages.isEmpty() && !running) {
throw new IOException("Closed pipe"); //$NON-NLS-1$
throw new IOException(CLOSED_PIPE);
}
}
LOGGER.finest("Polled: " + messages.peek()); //$NON-NLS-1$
@ -161,19 +164,17 @@ public class ReadingRunnable implements Runnable {
public boolean hasMessage() throws IOException {
synchronized (lock) {
if (!running) {
throw new IOException("Closed pipe"); //$NON-NLS-1$
throw new IOException(CLOSED_PIPE);
}
return !messages.isEmpty();
}
}
/**
*
*/
/** Interrupts the wait on the next message by providing an empty message */
public void interrupt() {
synchronized (lock) {
if (waiting) {
messages.offer("");
messages.offer(""); //$NON-NLS-1$
lock.notify();
}
}