|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.mmm.util.component.base.AbstractComponent
net.sf.mmm.util.component.base.AbstractLoggableComponent
net.sf.mmm.util.process.base.ProcessUtilImpl
@Singleton @Named public class ProcessUtilImpl
This is the implementation of the ProcessUtil interface.
ATTENTION:
The execute-methods spin up multiple threads,
especially when multiple processes are piped (2*n+1[+1] threads). Therefore
you should NOT use the singleton variant of this util
except you are writing a simple command-line client that does a simple job
and then terminates. When writing a server-application or library, that makes
such calls repetitive, you should create your own instance and
configure a thread-pool as
Executor.
| Nested Class Summary | |
|---|---|
protected static class |
ProcessUtilImpl.AsyncProcessExecutorImpl
This inner class is the default implementation of the AsyncProcessExecutor. |
protected class |
ProcessUtilImpl.ProcessExecutor
This inner class is does the actual execution of the Process(es). |
| Field Summary | |
|---|---|
private Executor |
executor
|
private static ProcessUtil |
instance
|
private StreamUtil |
streamUtil
|
| Constructor Summary | |
|---|---|
ProcessUtilImpl()
The constructor. |
|
| Method Summary | |
|---|---|
protected void |
doInitialize()
This method performs the actual initialization. |
int |
execute(ProcessContext context,
long timeout,
TimeUnit unit,
ProcessBuilder... builders)
This method executes the external Processes configured by the given
builders. |
int |
execute(ProcessContext context,
ProcessBuilder... builders)
This method executes the external Processes configured by the given
builders. |
AsyncProcessExecutor |
executeAsync(ProcessContext context,
ProcessBuilder... builders)
This method executes the external Processes configured by the given
builders as async task. |
protected Executor |
getExecutor()
This method gets the Executor used to run asynchronous tasks. |
static ProcessUtil |
getInstance()
This method gets the singleton instance of this ProcessUtilImpl. |
protected StreamUtil |
getStreamUtil()
This method gets the stream-util that is used by this process-util. |
void |
setExecutor(Executor executor)
This method sets the executor. |
void |
setStreamUtil(StreamUtil streamUtil)
This method sets the stream-util. |
| Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableComponent |
|---|
getLogger, setLogger |
| Methods inherited from class net.sf.mmm.util.component.base.AbstractComponent |
|---|
doInitialized, getInitializationState, initialize |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static ProcessUtil instance
getInstance()private StreamUtil streamUtil
getStreamUtil()private Executor executor
getExecutor()| Constructor Detail |
|---|
public ProcessUtilImpl()
| Method Detail |
|---|
public static ProcessUtil getInstance()
ProcessUtilImpl.getInstance() methods and
construct new instances via the container-framework of your choice (like
plexus, pico, springframework, etc.). To wire up the dependent components
everything is properly annotated using common-annotations (JSR-250). If
your container does NOT support this, you should consider using a better
one.
protected void doInitialize()
initialization. It is
called when AbstractComponent.initialize() is invoked for the first time.super.AbstractComponent.doInitialize().
doInitialize in class AbstractLoggableComponentprotected Executor getExecutor()
Executor used to run asynchronous tasks. It
may use a thread-pool.
@Inject public void setExecutor(Executor executor)
executor.
executor - the executor to set.protected StreamUtil getStreamUtil()
@Inject public void setStreamUtil(StreamUtil streamUtil)
stream-util.
streamUtil - the streamUtil to set
public int execute(ProcessContext context,
ProcessBuilder... builders)
throws IOException,
InterruptedException
Processes configured by the given
builders. If more than one builder is
given, the according processes are piped.
execute in interface ProcessUtilcontext - is the context of the process pipe (fist stdin,
last stdout and stderr for all processes
as well as a potential timeout).builders - are the configurations of the Process(es) to
execute. The array needs to have a length greater than zero.
exit-code of the Process-pipe
configured by the given builders.
IOException - if an input/output-error occurred.
InterruptedException - if the calling Thread was interrupted
while waiting for a Process to
complete.
public int execute(ProcessContext context,
long timeout,
TimeUnit unit,
ProcessBuilder... builders)
throws IOException,
TimeoutException,
InterruptedException
Processes configured by the given
builders. If more than one builder is
given, the according processes are piped.threads, especially when
multiple processes are piped (2*n+1[+1] threads). Therefore you should NOT
use the singleton variant of this util except you are writing a simple
command-line client that does a simple job and then terminates. When
writing a server-application or library, that makes such calls repetitive,
you should create your own instance of ProcessUtil and configure a
thread-pool as Executor.
execute in interface ProcessUtilcontext - is the context of the process pipe (fist stdin,
last stdout and stderr for all processes
as well as a potential timeout).timeout - is the maximum amount of time to wait for the
Process-pipe to finish.unit - is the TimeUnit of the given timeout
argument.builders - are the configurations of the Process(es) to
execute. The array needs to have a length greater than zero.
exit-code of the Process-pipe
configured by the given builders.
IOException - if an input/output-error occurred.
TimeoutException - if the Process-pipe did NOT complete
before the given timeout (according to
unit).
InterruptedException - if the calling Thread was interrupted
while waiting for the Process-pipe to complete and before
the timeout occurred.
public AsyncProcessExecutor executeAsync(ProcessContext context,
ProcessBuilder... builders)
throws IOException
Processes configured by the given
builders as async task. If more than one
builder is given, the according processes are piped.threads, especially when
multiple processes are piped (2*n+1[+1] threads). Therefore you should NOT
use the singleton variant of this util except you are writing a simple
command-line client that does a simple job and then terminates. When
writing a server-application or library, that makes such calls repetitive,
you should create your own instance of ProcessUtil and configure a
thread-pool as Executor.
executeAsync in interface ProcessUtilcontext - is the context of the process pipe (fist stdin,
last stdout and stderr for all processes
as well as a potential timeout).builders - are the configurations of the Process(es) to
execute. The array needs to have a length greater than zero.
exit-code of the Process-pipe
configured by the given builders.
IOException - if an input/output-error occurred while setting up the
Process(es).
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||