#2450 add outputCallbac

This commit is contained in:
Shinsuke Sugaya 2020-05-08 22:45:14 +09:00
parent 870c32cbee
commit 059f8080cd
3 changed files with 15 additions and 4 deletions

View file

@ -57,13 +57,18 @@ public class ProcessHelper {
}
}
public synchronized JobProcess startProcess(final String sessionId, final List<String> cmdList, final Consumer<ProcessBuilder> pbCall) {
public JobProcess startProcess(final String sessionId, final List<String> cmdList, final Consumer<ProcessBuilder> pbCall) {
return startProcess(sessionId, cmdList, pbCall, InputStreamThread.MAX_BUFFER_SIZE, null);
}
public synchronized JobProcess startProcess(final String sessionId, final List<String> cmdList, final Consumer<ProcessBuilder> pbCall,
final int bufferSize, final Consumer<String> outputCallback) {
final ProcessBuilder pb = new ProcessBuilder(cmdList);
pbCall.accept(pb);
destroyProcess(sessionId);
JobProcess jobProcess;
try {
jobProcess = new JobProcess(pb.start());
jobProcess = new JobProcess(pb.start(), bufferSize, outputCallback);
destroyProcess(sessionId, runningProcessMap.putIfAbsent(sessionId, jobProcess));
return jobProcess;
} catch (final IOException e) {

View file

@ -32,7 +32,7 @@ public class InputStreamThread extends Thread {
private BufferedReader br;
private static final int MAX_BUFFER_SIZE = 1000;
public static final int MAX_BUFFER_SIZE = 1000;
private final List<String> list = new LinkedList<>();

View file

@ -15,6 +15,8 @@
*/
package org.codelibs.fess.util;
import java.util.function.Consumer;
import org.codelibs.fess.Constants;
public class JobProcess {
@ -23,8 +25,12 @@ public class JobProcess {
protected InputStreamThread inputStreamThread;
public JobProcess(final Process process) {
this(process, InputStreamThread.MAX_BUFFER_SIZE, null);
}
public JobProcess(final Process process, final int bufferSize, final Consumer<String> outputCallback) {
this.process = process;
inputStreamThread = new InputStreamThread(process.getInputStream(), Constants.UTF_8);
inputStreamThread = new InputStreamThread(process.getInputStream(), Constants.UTF_8, bufferSize, outputCallback);
}
public Process getProcess() {