com.jscape.inet.telnet

## Class TelnetTask

- java.lang.Object
- - com.jscape.inet.telnet.TelnetAdapter
  - - com.jscape.inet.telnet.TelnetTask

- All Implemented Interfaces:
    TelnetListener, java.io.Serializable

      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

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `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

    Constructors
    Constructor and Description
    `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

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `cancel()` Cancels this task and subsequent tasks 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
    `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 `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`.
    `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.
    `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` | `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 `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` | `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.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`

    - #### setDebug

          public void setDebug(boolean debug)

      Enables/disables additional debugging for this task.
      Parameters:
        `debug` - true if debugging is enabled, false otherwise

    - #### setDebugStream

          public void setDebugStream(java.io.PrintStream debugStream)

      Sets debug stream to be used when printing debug messages. Default debug stream is System.out
      Parameters:
        `debugStream` - a PrintStream

    - #### getDebugStream

          public java.io.PrintStream getDebugStream()

      Gets debug stream used when printing debug messages. Default debug stream is System.out
      Returns:
        a PrintStream

    - #### getDebug

          public boolean getDebug()

      Checks whether debugging is enabled for this task.
      Returns:
        true if enabled, false otherwise

    - #### 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()`

    - #### getStatusString

          public java.lang.String getStatusString(int status)

      Gets status string based on task status
      Parameters:
        `status` - the status code
      Returns:
        the status
      See Also:
        `PENDING`, `ACTIVE`, `RUNNING`, `COMPLETE`

    - #### 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 and subsequent tasks by setting it's status to complete.

    - #### 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

    - #### 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

    - #### setRegexMatchLength

          public 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. Default value is 20.
      Parameters:
        `regexMatchLength` -

    - #### getRegexMatchLength

          public 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. Default value is 20.
      Returns:
        match length

    - #### 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
      See Also:
        `setRegexMatchLength(int)`

    - #### 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
      See Also:
        `setRegexMatchLength(int)`

Copyright © JSCAPE LLC. 1999-2021. All Rights Reserved