Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## glassfrog.server
Class Server

    java.lang.Object
      glassfrog.server.Server

All Implemented Interfaces:
  java.lang.Runnable

    public class Server

extends java.lang.Object
implements java.lang.Runnable

The Server class is a persistant java server that has a `ServerSocket` serving on port 9000. This ServerSocket handles incoming connections and sends back information depending on the request made. The Server is capable of creating a `Room`, querying information about a Room or general status Each connection to the server is forked into a separate thread to allow multiple conncurent connections to the Server. Each thread only stays alive for the duration of the request connection and then is terminated.

Author:
  jdavidso

Nested Class Summary
`class` | `Server.ServerConnectionHandler` A class used to handle incoming connections to the server.

Field Summary
`private static boolean` | `alive`
`private static int` | `CONNECTION_MAX`
`private static java.lang.String` | `DUPLICATE_POLICY`
`private static java.util.ArrayList<java.lang.String>` | `errorList`
`private java.io.FileWriter` | `errorLog`
`private java.io.BufferedWriter` | `errorLogWriter`
`private static java.util.ArrayList<java.lang.String>` | `finishedList`
`private static java.util.ArrayList<java.lang.String>` | `keyList`
`private static java.util.ArrayList<java.lang.Thread>` | `liveThreads`
`private static int` | `PORT`
`private static java.util.concurrent.CopyOnWriteArrayList<java.lang.Integer>` | `portList`
`private static java.util.ArrayList<Room>` | `rooms`
`private java.io.FileWriter` | `serverLog`
`private java.io.BufferedWriter` | `serverLogWriter`
`private static java.net.ServerSocket` | `ss`
`private static int` | `TIMEOUT`

Constructor Summary
`Server(int timeout, int port)` The constructor for the server starts up a server on port 9000 and opens a ServerSocket to handle server requests

Method Summary
`private void` | `houseKeeping()` Do some housekeeping whenever a new connection is started or every 30 seconds on the socket timeout
`private void` | `initLogging()` Initialize the logs for the game.
`private static void` | `loadSettings()`
`void` | `logError(java.lang.Exception ex)` Utility for logging an error message to the errorLogger
`void` | `logError(java.lang.Exception ex, java.lang.String message)` Specify and extra message to the error logger
`private void` | `logInfo(java.lang.String info)` Log a info to the serverLogger
`private void` | `logWarning(java.lang.String warningMessage)` Utility for logging a warning message to the errorLogger
`static void` | `main(java.lang.String[] args)` Start the server from the command line.
`void` | `run()` The run method for the server.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### rooms

    private static java.util.ArrayList<Room> rooms

### portList

    private static java.util.concurrent.CopyOnWriteArrayList<java.lang.Integer> portList

### keyList

    private static java.util.ArrayList<java.lang.String> keyList

### liveThreads

    private static java.util.ArrayList<java.lang.Thread> liveThreads

### finishedList

    private static java.util.ArrayList<java.lang.String> finishedList

### errorList

    private static java.util.ArrayList<java.lang.String> errorList

### ss

    private static java.net.ServerSocket ss

### errorLog

    private java.io.FileWriter errorLog

### serverLog

    private java.io.FileWriter serverLog

### errorLogWriter

    private java.io.BufferedWriter errorLogWriter

### serverLogWriter

    private java.io.BufferedWriter serverLogWriter

### alive

    private static boolean alive

### PORT

    private static int PORT

### TIMEOUT

    private static int TIMEOUT

### DUPLICATE_POLICY

    private static java.lang.String DUPLICATE_POLICY

### CONNECTION_MAX

    private static final int CONNECTION_MAX

See Also:
  Constant Field Values

Constructor Detail

### Server

    public Server(int timeout,
                  int port)
           throws java.net.BindException,
                  java.io.IOException

  The constructor for the server starts up a server on port 9000 and opens a ServerSocket to handle server requests

  Parameters:
    `timeout` - A timeout used for server connections
    `port` - a port to start the server on
  Throws:
    `java.net.BindException`
    `java.io.IOException`

Method Detail

### initLogging

    private void initLogging()

  Initialize the logs for the game.

### logError

    public void logError(java.lang.Exception ex)

  Utility for logging an error message to the errorLogger

  Parameters:
    `ex` -

### logError

    public void logError(java.lang.Exception ex,
                         java.lang.String message)

  Specify and extra message to the error logger

  Parameters:
    `ex` -
    `message` -

### logWarning

    private void logWarning(java.lang.String warningMessage)

  Utility for logging a warning message to the errorLogger

  Parameters:
    `warningMessage` - A message to log to the error log

### logInfo

    private void logInfo(java.lang.String info)

  Log a info to the serverLogger

  Parameters:
    `info` - the message to log to the room log

### run

    public void run()

  The run method for the server. A server will busy wait and listen for incoming connections on it's ServerSocket and then fork a ServerConnectionHandler thread to deal with the connections while the server is still alive

  Specified by:
    `run` in interface `java.lang.Runnable`

### houseKeeping

    private void houseKeeping()

  Do some housekeeping whenever a new connection is started or every 30 seconds on the socket timeout

### main

    public static void main(java.lang.String[] args)

  Start the server from the command line. Can also be started via the class

  Parameters:
    `args` - Command line args

### loadSettings

    private static void loadSettings()
                              throws javax.xml.parsers.ParserConfigurationException,
                                     org.xml.sax.SAXParseException,
                                     org.xml.sax.SAXException,
                                     java.io.IOException,
                                     java.lang.InterruptedException

  Throws:
    `javax.xml.parsers.ParserConfigurationException`
    `org.xml.sax.SAXParseException`
    `org.xml.sax.SAXException`
    `java.io.IOException`
    `java.lang.InterruptedException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD