SSH Factory

com.jscape.inet.telnet
Class TelnetTask

java.lang.Object
  extended bycom.jscape.inet.telnet.TelnetAdapter
      extended bycom.jscape.inet.telnet.TelnetTask
All Implemented Interfaces:
java.io.Serializable, TelnetListener

public class TelnetTask
extends TelnetAdapter
implements java.io.Serializable

The TelnetTask class represents a command to be executed in batch (non-interactive) mode. In order to execute a command in batch mode the TelnetTask must know the following:

Start Prompt - The start prompt is the data that is sent back by the Telnet server indicating that it is ready to execute the command. e.g. user@localhost$

Command - 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 Telnet server indicating that it has completed execution of the command. In most cases this is the same as the Start Prompt. e.g. user@localhost$

When creating a new TelnetTask you must at a MINIMUM provide both the Command and End Prompt. In most cases a Start Prompt should be provided although you may provide a null value in cases where you are not waiting for Telnet server data but want the command to be executed immediately.

See Also:
Serialized Form

Field Summary
static int ACTIVE
          TelnetTask is active and waiting for start prompt to execute command
static int COMPLETE
          TelnetTask has finished execution of command and has received end prompt
static int PENDING
          TelnetTask is waiting to be activated
static int RUNNING
          TelnetTask has received start prompt and is currently executing command
 
Constructor Summary
TelnetTask(java.lang.String startPrompt, java.lang.String command, java.lang.String endPrompt)
          Constructs a new TelnetTask instance.
TelnetTask(java.lang.String name, java.lang.String startPrompt, java.lang.String command, java.lang.String endPrompt)
          Constructs a new TelnetTask instance.
 
Method Summary
 void cancel()
          Cancels this task by setting it's status to complete.
 void dataReceived(TelnetDataReceivedEvent event)
          Gets data received from Telnet server as fired by TelnetListener
 java.lang.String getCommand()
          Gets the command to execute
 java.lang.String getEndPrompt()
          Gets the end shell prompt this TelnetTask should wait for to indicate that this TelnetTask 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 TelnetTask as defined in constructor.
 TelnetTask getNextTask()
          Gets the next task executed after this TelnetTask.
 TelnetTask getPreviousTask()
          Gets the TelnetTask executed prior to this TelnetTask.
 java.lang.String getResponse()
          Gets response to command executed.
 TelnetScript getScript()
          Gets the TelnetScript this TelnetTask is bound to.
 java.lang.String getStartPrompt()
          Gets the shell prompt this TelnetTask 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 TelnetTask.
 java.lang.String getTerminator()
          Gets line terminator used when sending commands.
 long getTimeout()
          Deprecated. replaced by getEndPromptTimeout method
 boolean isActive()
          Checks if this TelnetTask is active.
 boolean isComplete()
          Checks if this TelnetTask is complete.
 boolean isEndPromptRegex()
          Checks if end prompt is a regular expression
 boolean isPending()
          Checks if this TelnetTask is pending activation.
 boolean isRunning()
          Checks if this TelnetTask is running.
 boolean isStartPromptRegex()
          Specified if start prompt is a regular expression
 boolean isTimedOut()
          Checks if task has exceeded timeout
 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 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.
 void setTimeout(long timeout)
          Deprecated. replaced by setEndPromptTimeout method
 
Methods inherited from class com.jscape.inet.telnet.TelnetAdapter
connected, disconnected, dontOption, doOption, doSubOption, willOption, wontOption
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PENDING

public static final int PENDING
TelnetTask is waiting to be activated

See Also:
Constant Field Values

ACTIVE

public static final int ACTIVE
TelnetTask is active and waiting for start prompt to execute command

See Also:
Constant Field Values

RUNNING

public static final int RUNNING
TelnetTask has received start prompt and is currently executing command

See Also:
Constant Field Values

COMPLETE

public static final int COMPLETE
TelnetTask has finished execution of command and has received end prompt

See Also:
Constant Field Values
Constructor Detail

TelnetTask

public TelnetTask(java.lang.String name,
                  java.lang.String startPrompt,
                  java.lang.String command,
                  java.lang.String endPrompt)
Constructs a new TelnetTask instance.

Parameters:
name - a name to uniquely identify this TelnetTask.
startPrompt - the shell prompt this task should wait for before executing command.
command - the command to execute
endPrompt - the end shell prompt this task should wait for to indicate that this task is finished.

TelnetTask

public TelnetTask(java.lang.String startPrompt,
                  java.lang.String command,
                  java.lang.String endPrompt)
Constructs a new TelnetTask instance.

Parameters:
startPrompt - the start data this task should wait for before executing command.
command - the command to execute
endPrompt - the end data this task should wait for to indicate that this task is finished.
Method Detail

getNextTask

public TelnetTask getNextTask()
Gets the next task executed after this TelnetTask.

Returns:
the next TelnetTask or null if none found

getPreviousTask

public TelnetTask getPreviousTask()
Gets the TelnetTask executed prior to this TelnetTask.

Returns:
the previous TelnetTask or null if no previous TelnetTask found

getScript

public TelnetScript getScript()
Gets the TelnetScript this TelnetTask is bound to.

Returns:
a TelnetScript
See Also:
TelnetScript

dataReceived

public void dataReceived(TelnetDataReceivedEvent event)
Gets data received from Telnet server as fired by TelnetListener

Specified by:
dataReceived in interface TelnetListener
Overrides:
dataReceived in class TelnetAdapter
Parameters:
event - a TelnetDataReceivedEvent
See Also:
TelnetDataReceivedEvent, TelnetListener

getCommand

public java.lang.String getCommand()
Gets the command to execute

Returns:
the command to execute

getStartPrompt

public java.lang.String getStartPrompt()
Gets the shell prompt this TelnetTask should wait for before executing command.

Returns:
the start shell prompt

getEndPrompt

public java.lang.String getEndPrompt()
Gets the end shell prompt this TelnetTask should wait for to indicate that this TelnetTask is complete.

Returns:
the end shell prompt

getStatus

public int getStatus()
Gets completion status of this TelnetTask.

Returns:
the completion status of this TelnetTask
See Also:
PENDING, ACTIVE, RUNNING, COMPLETE

getResponse

public java.lang.String getResponse()
Gets response to command executed. Response will be empty if command has not executed.

Returns:
the response to command executed
See Also:
isComplete()

isPending

public boolean isPending()
Checks if this TelnetTask is pending activation.

Returns:
true if pending activation, false otherwise

isActive

public boolean isActive()
Checks if this TelnetTask is active.

Returns:
true if active, false otherwise

isRunning

public boolean isRunning()
Checks if this TelnetTask is running.

Returns:
true if running, false otherwise

isComplete

public boolean isComplete()
Checks if this TelnetTask is complete.

Returns:
true if complete, false otherwise

getName

public java.lang.String getName()
Gets name of this TelnetTask as defined in constructor.

Returns:
name of this TelnetTask, null if not defined.

getTerminator

public java.lang.String getTerminator()
Gets line terminator used when sending commands. Default is LF (Line Feed).

Returns:
line terminator

setTerminator

public void setTerminator(java.lang.String string)
Sets line terminator used when sending commands. Default is LF (Line Feed).

Parameters:
string - line terminator

cancel

public void cancel()
Cancels this task by setting it's status to complete.


getTimeout

public long getTimeout()
Deprecated. replaced by getEndPromptTimeout method

Gets timeout used by task to determine when to abort task if end prompt is not received within specified timeout after task is started. Default timeout is 120000ms (2 minutes)

Returns:
the task timeout
See Also:
getEndPromptTimeout()

getEndPromptTimeout

public long getEndPromptTimeout()
Gets the maximum timeout between the time the task is in running state and the expected end prompt is received.

Returns:
the timeout in milliseconds

getStartPromptTimeout

public long getStartPromptTimeout()
Gets the maximum timeout between the time the task is in active state and the expected start prompt is received.

Returns:
the timeout in milliseconds

setTimeout

public void setTimeout(long timeout)
Deprecated. replaced by setEndPromptTimeout method

Sets timeout used by task to determine when to abort task if end prompt is not received within specified timeout after task is started. Default timeout is 120000ms (2 minutes)

Parameters:
timeout - the task timeout
See Also:
setEndPromptTimeout(long)

setEndPromptTimeout

public void setEndPromptTimeout(long endPromptTimeout)
Sets the maximum timeout between the time the task is in running state and the expected end prompt is received.

Parameters:
endPromptTimeout - the timeout in milliseconds

setStartPromptTimeout

public void setStartPromptTimeout(long startPromptTimeout)
Sets the maximum timeout between the time the task is in active state and the expected start prompt is received.

Parameters:
startPromptTimeout - the timeout in milliseconds

isTimedOut

public boolean isTimedOut()
Checks if task has exceeded timeout

Returns:
true if timeout exceeded, false otherwise

isEndPromptRegex

public boolean isEndPromptRegex()
Checks if end prompt is a regular expression

Returns:
true if is a regular expression, false otherwise

isStartPromptRegex

public boolean isStartPromptRegex()
Specified if start prompt is a regular expression

Returns:
true if is a regular expression, false otherwise

setEndPromptRegex

public void setEndPromptRegex(boolean b)
                       throws TelnetException
Specifies if end prompt is a regular expression

Parameters:
b - true if end prompt is a regular expression, false otherwise
Throws:
TelnetException - if the end prompt is an invalid regular expression

setStartPromptRegex

public void setStartPromptRegex(boolean b)
                         throws TelnetException
Specifies if start prompt is a regular expression

Parameters:
b - true if start prompt is a regular expression, false otherwise
Throws:
TelnetException - if the start prompt is an invalid regular expression

SSH Factory

Copyright JSCAPE 2004 All Rights Reserved