net.sf.freecol.server.control
Class InputHandler

java.lang.Object
  extended by net.sf.freecol.server.control.FreeColServerHolder
      extended by net.sf.freecol.server.control.InputHandler
All Implemented Interfaces:
MessageHandler
Direct Known Subclasses:
InGameInputHandler, PreGameInputHandler

public abstract class InputHandler
extends FreeColServerHolder
implements MessageHandler

Handles the network messages.

See Also:
Controller

Nested Class Summary
(package private)  class InputHandler.CurrentPlayerNetworkRequestHandler
          A network request handler for the current player will automatically return an error ("not your turn") if called by a connection other than that of the currently active player.
private  class InputHandler.DisconnectHandler
           
(package private) static interface InputHandler.NetworkRequestHandler
          A network request handler knows how to handle in a given request type.
 
Field Summary
private  java.util.Map<java.lang.String,InputHandler.NetworkRequestHandler> _handlerMap
          The handler map provides named handlers for network requests.
private static java.util.logging.Logger logger
           
 
Constructor Summary
InputHandler(FreeColServer freeColServer)
          The constructor to use.
 
Method Summary
protected  org.w3c.dom.Element createErrorReply(java.lang.String message)
          Create a reply message with an error.
 org.w3c.dom.Element handle(Connection connection, org.w3c.dom.Element element)
          Deals with incoming messages that have just been received.
protected  void logException(java.lang.Exception e)
          Log an exception as a warning.
protected abstract  org.w3c.dom.Element logout(Connection connection, org.w3c.dom.Element logoutElement)
          Handles a "logout"-message.
protected  void register(java.lang.String name, InputHandler.NetworkRequestHandler handler)
          Register a network request handler.
private  void sendReconnectSafely(Connection connection)
          Send a reconnect message ignoring (but logging) IO errors.
 
Methods inherited from class net.sf.freecol.server.control.FreeColServerHolder
getFreeColServer, getGame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static java.util.logging.Logger logger

_handlerMap

private final java.util.Map<java.lang.String,InputHandler.NetworkRequestHandler> _handlerMap
The handler map provides named handlers for network requests. Each handler deals with a given request type.

Constructor Detail

InputHandler

public InputHandler(FreeColServer freeColServer)
The constructor to use.

Parameters:
freeColServer - The main server object.
Method Detail

register

protected void register(java.lang.String name,
                        InputHandler.NetworkRequestHandler handler)
Register a network request handler.

Parameters:
name - The name.
handler - The handler.

handle

public final org.w3c.dom.Element handle(Connection connection,
                                        org.w3c.dom.Element element)
Deals with incoming messages that have just been received.

Specified by:
handle in interface MessageHandler
Parameters:
connection - The Connection the message was received on.
element - The root element of the message.
Returns:
The reply.

sendReconnectSafely

private void sendReconnectSafely(Connection connection)
Send a reconnect message ignoring (but logging) IO errors.

Parameters:
connection - The connection.

logException

protected void logException(java.lang.Exception e)
Log an exception as a warning.

Parameters:
e - The exception to log.

createErrorReply

protected org.w3c.dom.Element createErrorReply(java.lang.String message)
Create a reply message with an error.

Parameters:
message - The error message.
Returns:
reply element with message.

logout

protected abstract org.w3c.dom.Element logout(Connection connection,
                                              org.w3c.dom.Element logoutElement)
Handles a "logout"-message.

Parameters:
connection - The Connection the message was received on.
logoutElement - The element (root element in a DOM-parsed XML tree) that holds all the information.
Returns:
The reply.