Class FingerServer

java.lang.Object
  extended byjava.lang.Thread
      extended byFingerServer
All Implemented Interfaces:
Runnable

public class FingerServer
extends Thread

Implements a finger-protocol server to provide information about drink through finger.

In it's current state, this class supports 5 finger targets:
'@drink' - provides the temperature readouts and a slot listing
'temp@drink' - lists the temperatures of the cabinet and power supply.
'user@drink' - provide the balance, user admin status of the user.
'slotname@drink' - lists the information for a single slot. Similar to @drink
'info@drink' - provides a quick help reference.

Version:
$Revision: #21 $
Author:
Bill Kuker [kukester@csh.rit.edu], Kevin Thompson [antiduh@csh.rit.edu]

Field Summary
private  AcctMgrSpec acctMgr
          The account manager we get user data from.
private  ConfigMgr configMgr
          The ConfigMgr that we get our runtime configuration data from.
private  DrinkMachineSpec drink
          The Drink machine we are to use for hardware access.
private  ServerSocket listen
          The ServerSocket that listens for connections from new clients.
private  String location
          A description of the location of the machine.
private  DrinkLoggerSpec log
          Where we send our log messages for info/errors/etc.
private  String motd
          The message of the day to display to users.
private  int port
          The port number we are to listen on for connections.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
FingerServer(DrinkMachineSpec _drink, AcctMgrSpec _acct, DrinkLoggerSpec _log, ConfigMgr _config)
          Constructs the FingerServer.
 
Method Summary
private  int naturalInt(String num)
          Tests to see if the given string is a non-zero number.
private  void printInfo(PrintWriter out)
          Prints a quick guide to the targets that the finger server provides.
private  void printStat(PrintWriter out)
          Prints the can statistics.
private  void printTemp(PrintWriter out)
          Prints the temperature statistics.
private  void printUser(PrintWriter out, String user)
          Prints the information for a single user.
 void run()
          Executed when a new connection comes in.
private  String slotStat(int slotIndex)
          Prints the stats for a single slot.
 
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

port

private int port
The port number we are to listen on for connections.


listen

private ServerSocket listen
The ServerSocket that listens for connections from new clients.


drink

private DrinkMachineSpec drink
The Drink machine we are to use for hardware access.


acctMgr

private AcctMgrSpec acctMgr
The account manager we get user data from.


log

private DrinkLoggerSpec log
Where we send our log messages for info/errors/etc.


configMgr

private ConfigMgr configMgr
The ConfigMgr that we get our runtime configuration data from.


motd

private String motd
The message of the day to display to users.


location

private String location
A description of the location of the machine. Mildly pointless.

Constructor Detail

FingerServer

public FingerServer(DrinkMachineSpec _drink,
                    AcctMgrSpec _acct,
                    DrinkLoggerSpec _log,
                    ConfigMgr _config)
Constructs the FingerServer. Saves the parameters and begins listening on the port.

Parameters:
_drink - The DrinkMachineSpec to interact with
_acct - The AcctMgrSpec to interact with.
_log - The DrinkLoggerSpec to log messages to.
_config - The ConfigMgr class to use.
Method Detail

slotStat

private String slotStat(int slotIndex)
Prints the stats for a single slot. The stats include the slot index, name, price, quantity, and number sold.

Parameters:
slotIndex - The index of the slot to print.

printInfo

private void printInfo(PrintWriter out)
Prints a quick guide to the targets that the finger server provides.

Parameters:
out - The PrintWriter to do the printing to.

printStat

private void printStat(PrintWriter out)
Prints the can statistics.

Parameters:
out - The PrintWriter to print the stats to.

printUser

private void printUser(PrintWriter out,
                       String user)
Prints the information for a single user.

Parameters:
out - The PrintWriter to print to.
user - The user to print stats on.

printTemp

private void printTemp(PrintWriter out)
Prints the temperature statistics. Currently, this prints the power supply heatsink temperature and the cabinet temperatures.

Parameters:
out - the PrintWriter to print the stats to.

run

public void run()
Executed when a new connection comes in. Open the socket, read in the command and print back the results.


naturalInt

private int naturalInt(String num)
Tests to see if the given string is a non-zero number. If it is not a number, it will return -1. Anything else, and it will return the number.