Class ClientServer

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

public class ClientServer
extends Thread

This is a drink client designed to run directly on a drink machine alongside of the regular software. This client does not use SundayServer to for communication, it simply accesses everything just by itself. The ClientServer class itself listens for incoming connections and passes them to ClientServerThread, which handles all the processing and IO. The ClientServerThread can be quite large, since there is so much to process.

Version:
$Revision: #47 $
Author:
Kevin Thompson [antiduh@csh.rit.edu]

Nested Class Summary
 class ClientServer.ClientServerThread
          Handles new client connections.
 class ClientServer.TelnetPrintWriter
          Extends the PrintWriter class to replace the println() method, so that it always prints a CR LF, which is required by the telnet protocol.
 
Field Summary
private  AcctMgrSpec acctMgr
          The class we use for performing user authentication and for retreiving that users information.
private static int clientCount
          The number of currenlty connected clients.
private  ConfigMgr configMgr
          Where we get our runtime configuration data from.
private  DrinkMachineSpec drink
          The DrinkMachineSpec we use for communicating with the hardware with.
private  boolean killAfterDrop
          Whether or not to kill the connection immediately after a drop.
private static ServerSocket listen
          The socket to listen for client connections on.
private  String location
          A description of the location of the machine.
private  DrinkLoggerSpec log
          The DrinkLoggerSpec we log all our errors/etc to.
private  int maxClients
          The maximum number of connected clients.
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 number we are to listen on for connections.
static String VERSION_TAG
          Specifies the internal version number and the date the client was last updated.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ClientServer(DrinkMachineSpec _drink, AcctMgrSpec _acct, DrinkLoggerSpec _log, ConfigMgr _config)
          This is the constructor for the ClientServer class.
 
Method Summary
 boolean addClient()
          Keeps track of the number of logged in clients.
 boolean removeClient()
          Keeps track of the number of clients If clientCount is not zero, then decrement clientCount and return true, otherwise return false.
 void run()
          This method attempts to accept connections forever, and launches new ClientServerThread's as they come in.
 
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

VERSION_TAG

public static final String VERSION_TAG
Specifies the internal version number and the date the client was last updated. This is typically used to print back to the user.

See Also:
Constant Field Values

listen

private static ServerSocket listen
The socket to listen for client connections on.


clientCount

private static int clientCount
The number of currenlty connected clients. This is here so that the class can keep track of how many users it is servicing and subsequently how much cpu/etc it is sucking up.


drink

private DrinkMachineSpec drink
The DrinkMachineSpec we use for communicating with the hardware with.


log

private DrinkLoggerSpec log
The DrinkLoggerSpec we log all our errors/etc to.


acctMgr

private AcctMgrSpec acctMgr
The class we use for performing user authentication and for retreiving that users information.


port

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


maxClients

private int maxClients
The maximum number of connected clients.


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.


configMgr

private ConfigMgr configMgr
Where 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.


killAfterDrop

private boolean killAfterDrop
Whether or not to kill the connection immediately after a drop.

Constructor Detail

ClientServer

public ClientServer(DrinkMachineSpec _drink,
                    AcctMgrSpec _acct,
                    DrinkLoggerSpec _log,
                    ConfigMgr _config)
This is the constructor for the ClientServer class. It saves the passed-in parameters and then opens the port for listening.

Parameters:
_drink - The drink machine that we are to interact with.
_log - The log we are to output our info/errors/etc to.
_acct - The Account manager ClientServerThread authorizes with.
_config - The ConfigMgr to use to get config values.
Method Detail

run

public void run()
This method attempts to accept connections forever, and launches new ClientServerThread's as they come in. If too many clients are connected at once, an error message is printed and the client is disconnected.


addClient

public boolean addClient()
Keeps track of the number of logged in clients. If MAXCLIENTS has not been reached, then increment clientCount and return true, otherwise return false.

Returns:
True if there are less than MAXCLIENTS connected, false otherwise.

removeClient

public boolean removeClient()
Keeps track of the number of clients If clientCount is not zero, then decrement clientCount and return true, otherwise return false.

Returns:
True if there are more than zero clients, false otherwise.