|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface VNCRobotThread
This interface allows to use the VNCRobot automated tasks in multi-threaded third party applications.
A VNCRobot thread typically performs one automated task. If you run VNCRobot as an application in the CLI mode to execute a test script, it actually creates a single thread and executes it. The thread life cycle is:
To create a VNCRobot thread, instantiate the com.vncrobot.VNCRobot
class and call the method
createVNCRobotThread(String threadId, String params[], PrintStream logStream, boolean exitOnFinish)
where:
threadId
should be a unique string (name) identifying the process, e.g. "my automated task #1"
.params
is a string array with VNCRobot CLI options. To obtain a complete list of available options
see the VNCRobot CLI Options document
or run the VNCRobot executable with the --help
option. Options followed by a value should be specified
as two strings in the array, e.g. new String[] { "--connect", "localhost:1", "--password", "welcome" }
.logStream
. To print the logs into the console window use
System.out
as value. A null
value of this argument will suppress all log messages.
exitOnFinish
indicates whether the process should terminate using
System.exit(exitCode)
after the automated task gets finished. Third party applications should
use the value of false
to prevent termination of their Java VM.If you need to modify behavior of an individual thread, you may take advantage of the -o
or
--option
. For the list of available options review
the DefaultConfiguration.properties default
configuration file.
The following example starts two VNCRobot threads. The first one connects to VNC server at localhost:1 and
executes script /root/thread1.txt
. The other one connects to VNC server localhost:2 and executes
another script /root/thread2.txt
. Note that both the threads will be executed simultaneously and
the program exits when the last thread finishes.
IMPORTANT NOTE: This is version has one major limitation:import com.vncrobot.VNCRobot; import com.vncrobot.api.VNCRobotThread; public class TwoTasks { public static void main(String[] argv) { VNCRobot robot = new VNCRobot(); String args1[] = { "-c", "localhost:1", "-p", "welcome", "-n", "-r", "/root/thread1.txt" }; VNCRobotThread thread1 = robot.createVNCRobotThread("cli-1", args1, System.out, false); Thread t1 = new Thread(thread1); t1.start(); String args2[] = { "-c", "localhost:2", "-p", "welcome", "-n", "-r", "/root/thread2.txt" }; VNCRobotThread thread2 = robot.createVNCRobotThread("cli-2", args2, System.out, false); Thread t2 = new Thread(thread2); t2.start(); } }
-n
or --nodisplay
among the thread parameters.Since: VNCRobot 1.3
(C) 2006 Robert Pes. All rights reserved. Date: Dec 9, 2006, 11:02:41 AM
Method Summary | |
---|---|
int |
getExitCode()
Get the thread exit code which should reflect result of the script execution. |
java.lang.String |
getId()
Get the thread ID assigned during the thread creation. |
boolean |
isConnected()
Returns true if the thread is connected to a VNC server. |
boolean |
isConsoleMode()
Returns true if the thread is running in console/CLI mode (i.e. |
boolean |
isRunning()
Returns true if the thread is executing a script, false if not. |
void |
stop()
Stop the thread. |
Methods inherited from interface java.lang.Runnable |
---|
run |
Method Detail |
---|
boolean isConsoleMode()
boolean isRunning()
false
may indicate
that the thread is not started, it failed or finished, or it is in the initial or shutdown countdown phase.
Note that if you need to find out whether the thread is started or has finished, you should rather use
the Thread.isAlive()
method.
boolean isConnected()
void stop()
int getExitCode()
Get the thread exit code which should reflect result of the script execution. Value of zero usually indicates
successful execution, non-zero values mean failures. See the Exit
command in the VNCRobot Language
Specification document for more info on exit codes.
Threads stopped by the stop()
method always return zero unless an internal error occurs.
java.lang.String getId()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |