public final class ExecutionService extends Object
It will execute the program with an associated I/O window, with stop and restart buttons. It will also obey various descriptor properties such as whether or not to show a progress bar.
All processes launched by this class are terminated on VM exit (if these are not finished or terminated earlier).
Note that once service is run for the first time, subsequents runs can be
invoked by the user (rerun button) if it is allowed to do so
(ExecutionDescriptor.isControllable()
).
Sample usage - executing ls command:
ExecutionDescriptor descriptor = new ExecutionDescriptor() .frontWindow(true).controllable(true); ExternalProcessBuilder processBuilder = new ExternalProcessBuilder("ls"); ExecutionService service = ExecutionService.newService(processBuilder, descriptor, "ls command"); Future<Integer> task = service.run();
Modifier and Type | Method and Description |
---|---|
static ExecutionService |
newService(Callable<Process> processCreator,
ExecutionDescriptor descriptor,
String displayName)
Creates new execution service.
|
Future<Integer> |
run()
Runs the process described by this service.
|
@NonNull public static ExecutionService newService(@NonNull Callable<Process> processCreator, @NonNull ExecutionDescriptor descriptor, @NonNull String displayName)
processCreator
and will manage them.processCreator
- callable returning the process to wrap updescriptor
- descriptor describing the configuration of servicedisplayName
- display name of this service@NonNull public Future<Integer> run()
Future
is exit code of the process.
The output tabs are reused (if caller does not use the custom one,
see ExecutionDescriptor.getInputOutput()
) - the tab to reuse
(if any) is selected by having the same name and same buttons
(control and option). If there is no output tab to reuse new one
is opened.
This method can be invoked multiple times returning the different and
unrelated Future
s. On each call Callable<Process>
passed to ExecutionService.newService(java.util.concurrent.Callable, org.netbeans.api.extexecution.ExecutionDescriptor, java.lang.String)
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 ExecutionDescriptor
.
Future
is exit code of the process