org.netbeans.modules.extexecution/2 1.25.1

org.netbeans.api.extexecution
Class ExecutionService

java.lang.Object
  extended by org.netbeans.api.extexecution.ExecutionService

public final class ExecutionService
extends Object

Execution service provides the facility to execute the process while displaying the output and handling the input.

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();
 

See Also:
newService(java.util.concurrent.Callable, org.netbeans.api.extexecution.ExecutionDescriptor, java.lang.String), ExecutionDescriptor

Method Summary
static ExecutionService newService(Callable<Process> processCreator, ExecutionDescriptor descriptor, String displayName)
          Creates new execution service.
 Future<Integer> run()
          Runs the process described by this service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newService

@NonNull
public static ExecutionService newService(@NonNull
                                                  Callable<Process> processCreator,
                                                  @NonNull
                                                  ExecutionDescriptor descriptor,
                                                  @NonNull
                                                  String displayName)
Creates new execution service. Service will wrap up the processes created by processCreator and will manage them.

Parameters:
processCreator - callable returning the process to wrap up
descriptor - descriptor describing the configuration of service
displayName - display name of this service
Returns:
new execution service

run

@NonNull
public Future<Integer> run()
Runs the process described by this service. The call does not block and the task is represented by the returned value. Integer returned as a result of the 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 Futures. On each call Callable<Process> passed to 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.

Returns:
task representing the actual run, value representing result of the Future is exit code of the process

org.netbeans.modules.extexecution/2 1.25.1

Built on December 5 2011.  |  Portions Copyright 1997-2011 Sun Microsystems, Inc. All rights reserved.