Class SundayServer

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

public class SundayServer
extends Thread

A class that implements Joe Sunday's Drink Protocol for the TINI-board based Drink Server (although, in theory it is abstracted enough to be used on anything that has a DrinkMachineSpec class).

Version:
$Revision: #43 $
Author:
Kevin Thompson [antiduh@csh.rit.edu], Sean M. Graham [grahams@csh.rit.edu], Marius Grigoriu [marius@csh.rit.edu]
See Also:
Sunday Protocol, Sunday Protocol Errorcodes

Nested Class Summary
 class SundayServer.SundayClientThread
          This inner class represents an individual client connection to the server.
 
Field Summary
private  AcctMgrSpec acctMgr
          The account manager
private  int clientCount
          How many clients are currently connected.
private  ConfigMgr configMgr
          Where we get our runtime configuration values from.
private  DrinkMachineSpec drink
          The logger.
private  ServerSocket listen
          The socket we listen for connections from clients on.
private  String location
          A description of the location of the machine.
private  DrinkLoggerSpec log
          The drink machine
private  int maxClients
          The maximum number of clients we are to allow to connect.
private  int maxDelay
          The maximum a user can request that the drop be delayed for.
private  String motd
          The message of the day to display to users.
private  int port
          The port to listen on for client connections.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SundayServer(DrinkMachineSpec inDrink, AcctMgrSpec inAcctMgr, DrinkLoggerSpec inLog, ConfigMgr inConfigMgr)
          Constructor.
 
Method Summary
 boolean addClient()
          If MAXCLIENTS has not been reached, then increment clientCount and return true, otherwise return false.
 boolean removeClient()
          If clientCount is not zero, then decrement clientCount and return true, otherwise return false.
 void run()
          The run method accepts client connections.
 
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

listen

private ServerSocket listen
The socket we listen for connections from clients on. XXX: This used to be private static ServerSocket listen = null;


port

private int port
The port to listen on for client connections.


clientCount

private int clientCount
How many clients are currently connected. Used for denying connections if too many clients are connected. XXX: This used to be private static int clientCount = 0;


acctMgr

private AcctMgrSpec acctMgr
The account manager


drink

private DrinkMachineSpec drink
The logger.


log

private DrinkLoggerSpec log
The drink machine


configMgr

private ConfigMgr configMgr
Where we get our runtime configuration values from.


maxClients

private int maxClients
The maximum number of clients we are to allow to connect. This is to prevent resource hoarding on limited systems like the TINI.


maxDelay

private int maxDelay
The maximum a user can request that the drop be delayed for. This is so that users can't open up a bunch of connections and set the delay to Integer.MAX_VALUE, thereby causing a DoS.


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

SundayServer

public SundayServer(DrinkMachineSpec inDrink,
                    AcctMgrSpec inAcctMgr,
                    DrinkLoggerSpec inLog,
                    ConfigMgr inConfigMgr)
Constructor. Creates the listen socket, saves variables. All runtime configuration data is gathered from the ConfigMgr. No runtime configuration data is to be passed into the constructor.

Parameters:
inDrink - Reference to the Systemwide DrinKMachine object
inAcctMgr - Reference to the Systemwide AcctMgrSpec object
inLog - Reference to the Systemwide DrinkLoggerSpec object
inConfigMgr - The ConfigMgr to get config values from.
Method Detail

run

public void run()
The run method accepts client connections. If MAXCLIENTS has not been reached, then it create a new SundayClientThread, otherwise it prints an error message and disconnect the client.


addClient

public boolean addClient()
If MAXCLIENTS has not been reached, then increment clientCount and return true, otherwise return false.


removeClient

public boolean removeClient()
If clientCount is not zero, then decrement clientCount and return true, otherwise return false.