Archived
0

Zond:fix: завершение процесса без зависаний на read()

This commit is contained in:
2017-07-19 00:13:39 +03:00
parent c12bf89e8f
commit 630c20124e
3 changed files with 38 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ public class PipeInputStream extends InputStream {
private int lastWritePos = 0,
lastReadPos = 0,
wallPos = buffer.length-1;
private boolean closed = false;
public synchronized void write(String s) {
byte[] strBytes = s.getBytes();
@@ -46,6 +47,7 @@ public class PipeInputStream extends InputStream {
return 0;
}
}
if (closed) return 0;
if (lastReadPos == wallPos) {
lastReadPos = 0;
@@ -68,6 +70,7 @@ public class PipeInputStream extends InputStream {
return 0;
}
}
if (closed) return 0;
int actualLen = len;
if (lastReadPos > lastWritePos) {
@@ -88,4 +91,14 @@ public class PipeInputStream extends InputStream {
notify();
return actualLen;
}
public void open() {
closed = false;
}
@Override
public synchronized void close() {
this.closed = true;
notify();
}
}

View File

@@ -48,8 +48,9 @@ public class ZondCommandHandler implements CommandHandler {
Shell.getInstance().shutdown();
} else if (line.equalsIgnoreCase("start")) {
if (watchdog == null) {
watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
watchdog = new ZondExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT, proxyStdIn);
executor.setWatchdog(watchdog);
Runnable task = () -> {
int code = 0;
try {

View File

@@ -0,0 +1,23 @@
/*
* DmitriyMX <dimon550@gmail.com>
* 2017-07-19
*/
package asys.zond;
import org.apache.commons.exec.ExecuteWatchdog;
public class ZondExecuteWatchdog extends ExecuteWatchdog {
private final PipeInputStream inputStream;
public ZondExecuteWatchdog(long timeout, PipeInputStream inputStream) {
super(timeout);
this.inputStream = inputStream;
inputStream.open();
}
@Override
public synchronized void stop() {
super.stop();
inputStream.close();
}
}