public final class BaseExecutionService extends Object
All processes launched by this class are terminated on VM exit (if these are not finished or terminated earlier).
Sample usage (ls command):
BaseExecutionDescriptor descriptor = new BaseExecutionDescriptor() .outProcessorFactory(new BaseExecutionDescriptor.InputProcessorFactory() { @Override public InputProcessor newInputProcessor() { return InputProcessors.copying(new BufferedWriter(new OutputStreamWriter(System.out))); } }); ProcessBuilder processBuilder = ProcessBuilder.getLocal(); processBuilder.setExecutable(ls); BaseExecutionService service = BaseExecutionService.newService(processBuilder, descriptor); Future<Integer> task = service.run();
Even simpler usage but without displaying output (ls command):
ProcessBuilder processBuilder = ProcessBuilder.getLocal(); processBuilder.setExecutable(ls); ExecutionService service = ExecutionService.newService(processBuilder, new BaseExecutionDescriptor()); Future<Integer> task = service.run();
Modifier and Type | Method and Description |
---|---|
static BaseExecutionService |
newService(Callable<? extends Process> processCreator,
BaseExecutionDescriptor descriptor)
Creates new execution service.
|
Future<Integer> |
run()
Runs the process described by this service.
|
@NonNull public static BaseExecutionService newService(@NonNull Callable<? extends Process> processCreator, @NonNull BaseExecutionDescriptor descriptor)
processCreator
and will manage them.processCreator
- callable returning the process to wrap updescriptor
- descriptor describing the configuration of service@NonNull public Future<Integer> run()
Future
is exit code of the process.
This method can be invoked multiple times returning the different and
unrelated Future
s. On each call Callable<Process>
passed to BaseExecutionService.newService(java.util.concurrent.Callable, org.netbeans.api.extexecution.base.BaseExecutionDescriptor)
is invoked in order to create the process. If the process creation fails
(throwing an exception) returned Future
will throw
ExecutionException
on Future.get()
request.
For details on execution control see BaseExecutionDescriptor
.
Future
is exit code of the process