webtester.packages.distributed
Class serverHandler

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--webtester.packages.distributed.serverHandler
All Implemented Interfaces:
java.lang.Runnable

public class serverHandler
extends java.lang.Thread

Handles user input, and sends appropriate responses.

Author:
Aaron DeLong

Field Summary
private  boolean bConfigLoaded
          Indicates whether a config file is loaded.
private  boolean bMaster
          Indicates if the server is a master or not.
private static int iNodeAssign
          A counter used to assign new nodes a number.
private  java.io.DataInputStream input
          Contain input to the server.
private  int iNumTries
          Number of allowed tries to read data from client.
private  int iSleepTime
          Amount of time to sleep when waiting for client to send data.
private  int iTextAreaLength
          Max number of characters allowed in textarea.
private  java.io.PrintStream output
          Sends ouput to the client.
private  java.lang.String sConfigFile
          The config file that was loaded.
private  java.lang.String sMessage
          Last status message.
private  javax.swing.JTextArea text
          Text area used to update user.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
serverHandler(java.io.InputStream in, java.io.OutputStream out)
          Constructor that takes input/output streams as arguments.
 
Method Summary
private  java.lang.String getConfigFileContents()
          Retrieve the contents of the configuration file that is loaded.
 java.lang.String getMessage()
          Return the last message received.
private  int getNodeNumber()
          Get a uniqe number to assign to the node.
private  void handleNodeUpdates(java.lang.String sCmdStr)
          Deal with updates coming from a node to the master server.
 void run()
          The main entry point into the server handler routines.
private  void sendResponse(java.lang.String sResponse)
           
 void setConfigFile(java.lang.String sStr)
          Set the config file that was loaded.
 void setConfigLoaded(boolean bVal)
          Set the value that indicates if a config file is loaded.
 void setMaster(boolean bVal)
          Indicates whether the server is a master.
 void setTextArea(javax.swing.JTextArea jtext)
          Set textarea used to update user.
private  void updateTextArea(java.lang.String sText)
          Update the text area without erasing all existing data, if possible
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

input

private java.io.DataInputStream input
Contain input to the server.


output

private java.io.PrintStream output
Sends ouput to the client.


text

private javax.swing.JTextArea text
Text area used to update user.


iNumTries

private final int iNumTries
Number of allowed tries to read data from client.

See Also:
Constant Field Values

iSleepTime

private final int iSleepTime
Amount of time to sleep when waiting for client to send data.

See Also:
Constant Field Values

iTextAreaLength

private final int iTextAreaLength
Max number of characters allowed in textarea.

See Also:
Constant Field Values

iNodeAssign

private static int iNodeAssign
A counter used to assign new nodes a number.


bConfigLoaded

private boolean bConfigLoaded
Indicates whether a config file is loaded.


sConfigFile

private java.lang.String sConfigFile
The config file that was loaded.


sMessage

private java.lang.String sMessage
Last status message.


bMaster

private boolean bMaster
Indicates if the server is a master or not.

Constructor Detail

serverHandler

public serverHandler(java.io.InputStream in,
                     java.io.OutputStream out)
Constructor that takes input/output streams as arguments.

Parameters:
in - contains input to the server
out - used to send output to the client
Method Detail

setMaster

public void setMaster(boolean bVal)
Indicates whether the server is a master.

Parameters:
bVal - indicates whether the server is a master

setTextArea

public void setTextArea(javax.swing.JTextArea jtext)
Set textarea used to update user.

Parameters:
jtext - textarea used to update user

setConfigLoaded

public void setConfigLoaded(boolean bVal)
Set the value that indicates if a config file is loaded.

Parameters:
bVal - the boolean value to use

setConfigFile

public void setConfigFile(java.lang.String sStr)
Set the config file that was loaded.

Parameters:
sStr - the config file that was loaded

getMessage

public java.lang.String getMessage()
Return the last message received.

Returns:
a String that contains the last message received

run

public void run()
The main entry point into the server handler routines.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

sendResponse

private void sendResponse(java.lang.String sResponse)

getNodeNumber

private int getNodeNumber()
Get a uniqe number to assign to the node.

Returns:
an integer that represents the node assignment

updateTextArea

private void updateTextArea(java.lang.String sText)
Update the text area without erasing all existing data, if possible

Parameters:
sText - the text to add to the text area

getConfigFileContents

private java.lang.String getConfigFileContents()
Retrieve the contents of the configuration file that is loaded.

Returns:
the contents of the configuration file

handleNodeUpdates

private void handleNodeUpdates(java.lang.String sCmdStr)
Deal with updates coming from a node to the master server.

Parameters:
sCmdStr - command input to the server