triptracker.server
Class Server

java.lang.Object
  extended by triptracker.server.Server

public class Server
extends Object

Main server class.


Constructor Summary
Server()
          Default constructor.
 
Method Summary
protected  void addGPSHandler(GPSHandler handler)
          Adds a GPS client handler to the main server handler list.
 void addListener(ServerListener listener)
          Register a listener for server events.
protected  void addMapHandler(MapHandler handler)
          Adds a map client handler from the main server handler list.
protected  void checkMapHandler(GPSHandler gpsHandler)
          Checks if any mapHandlers are listening to the route gpsHandler will log
protected  void clientListUpdate(ClientHandler client, boolean joined)
          Publish a "socket error" event to all listeners.
 GPSHandler getGPSHandler(Route route)
          Returns a GPSHandler to listen to.
 List<GPSHandler> getGPSHandlers()
           
protected  void invalidMessage(ClientHandler client, String message)
          Publish an "invalid message" event to all listeners.
protected  void log(String source, String message)
          Log a status message to the server log file.
static void main(String[] args)
          Main server entry point.
protected  void removeGPSHandler(GPSHandler handler)
          Removes a GPS client handler from the main server handler list.
 void removeListener(ServerListener listener)
          Remove listener from listener queue.
protected  void removeMapHandler(MapHandler handler)
          Removes a map client handler from the main server handler list.
protected  void socketErrorEvent(ClientHandler client, IOException exception)
          Publish a "socket error" event to all listeners.
 void startServer(int port)
          Main method will open the server socket, and go into a loop, where it recieves clients and starts handlers.
 void stopServer()
          Method being run when server is set for stopping.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Server

public Server()
Default constructor.

Method Detail

stopServer

public final void stopServer()
                      throws IOException
Method being run when server is set for stopping.

Throws:
IOException - server dies on IOException

main

public static void main(String[] args)
Main server entry point.


startServer

public final void startServer(int port)
                       throws IOException
Main method will open the server socket, and go into a loop, where it recieves clients and starts handlers.

Parameters:
port - listening port
Throws:
IOException - server dies on IOException

getGPSHandler

public GPSHandler getGPSHandler(Route route)
Returns a GPSHandler to listen to.

Returns:
GPS handler

addGPSHandler

protected final void addGPSHandler(GPSHandler handler)
Adds a GPS client handler to the main server handler list.

Parameters:
handler - handler

removeGPSHandler

protected final void removeGPSHandler(GPSHandler handler)
Removes a GPS client handler from the main server handler list.

Parameters:
handler - handler

checkMapHandler

protected final void checkMapHandler(GPSHandler gpsHandler)
Checks if any mapHandlers are listening to the route gpsHandler will log

Parameters:
gpsHandler -

addMapHandler

protected final void addMapHandler(MapHandler handler)
Adds a map client handler from the main server handler list.

Parameters:
handler - handler

removeMapHandler

protected final void removeMapHandler(MapHandler handler)
Removes a map client handler from the main server handler list.

Parameters:
handler - handler

getGPSHandlers

public List<GPSHandler> getGPSHandlers()

addListener

public final void addListener(ServerListener listener)
Register a listener for server events.

Parameters:
listener - event receiver

removeListener

public final void removeListener(ServerListener listener)
Remove listener from listener queue.

Parameters:
listener - event receiver

socketErrorEvent

protected final void socketErrorEvent(ClientHandler client,
                                      IOException exception)
Publish a "socket error" event to all listeners. This generally means that the socket associated with client has been closed and the client has been removed from any client list it might be a member of.

Parameters:
client - disconnected client
exception - socket IOException thrown by client

invalidMessage

protected final void invalidMessage(ClientHandler client,
                                    String message)
Publish an "invalid message" event to all listeners. This signals an unsupported or malformed message recieved from client. Clients are usually not disconnected for sending invalid messages, unless the amount of invalid messages is significant and the behaviour of the client appears to be malicious.

Parameters:
client - misbehaving client
message - full message

clientListUpdate

protected final void clientListUpdate(ClientHandler client,
                                      boolean joined)
Publish a "socket error" event to all listeners. This generally means that the socket associated with client has been closed and the client has been removed from any client list it might be a member of.

Parameters:
client - joined or disconnected client
joined - true if joined, false if disconnected

log

protected final void log(String source,
                         String message)
Log a status message to the server log file. Each log entry is given a timestamp and appended to the end of the file.

Parameters:
source - in what context the log message was recorded
message - status message


Copyright © 2006 Team Trip Tracker. All Rights Reserved.