mstar
Class Connection

java.lang.Object
  |
  +--mstar.Connection
Direct Known Subclasses:
TinyMudConnection

public abstract class Connection
extends java.lang.Object

The connection class is an abstract base class that is used to manage the connection for a collaborative environment session.

Version:
1.6
Author:
Thaddeus O. Cooper (cooper@tweenproject.org)

Constructor Summary
Connection()
          Initialize the connection class with a null hostname and set the port to connect to the collaborative environment at to the default of 4201.
Connection(int port)
          Initialize the connection class with a null hostname and set the port to connect to the collaborative environment at to the given port number.
Connection(java.lang.String hostname)
          Initialize the connection class with hostname and set the port to connect to the collaborative environment at to the default of 4201.
Connection(java.lang.String hostname, int port)
          Initialize the connection class with hostname and set the port to connect to the collaborative environment at to the given port number.
 
Method Summary
 int available()
          Returns the number of bytes that can be read from the collaborative environment without blocking.
abstract  void clearChatterVector()
          Clears the chatter vector that output from the collaborative environment is being stored in.
 void connectToMud()
          Connect the robot to the Mud/MOO.
 void drainConnection()
          Drain the connection until there is no more output waiting to be collected.
abstract  void drainConnection(boolean wait)
          Drain the connection until there is no more output waiting to be collected.
 void drainConnectionToSuffix()
          Drain the output from the collaborative environment until the suffix that was set using setOutputSuffix is found.
abstract  void drainConnectionToSuffix(boolean wait)
          Drain the output from the collaborative environment until the suffix that was set using setOutputSuffix is found.
abstract  void findOutputPrefix()
          Find the output prefix in the input stream.
abstract  java.util.Vector getChatterVector()
          Returns the chatter vector that output from the collaborative environment is stored in for later processing.
 java.lang.String getHostname()
          Gets the hostname to connect to.
 java.io.DataInputStream getInputStream()
          Gets the stream for receiving data from the collaborative environment.
 java.lang.String getOutputPrefix()
          Gets the string that will be used for the output prefix in commands returned by the collaborative environment.
 java.io.PrintStream getOutputStream()
          Gets the stream for sending data to the collaborative environment.
 java.lang.String getOutputSuffix()
          Gets the string that will be used for the output suffix in commands returned by the collaborative environment.
 int getPort()
          Gets the port to connect at.
 java.lang.String getRobotName()
          Gets the name of the robot.
abstract  void loginToMud(java.lang.String name, java.lang.String password)
          Log the robot into the Mud/MOO.
abstract  void logOffMud()
          Log the robot off the MUD/MOO.
 java.lang.String readLine()
          Read a line of output from the MUD/MOO.
 void setHostname(java.lang.String hostname)
          Sets the hostname to connect to.
 void setOutputPrefix(java.lang.String outputPrefix)
          Sets the string that will be used for the output prefix in commands returned by the collaborative environment.
 void setOutputSuffix(java.lang.String outputSuffix)
          Sets the string that will be used for the output suffix in commands returned by the collaborative environment.
 void setPort(int port)
          Sets the port to connect at.
 void setRobotName(java.lang.String robotName)
          Sets the name of the robot.
 void waitForData()
          Wait until data becomes available from the collaborative environment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Connection

public Connection()
Initialize the connection class with a null hostname and set the port to connect to the collaborative environment at to the default of 4201.

Connection

public Connection(java.lang.String hostname)
Initialize the connection class with hostname and set the port to connect to the collaborative environment at to the default of 4201.
Parameters:
hostname - the name of the host to connect to.

Connection

public Connection(java.lang.String hostname,
                  int port)
Initialize the connection class with hostname and set the port to connect to the collaborative environment at to the given port number.
Parameters:
hostname - the name of the host to connect to.
port - the port to connect to.

Connection

public Connection(int port)
Initialize the connection class with a null hostname and set the port to connect to the collaborative environment at to the given port number.
Parameters:
port - the port to connect to.
Method Detail

setHostname

public void setHostname(java.lang.String hostname)
Sets the hostname to connect to.
Parameters:
hostname - the hostname to connect to.

getHostname

public java.lang.String getHostname()
Gets the hostname to connect to.
Returns:
the hostname to connect to.

setPort

public void setPort(int port)
Sets the port to connect at.
Parameters:
port - the port to connect at.

getPort

public int getPort()
Gets the port to connect at.
Returns:
the port to connect at.

getInputStream

public java.io.DataInputStream getInputStream()
Gets the stream for receiving data from the collaborative environment.
Returns:
the DataInputStream for receiving data from the collaborative environment.

getOutputStream

public java.io.PrintStream getOutputStream()
Gets the stream for sending data to the collaborative environment.
Returns:
the PrintStream for sending data to the collaborative environment.

setOutputPrefix

public void setOutputPrefix(java.lang.String outputPrefix)
Sets the string that will be used for the output prefix in commands returned by the collaborative environment.
Parameters:
outputPrefix - the string to use as the output prefix.

getOutputPrefix

public java.lang.String getOutputPrefix()
Gets the string that will be used for the output prefix in commands returned by the collaborative environment.
Returns:
the string to use as the output prefix.

setOutputSuffix

public void setOutputSuffix(java.lang.String outputSuffix)
Sets the string that will be used for the output suffix in commands returned by the collaborative environment.
Parameters:
outputSuffix - the string to use as the output suffix.

getOutputSuffix

public java.lang.String getOutputSuffix()
Gets the string that will be used for the output suffix in commands returned by the collaborative environment.
Returns:
the string to use as the output suffix.

setRobotName

public void setRobotName(java.lang.String robotName)
Sets the name of the robot.
Parameters:
robotName - the name of the robot.

getRobotName

public java.lang.String getRobotName()
Gets the name of the robot.
Returns:
the name of the robot.

findOutputPrefix

public abstract void findOutputPrefix()
Find the output prefix in the input stream.

drainConnection

public abstract void drainConnection(boolean wait)
Drain the connection until there is no more output waiting to be collected. If wait is set to true, wait for output if there is no output currently waiting.
Parameters:
wait - if true, wait for output if none is currently available. If false, and no data is available then just return.

drainConnection

public void drainConnection()
Drain the connection until there is no more output waiting to be collected. Wait for output if there is no output currently waiting.

waitForData

public void waitForData()
Wait until data becomes available from the collaborative environment.

drainConnectionToSuffix

public abstract void drainConnectionToSuffix(boolean wait)
Drain the output from the collaborative environment until the suffix that was set using setOutputSuffix is found. If wait is set to true wait until data becomes available from the collaborative environment. If wait is set to false and no data is available return immediately.
Parameters:
wait - if true, wait for output if none is currently available. If false, and no data is available then just return.

drainConnectionToSuffix

public void drainConnectionToSuffix()
Drain the output from the collaborative environment until the suffix that was set using setOutputSuffix is found. Wait until data becomes available from the collaborative environment.

getChatterVector

public abstract java.util.Vector getChatterVector()
Returns the chatter vector that output from the collaborative environment is stored in for later processing.
Returns:
the Vector containing output from the collaborative environment.

clearChatterVector

public abstract void clearChatterVector()
Clears the chatter vector that output from the collaborative environment is being stored in.

connectToMud

public void connectToMud()
Connect the robot to the Mud/MOO.

loginToMud

public abstract void loginToMud(java.lang.String name,
                                java.lang.String password)
Log the robot into the Mud/MOO. This routine should be called after connectToMud has been called.
Parameters:
name - the name of the robot.
password - the password of the robot.

logOffMud

public abstract void logOffMud()
Log the robot off the MUD/MOO.

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Read a line of output from the MUD/MOO.
Throws:
java.io.IOException - If an I/O error occurs.

available

public int available()
              throws java.io.IOException
Returns the number of bytes that can be read from the collaborative environment without blocking.
Returns:
the number of bytes that can be read from the collaborative environment without blocking.
Throws:
java.io.IOException - if an I/O error occurs.