Zond:fix: завершение процесса без зависаний на read()
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
23
zond/src/main/java/asys/zond/ZondExecuteWatchdog.java
Normal file
23
zond/src/main/java/asys/zond/ZondExecuteWatchdog.java
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user