public class ProcessDaemon extends java.lang.Object implements Launcher
launch(java.lang.String[],boolean,boolean,boolean)
where
the child process has its STDIO connected to the terminal (such that the user can
interact with the program)
launch(java.lang.String[],int,int)
where the child
process has its STDIO redirected to and/or from caller specified streams.
This is designed to launch processes on a remote network node.
Modifier and Type | Field and Description |
---|---|
private ChildProcessFactory |
factory
Helper to create interactive child processes in a UI independent manner.
|
private static java.lang.Object |
modToken
Token used to authenticate with the dispatcher when registering APIs.
|
private StreamDaemon |
sd
Stream daemon (provides access to streams by id).
|
Constructor and Description |
---|
ProcessDaemon(ChildProcessFactory factory,
boolean single,
StreamDaemon sd)
Initializes the process server.
|
Modifier and Type | Method and Description |
---|---|
int |
launch(java.lang.String[] cmdlist,
boolean silent,
boolean wait,
boolean console)
Launches the external executable specified by the
cmdlist taking into account
the flags which specify synchronous or asynchronous operation and whether a prompt is
provided after the child process terminates. |
void |
launch(java.lang.String[] cmdlist,
int sout,
int sin)
Launches the external executable specified by the
cmdlist on an asynchronous
basis. |
private static java.lang.String[] |
prepareCommandLine(java.lang.String[] cmdlist,
boolean missing,
boolean iact,
boolean inConsole)
Converts the given command list into a form that is suitable for process launching.
|
private static java.lang.Object modToken
private ChildProcessFactory factory
private StreamDaemon sd
public ProcessDaemon(ChildProcessFactory factory, boolean single, StreamDaemon sd)
factory
- Helper to create interactive child processes in a UI independent manner.single
- true
to startup within the server process which must bypass the
shared infrastructure initialization. Use false
for the normal
client JVM startup.sd
- Provides translation from id to stream instance.public int launch(java.lang.String[] cmdlist, boolean silent, boolean wait, boolean console)
cmdlist
taking into account
the flags which specify synchronous or asynchronous operation and whether a prompt is
provided after the child process terminates. The command is always executed as a child
process of the shell which is a child process of the JVM process on the node in which this
is served.
STDIN
, STDOUT
and STDERR
of the child process are
mapped into the PTY (terminal) of the JVM process. In other words, this child process has
capability to be interactive with the user.
Since the Runtime.exec()
process launching method of J2SE does not provide a
terminal/console to the launched child process, that method cannot be used to launch this
child process. For example, it is impossible to get J2SE child processes to be
interactive with the user. For this reason, an alternate process launching infrastructure
is used, which relies on native code for launching. This native code is accessed via a
plugin architecture that allows different native code implementations, based on the
different client types in use.
All proper wait and pause semantics are honored and the current process' terminal processing is properly suspended and resumed as needed.
launch
in interface Launcher
cmdlist
- The command line to be executed, with the first element used as the program to
run and all other array elements as the arguments.silent
- If true
the default prompt is suppressed. Otherwise, a pause is
implemented when the child process exits.wait
- If true
, synchronous operation is requested which waits for the
termination of the child process on the current thread. If false
,
a thread will be started to wait for the child process termination and to
subsequently handle cleanup (asynchronous mode).console
- If true
, the process is starting in a separate new console,
false
means using 4GL no-console option.public void launch(java.lang.String[] cmdlist, int sout, int sin)
cmdlist
on an asynchronous
basis. The command is always executed as a child process of the shell which is a child
process of the the JVM process on the node in which this is served. This corresponds to
the standard concept of "co-processing" where the parent process and child process are
both running at the same time and they interact in one direction or both directions by
reading and/or writing from connected pipes.
This is a redirected mode process launch. The STDIN
, STDOUT
and
STDERR
are all linked from the child process to the passed streams if those
parameters are not -1. Any pipes which are not to be linked are closed immediately. Those
pipes which are connected with the passed streams must be closed by the caller. Please see
the ProcessStream
for more details.
launch
in interface Launcher
cmdlist
- The command line to be executed, with the first element used as the program to
run and all other array elements as the arguments.sout
- The id of a ProcessStream
instance to be connected to the child
process' STDOUT
and STDERR
or -1 for no connection.
Used for reading.sin
- The id of a ProcessStream
instance to be connected to the child
process' STDIN
or -1 for no connection. Used for writing.private static java.lang.String[] prepareCommandLine(java.lang.String[] cmdlist, boolean missing, boolean iact, boolean inConsole)
cmdlist
- The command to execute (already split into whitespace delimited pieces).missing
- If the native terminal is missing from our process, we must force the
shell to enable job control (only on non-Windows platforms).iact
- Interactive flag (true
if not in silent mode AND if the 4GL session
will wait for the child process to complete before continuing).inConsole
- If true
, the process is starting in a separate new console,
false
means using 4GL no-console option.