mirror of
https://github.com/topjohnwu/libsu.git
synced 2024-11-23 03:59:43 +00:00
Change Shell.EXECUTOR type from ExecutorService to Executor
Remove unnecessary restrictions
This commit is contained in:
parent
e01d4cbb8d
commit
2eae61d7ac
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2023 John "topjohnwu" Wu
|
||||
* Copyright 2024 John "topjohnwu" Wu
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -37,7 +37,6 @@ import java.lang.annotation.Retention;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -120,13 +119,13 @@ public abstract class Shell implements Closeable {
|
||||
@interface ConfigFlags {}
|
||||
|
||||
/**
|
||||
* The {@link ExecutorService} that manages all worker threads used in {@code libsu}.
|
||||
* The {@link Executor} that manages all worker threads used in {@code libsu}.
|
||||
* <p>
|
||||
* Note: If the developer decides to replace the default ExecutorService, keep in mind that
|
||||
* Note: If the developer decides to replace the default Executor, keep in mind that
|
||||
* each {@code Shell} instance requires at least 3 threads to operate properly.
|
||||
*/
|
||||
@NonNull
|
||||
public static ExecutorService EXECUTOR = Executors.newCachedThreadPool();
|
||||
public static Executor EXECUTOR = Executors.newCachedThreadPool();
|
||||
|
||||
|
||||
/**
|
||||
|
@ -34,7 +34,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
abstract class JobTask extends Shell.Job implements Shell.Task, Closeable {
|
||||
|
||||
@ -75,10 +75,13 @@ abstract class JobTask extends Shell.Job implements Shell.Task, Closeable {
|
||||
result.err = list;
|
||||
}
|
||||
|
||||
try {
|
||||
Future<Integer> outGobbler = EXECUTOR.submit(new StreamGobbler.OUT(stdout, result.out));
|
||||
Future<Void> errGobbler = EXECUTOR.submit(new StreamGobbler.ERR(stderr, result.err));
|
||||
FutureTask<Integer> outGobbler =
|
||||
new FutureTask<>(new StreamGobbler.OUT(stdout, result.out));
|
||||
FutureTask<Void> errGobbler = new FutureTask<>(new StreamGobbler.ERR(stderr, result.err));
|
||||
EXECUTOR.execute(outGobbler);
|
||||
EXECUTOR.execute(errGobbler);
|
||||
|
||||
try {
|
||||
for (ShellInputSource src : sources)
|
||||
src.serve(stdin);
|
||||
stdin.write(END_CMD);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2023 John "topjohnwu" Wu
|
||||
* Copyright 2024 John "topjohnwu" Wu
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -28,7 +28,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
class ShellPipeStream {
|
||||
@ -58,7 +58,8 @@ class ShellPipeStream {
|
||||
});
|
||||
|
||||
// Open the fifo only after the shell request
|
||||
Future<InputStream> stream = Shell.EXECUTOR.submit(() -> new FileInputStream(fifo));
|
||||
FutureTask<InputStream> stream = new FutureTask<>(() -> new FileInputStream(fifo));
|
||||
Shell.EXECUTOR.execute(stream);
|
||||
return stream.get(FIFO_TIMEOUT, TimeUnit.MILLISECONDS);
|
||||
} catch (Exception e) {
|
||||
if (e instanceof FileNotFoundException)
|
||||
@ -104,7 +105,8 @@ class ShellPipeStream {
|
||||
});
|
||||
|
||||
// Open the fifo only after the shell request
|
||||
Future<OutputStream> stream = Shell.EXECUTOR.submit(() -> new FileOutputStream(fifo));
|
||||
FutureTask<OutputStream> stream = new FutureTask<>(() -> new FileOutputStream(fifo));
|
||||
Shell.EXECUTOR.execute(stream);
|
||||
return stream.get(FIFO_TIMEOUT, TimeUnit.MILLISECONDS);
|
||||
} catch (Exception e) {
|
||||
if (e instanceof FileNotFoundException)
|
||||
|
Loading…
Reference in New Issue
Block a user