|
SSH Factory | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jscape.inet.ssh.SshAdapter
com.jscape.inet.ssh.SshTask
public class SshTask
The SshTask class represents a command to be executed in batch (non-interactive) mode on SSH server. In order to execute a command in batch mode the SshTask must know the following:
Start Prompt - The start prompt is the data that is sent back by the SSH server indicating that it is ready to execute the command. e.g. $ Message - The command is the command to be executed. e.g. ls -al End Prompt - The end prompt is the data that is sent back by the SSH server indicating that it has completed execution of the command. In most cases this is the same as the Start Prompt. e.g. $ When creating a new SshTask you must at a MINIMUM provide both the Message and End Prompt. In most cases a Start Prompt should be provided although you may provide anull
value in cases where you are not waiting for SSH server data but want the
command to be executed immediately.
Field Summary | |
---|---|
static int |
ACTIVE
SshTask is active and waiting for start prompt to execute command |
static int |
COMPLETE
SshTask has finished execution of command and has received end prompt |
static int |
PENDING
SshTask is waiting to be activated |
static int |
RUNNING
SshTask has received start prompt and is currently executing command |
Constructor Summary | |
---|---|
SshTask(java.lang.String startPrompt,
java.lang.String command,
java.lang.String endPrompt)
Constructs a new SshTask instance. |
|
SshTask(java.lang.String name,
java.lang.String startPrompt,
java.lang.String command,
java.lang.String endPrompt)
Constructs a new SshTask instance. |
Method Summary | |
---|---|
void |
cancel()
Cancels this task and subsequent tasks by setting it's status to complete. |
void |
dataReceived(SshDataReceivedEvent event)
Gets data received from Ssh server as fired by SshListener |
java.lang.String |
getCharacterSet()
Gets the character set |
java.lang.String |
getCommand()
Gets the command to execute |
boolean |
getDebug()
Checks whether debugging is enabled for this task. |
java.io.PrintStream |
getDebugStream()
Gets debug stream used when printing debug messages. |
java.lang.String |
getEndPrompt()
Gets the end shell prompt this SshTask should wait for to indicate that this SshTask is complete. |
long |
getEndPromptTimeout()
Gets the maximum timeout between the time the task is in running state and the expected end prompt is received. |
java.lang.String |
getName()
Gets name of this SshTask as defined in constructor. |
SshTask |
getNextTask()
Gets the next task executed after this SshTask . |
SshTask |
getPreviousTask()
Gets the SshTask executed prior to this SshTask . |
int |
getRegexMatchLength()
Gets the number of characters to read from the end of the response buffer when using regular expressions to detect start or end prompts. |
java.lang.String |
getResponse()
Gets response to command executed. |
SshScript |
getScript()
Gets the SshScript this SshTask is bound to. |
java.lang.String |
getStartPrompt()
Gets the shell prompt this SshTask should wait for before executing command. |
long |
getStartPromptTimeout()
Gets the maximum timeout between the time the task is in active state and the expected start prompt is received. |
int |
getStatus()
Gets completion status of this SshTask . |
java.lang.String |
getStatusString(int status)
Gets status string based on task status |
java.lang.String |
getTerminator()
Gets line terminator used when sending commands. |
boolean |
isActive()
Checks if this SshTask is active. |
boolean |
isComplete()
Checks if this SshTask is complete. |
boolean |
isEndPromptRegex()
Checks if end prompt is a regular expression |
boolean |
isPending()
Checks if this SshTask is pending activation. |
boolean |
isRunning()
Checks if this SshTask is running. |
boolean |
isStartPromptRegex()
Specified if start prompt is a regular expression |
boolean |
isTimedOut()
Checks if task has exceeded timeout |
void |
setCharacterSet(java.lang.String characterSet)
Sets character set used when write data |
void |
setDebug(boolean debug)
Enables/disables additional debugging for this task. |
void |
setDebugStream(java.io.PrintStream debugStream)
Sets debug stream to be used when printing debug messages. |
void |
setEndPromptRegex(boolean b)
Specifies if end prompt is a regular expression |
void |
setEndPromptTimeout(long endPromptTimeout)
Sets the maximum timeout between the time the task is in running state and the expected end prompt is received. |
void |
setRegexMatchLength(int regexMatchLength)
Sets the number of characters to read from the end of the response buffer when using regular expressions to detect start or end prompts. |
void |
setStartPromptRegex(boolean b)
Specifies if start prompt is a regular expression |
void |
setStartPromptTimeout(long startPromptTimeout)
Sets the maximum timeout between the time the task is in active state and the expected start prompt is received. |
void |
setTerminator(java.lang.String string)
Sets line terminator used when sending commands. |
Methods inherited from class com.jscape.inet.ssh.SshAdapter |
---|
connected, disconnected |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int PENDING
public static final int ACTIVE
public static final int RUNNING
public static final int COMPLETE
Constructor Detail |
---|
public SshTask(java.lang.String name, java.lang.String startPrompt, java.lang.String command, java.lang.String endPrompt)
SshTask
instance.
name
- a name to uniquely identify this SshTask
.startPrompt
- the shell prompt this task should wait for before executing command.command
- the command to executeendPrompt
- the end shell prompt this task should wait for to indicate that this task is finished.public SshTask(java.lang.String startPrompt, java.lang.String command, java.lang.String endPrompt)
SshTask
instance.
startPrompt
- the start data this task should wait for before executing command.command
- the command to executeendPrompt
- the end data this task should wait for to indicate that this task is finished.Method Detail |
---|
public SshTask getNextTask()
SshTask
.
SshTask
or null
if none foundpublic SshTask getPreviousTask()
SshTask
executed prior to this SshTask
.
SshTask
or null
if no previous SshTask
foundpublic SshScript getScript()
SshScript
this SshTask
is bound to.
SshScript
SshScript
public void setDebug(boolean debug)
debug
- true if debugging is enabled, false otherwisepublic void setDebugStream(java.io.PrintStream debugStream)
debugStream
- a PrintStreampublic java.io.PrintStream getDebugStream()
public boolean getDebug()
public void dataReceived(SshDataReceivedEvent event)
SshListener
dataReceived
in interface SshListener
dataReceived
in class SshAdapter
event
- a SshDataReceivedEvent
SshDataReceivedEvent
,
SshListener
public void cancel()
public java.lang.String getCommand()
public java.lang.String getStartPrompt()
SshTask
should wait for before executing command.
public java.lang.String getEndPrompt()
SshTask
should wait for to indicate that this SshTask
is complete.
public int getStatus()
SshTask
.
SshTask
PENDING
,
ACTIVE
,
RUNNING
,
COMPLETE
public java.lang.String getResponse()
isComplete()
public java.lang.String getStatusString(int status)
status
- the status code
PENDING
,
ACTIVE
,
RUNNING
,
COMPLETE
public boolean isPending()
SshTask
is pending activation.
true
if pending activation, false
otherwisepublic boolean isActive()
SshTask
is active.
true
if active, false
otherwisepublic boolean isRunning()
SshTask
is running.
true
if running, false
otherwisepublic boolean isComplete()
SshTask
is complete.
true
if complete, false
otherwisepublic java.lang.String getName()
SshTask
as defined in constructor.
SshTask
, Unknown
if not defined.public java.lang.String getTerminator()
public void setTerminator(java.lang.String string)
string
- line terminatorpublic long getEndPromptTimeout()
public long getStartPromptTimeout()
public void setEndPromptTimeout(long endPromptTimeout)
endPromptTimeout
- the timeout in millisecondspublic void setStartPromptTimeout(long startPromptTimeout)
startPromptTimeout
- the timeout in millisecondspublic boolean isEndPromptRegex()
public boolean isStartPromptRegex()
public void setEndPromptRegex(boolean b) throws SshException
b
- true if end prompt is a regular expression, false otherwise
SshException
- if the end prompt is an invalid regular expressionsetRegexMatchLength(int)
public void setStartPromptRegex(boolean b) throws SshException
b
- true if start prompt is a regular expression, false otherwise
SshException
- if the start prompt is an invalid regular expressionsetRegexMatchLength(int)
public void setRegexMatchLength(int regexMatchLength)
regexMatchLength
- public int getRegexMatchLength()
public boolean isTimedOut()
public void setCharacterSet(java.lang.String characterSet)
characterSet
- the character setpublic java.lang.String getCharacterSet()
|
SSH Factory | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |