Class SundayServer.SundayClientThread

java.lang.Object
  extended byjava.lang.Thread
      extended bySundayServer.SundayClientThread
All Implemented Interfaces:
Runnable
Enclosing class:
SundayServer

public class SundayServer.SundayClientThread
extends Thread

This inner class represents an individual client connection to the server. This thread persists while the client connection does.

Author:
Kevin Thompson [antiduh@csh.rit.edu]

Field Summary
private  Socket client
          The socket that is connected to our client.
private  BufferedReader in
          Connected to the sockets input stream.
private  PrintWriter out
          Connected to the socket's output stream.
private  SundayServer server
          A reference to our parent class.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SundayServer.SundayClientThread(Socket inClient, SundayServer inServer)
          Construct the thread by simply saving the passed in variables.
 
Method Summary
private  void dropDrink(String command, String username)
          Parses out the information, verifies everything, and then drops the drink.
private  void dropRand(String command, String username)
          Drops a random drink.
 void editSlot(String command)
          Edit a slots information.
private  void editUser(String command)
          Edit a users account information.
private  void getStats(String command)
          Print the contents and statistics of the drink machine out to the socket.
 void run()
          The run method loops, processing user input and requests.
 
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

out

private PrintWriter out
Connected to the socket's output stream. This provides a simple interface for pushing data over the socket.


in

private BufferedReader in
Connected to the sockets input stream. This provides a simple, buffered interface for reading string data from the socket.


server

private SundayServer server
A reference to our parent class. We need this in order to call SundayServer.removeClient() when our session ends.


client

private Socket client
The socket that is connected to our client.

Constructor Detail

SundayServer.SundayClientThread

public SundayServer.SundayClientThread(Socket inClient,
                                       SundayServer inServer)
Construct the thread by simply saving the passed in variables.

Parameters:
inClient - Reference to the client socket connection
inServer - Reference to the SundayServer object
Method Detail

run

public void run()
The run method loops, processing user input and requests. This is a very long method since it boils down to a long switch statement, one case for each command.


dropDrink

private void dropDrink(String command,
                       String username)
Parses out the information, verifies everything, and then drops the drink.

Parameters:
command - The command, excluding the 'drop ' (space included). EG: '1 2'.

dropRand

private void dropRand(String command,
                      String username)
Drops a random drink.

Parameters:
command - The data portion of the command that was sent to the SundayServer.This excludes the command name and its associated space - 'rand '. The command should only be a single number. It should not contain spaces.
username - The name of the user who is asking to drop a random drink. Used for accountin

getStats

private void getStats(String command)
Print the contents and statistics of the drink machine out to the socket.

Parameters:
command - If a number is specified on the command line, only that slot is printed.

editUser

private void editUser(String command)
Edit a users account information.

Parameters:
command - Just the command string, excludes the 'edituser ' portion EX: 'antiduh 100 false'

editSlot

public void editSlot(String command)
Edit a slots information.

Parameters:
command - Just the parameters of the command. Should be stripped of leading spaces. The second param must be wrapped in quotes, always. EX: "0 "Coke" 50 43 307 true"