public class Commander
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
(package private) static java.lang.String |
allSubjectType
cMsg message subject or type used in internal Commander/Executor communication.
|
(package private) static java.lang.String |
remoteExecSubjectType
cMsg message subject or type used in internal Commander/Executor communication.
|
Constructor and Description |
---|
Commander(java.lang.String udl,
java.lang.String name,
java.lang.String description,
java.lang.String password)
Create this object given parameters needed to make a connection to the
cMsg server.
|
Modifier and Type | Method and Description |
---|---|
void |
cancelCallback(CommandReturn commandReturn)
Cancel a callback previously registered by calling
startProcess(ExecutorInfo, String, boolean, CommandCallback , Object) . |
void |
connectToServer(java.lang.String udl,
java.lang.String name,
java.lang.String description)
Connect to the specified cMsg server.
|
void |
findExecutors(int milliseconds)
Find all executors currently running.
|
java.util.Collection<ExecutorInfo> |
getExecutors()
Get the collection of known Executors.
|
void |
kill(ExecutorInfo exec,
boolean killProcesses)
Kill the specified executor and, optionally, all processes it has started.
|
void |
killAll(boolean killProcesses)
Kill all executors and, optionally, all processes they have started.
|
static void |
main(java.lang.String[] args)
Take keyboard input, pass as commands to one Executor,
and print results - like a simple remote terminal.
|
static void |
main0(java.lang.String[] args)
Run the command "ls" inside an xterm in all Executors.
|
static void |
main1(java.lang.String[] args)
RStart up 20 xterms in one Executor, then shut them down one-by-one.
|
static void |
main2(java.lang.String[] args)
Run the ExampleThread object as a thread in a single
Executor, wait 5 sec, and then shut it down.
|
static void |
main3(java.lang.String[] args)
Run a cMsg server a thread in a single
Executor, wait 5 sec, and then shut it down.
|
static void |
main4(java.lang.String[] args)
Kill all Executors and their spawned processes either 1-by-1 or all at once.
|
boolean |
reconnectToServer()
Tries to connect to the last cMsg server successfully connected to.
|
java.util.List<CommandReturn> |
startCommandInWindows(java.util.List<ExecutorInfo> executors,
java.lang.String command,
int widthChars,
int heightChars)
This method is example of how to make a bunch of identical xterm windows
fill the screen in a conveniently packed manner and run a single given command
in each of the xterms.
|
java.util.List<CommandReturn> |
startCommandsInWindows(java.util.List<ExecutorInfo> executors,
java.util.List<java.lang.String> commands,
int widthChars,
int heightChars)
This method is example of how to make a bunch of identical xterm windows
fill the screen in a conveniently packed manner and run a single, different
command in each of the xterms.
|
(package private) CommandReturn |
startProcess(ExecutorInfo exec,
java.lang.String cmd,
boolean monitor,
boolean wait,
CommandCallback callback,
java.lang.Object userObject,
int timeout)
Start an external process using the specified executor.
|
CommandReturn |
startProcess(ExecutorInfo exec,
java.lang.String cmd,
boolean monitor,
CommandCallback callback,
java.lang.Object userObject)
This method is an asynchronous means of starting an external process
using the specified executor.
|
CommandReturn |
startProcess(ExecutorInfo exec,
java.lang.String cmd,
boolean monitor,
int timeout)
This method is a synchronous means of starting an external process
using the specified executor and waiting for it to finish.
|
(package private) CommandReturn |
startThread(ExecutorInfo exec,
java.lang.String className,
boolean wait,
CommandCallback callback,
java.lang.Object userObject,
int timeout,
ConstructorInfo constructorArgs)
Starts an internal thread in the specified executor and immediately
returns.
|
(package private) CommandReturn |
startThread(ExecutorInfo exec,
java.lang.String className,
CommandCallback callback,
java.lang.Object userObject,
ConstructorInfo constructorArgs)
This method is an asynchronous means of starting an internal thread
in the specified executor and immediately returns.
|
CommandReturn |
startThread(ExecutorInfo exec,
java.lang.String className,
int timeout,
ConstructorInfo constructorArgs)
This method is a synchronous means of starting an internal thread
in the specified executor and waiting for it to finish.
|
java.util.List<CommandReturn> |
startWindows(ExecutorInfo exec,
java.lang.String title,
int count,
int widthChars,
int heightChars)
This method is example of how to make a bunch of identical xterm windows
fill the screen in a conveniently packed manner.
|
CommandReturn |
startXterm(ExecutorInfo exec,
java.lang.String cmd,
java.lang.String geometry,
java.lang.String title)
Start an xterm and run the specified command in it using the specified executor.
|
void |
stop(ExecutorInfo exec,
CommandReturn commandReturn)
Stop the given process or thread on the specified executor.
|
void |
stop(ExecutorInfo exec,
int commandId)
Stop the given process or thread on the specified executor.
|
void |
stopAll()
Stop all processes and threads on all executors.
|
void |
stopAll(ExecutorInfo exec)
Stop all processes and threads on the specified executor.
|
static java.util.List<java.lang.String> |
xtermGeometry(int count,
int widthChars,
int heightChars)
This method calculates the geometry specification of a given number of
identical xterm windows on the local display screen in a conveniently
packed manner.
|
static final java.lang.String allSubjectType
static final java.lang.String remoteExecSubjectType
public Commander(java.lang.String udl, java.lang.String name, java.lang.String description, java.lang.String password) throws cMsgException
udl
- UDL to connect to cMsg server.name
- unique name used to connect to cMsg server.password
- unique string used to connect to cMsg server.
It may be null but must be <= 16 characters if not null.description
- description used to connect to cMsg server.cMsgException
- if error connecting to cMsg server; password is > 16 characterspublic boolean reconnectToServer() throws cMsgException
false
(nothing done) if already connected,
true
if a new connection is made.cMsgException
- if cannot connect.public void connectToServer(java.lang.String udl, java.lang.String name, java.lang.String description) throws cMsgException
udl
- UDL to connect to cMsg server.name
- unique name used to connect to cMsg server.description
- description used to connect to cMsg server.cMsgException
- if cannot connect.public void findExecutors(int milliseconds) throws cMsgException
milliseconds
- number of milliseconds to wait for responses from executors.cMsgException
- if not connected to cMsg server.public java.util.Collection<ExecutorInfo> getExecutors()
public void kill(ExecutorInfo exec, boolean killProcesses) throws cMsgException
exec
- object specifying executor.killProcesses
- false
to leave spawned processes running,
else true
to kill them too.cMsgException
- if no connection to cMsg server or error sending messagepublic void killAll(boolean killProcesses) throws cMsgException
killProcesses
- false
to leave spawned processes running,
else true
to kill them too.cMsgException
- if no connection to cMsg server or error sending messagepublic void stop(ExecutorInfo exec, CommandReturn commandReturn) throws cMsgException
exec
- object specifying executor.commandReturn
- object specifying process or thread to stopcMsgException
- if no connection to cMsg server or error sending messagepublic void stop(ExecutorInfo exec, int commandId) throws cMsgException
exec
- object specifying executor.commandId
- id of process or thread to stopcMsgException
- if no connection to cMsg server or error sending messagepublic void stopAll(ExecutorInfo exec) throws cMsgException
exec
- object specifying executor.cMsgException
- if no connection to cMsg server or error sending message.public void stopAll() throws cMsgException
cMsgException
- if no connection to cMsg server or error sending message.public void cancelCallback(CommandReturn commandReturn)
startProcess(ExecutorInfo, String, boolean, CommandCallback , Object)
.commandReturn
- object associated with callback.public CommandReturn startProcess(ExecutorInfo exec, java.lang.String cmd, boolean monitor, CommandCallback callback, java.lang.Object userObject) throws cMsgException
exec
- Executor to start process with.cmd
- command that Executor will run.monitor
- true
if output of the command should be captured and returned,
else false
.callback
- callback to be run when process ends.userObject
- object to be passed to callback as argument.cMsgException
- if arg is null, cmsg sendAndGet communication fails or takes too long,
or internal protocol errorpublic CommandReturn startProcess(ExecutorInfo exec, java.lang.String cmd, boolean monitor, int timeout) throws cMsgException, java.util.concurrent.TimeoutException
exec
- Executor to start process with.cmd
- command that Executor will run.monitor
- true
if output of the command should be captured and returned,
else false
.timeout
- milliseconds to wait for reply (coming via asynchronous messaging system),
0 means wait forever.cMsgException
- if arg is null, cmsg communication fails, or internal protocol errorjava.util.concurrent.TimeoutException
- if process/thread return time exceeds timeout time.CommandReturn startProcess(ExecutorInfo exec, java.lang.String cmd, boolean monitor, boolean wait, CommandCallback callback, java.lang.Object userObject, int timeout) throws cMsgException, java.util.concurrent.TimeoutException
exec
- Executor to start process with.cmd
- command that Executor will run.monitor
- true
if output of the command should be captured and returned,
else false
.wait
- true
if executor waits for the process to complete before responding,
else false
.callback
- callback to be run when process ends.userObject
- object to be passed to callback as argument.timeout
- milliseconds to wait for reply (coming via asynchronous messaging system),
0 means wait forever.cMsgException
- if arg is null, cmsg communication fails, or internal protocol errorjava.util.concurrent.TimeoutException
- if process/thread return time exceeds timeout time.CommandReturn startThread(ExecutorInfo exec, java.lang.String className, CommandCallback callback, java.lang.Object userObject, ConstructorInfo constructorArgs) throws cMsgException
exec
- Executor to start thread in.className
- name of java class to instantiate and run as thread in executor.callback
- callback to be run when thread ends.userObject
- object to be passed to callback.constructorArgs
- object containing className constructor's arguments.
May be null.cMsgException
- if cmsg communication fails or takes too long,
or internal protocol errorpublic CommandReturn startThread(ExecutorInfo exec, java.lang.String className, int timeout, ConstructorInfo constructorArgs) throws cMsgException, java.util.concurrent.TimeoutException
exec
- Executor to start thread in.className
- name of java class to instantiate and run as thread in executor.timeout
- milliseconds to wait for reply (coming via asynchronous messaging system),
0 means wait forever.constructorArgs
- object containing className constructor's arguments.
May be null.cMsgException
- if cmsg communication fails or internal protocol errorjava.util.concurrent.TimeoutException
- if cmsg communication times outCommandReturn startThread(ExecutorInfo exec, java.lang.String className, boolean wait, CommandCallback callback, java.lang.Object userObject, int timeout, ConstructorInfo constructorArgs) throws cMsgException, java.util.concurrent.TimeoutException
exec
- Executor to start thread in.className
- name of java class to instantiate and run as thread in executor.wait
- true
if executor waits for the process to complete before responding,
else false
.callback
- callback to be run when process ends.userObject
- object to be passed to callback.timeout
- milliseconds to wait for reply (coming via asynchronous messaging system),
0 means wait forever.constructorArgs
- object containing className constructor's arguments.
May be null.cMsgException
- if args null, cmsg communication fails, or internal protocol errorjava.util.concurrent.TimeoutException
- if cmsg communication times outpublic static java.util.List<java.lang.String> xtermGeometry(int count, int widthChars, int heightChars)
count
- number of xterms.widthChars
- width of each xterm in characters.heightChars
- number of lines in each xterm.public CommandReturn startXterm(ExecutorInfo exec, java.lang.String cmd, java.lang.String geometry, java.lang.String title) throws cMsgException
NOTE: The command to run must not have any arguments (or white space) or it will most likely fail. If the desired command needs arguments, put it in a shell script and use the script name as the command.
exec
- Executor to start process with.cmd
- command that Executor will run inside xterm. May be null.
Must not have args.geometry
- geometry info in the form WxH+-X+-Y with W and H in chars, X and Y in pixels;
for example 75x10+0+200 or 75x10-10-20. May be null.title
- window title. May be null.cMsgException
- if arg is null, cmsg communication fails or takes too long,
internal protocol error, or white space in cmdpublic java.util.List<CommandReturn> startWindows(ExecutorInfo exec, java.lang.String title, int count, int widthChars, int heightChars) throws cMsgException
exec
- Executor to use.title
- title of xterm windows.count
- number of windows to make.widthChars
- width of each xterm in characters.heightChars
- number of lines in each xterm.cMsgException
- when starting the xterm, if cmsg communication fails or takes too long or
internal protocol errorpublic java.util.List<CommandReturn> startCommandInWindows(java.util.List<ExecutorInfo> executors, java.lang.String command, int widthChars, int heightChars) throws cMsgException
NOTE: The command to run must not have any arguments (or white space) or it will most likely fail. If the desired command needs arguments, put it in a shell script and use the script name as the command.
executors
- list of Executors to use.command
- command to run in each executor which must not have args.widthChars
- width of each xterm in characters.heightChars
- number of lines in each xterm.cMsgException
- when starting xterm, if cmsg communication fails or takes too long,
internal protocol error, or white space in cmdpublic java.util.List<CommandReturn> startCommandsInWindows(java.util.List<ExecutorInfo> executors, java.util.List<java.lang.String> commands, int widthChars, int heightChars) throws cMsgException
NOTE: The commands to run must not have any arguments (or white space) or they will most likely fail. If the desired commands need arguments, put each in its own shell script and use the script name as the command.
executors
- list of Executors to use.commands
- list of commands to run, one in each executor. Must not have args.widthChars
- width of each xterm in characters.heightChars
- number of lines in each xterm.cMsgException
- when starting xterm, if cmsg communication fails or takes too long,
internal protocol error, or white space in cmdpublic static void main0(java.lang.String[] args)
args
- arguments.public static void main1(java.lang.String[] args)
args
- arguments.public static void main2(java.lang.String[] args)
args
- arguments.public static void main3(java.lang.String[] args)
args
- arguments.public static void main4(java.lang.String[] args)
args
- arguments.public static void main(java.lang.String[] args)
args
- arguments.