Ver. 20060815

Server
Class Server

java.lang.Object
  extended by Server.Server

public class Server
extends java.lang.Object

Reference implementation of the SIMSA Server that contain the abstracted connections for clients and modules. The main server loop handles client and module registration and message routing. 2006-08-15 Kyle Reed


Field Summary
private  boolean alive
           
(package private)  java.util.HashMap<java.lang.Integer,ClientContainer> clientList
           
private  java.nio.channels.ServerSocketChannel clientPort
           
private  java.nio.channels.SelectionKey clientPortKey
           
private  java.nio.channels.SocketChannel incomingChannel
           
private  java.nio.channels.SelectionKey incomingKey
           
 int MAX_BUFFER_SIZE
           
(package private)  java.util.HashMap<java.lang.Integer,ModuleContainer> moduleList
           
private  java.nio.channels.ServerSocketChannel modulePort
           
private  java.nio.channels.SelectionKey modulePortKey
           
private  java.util.Set<java.nio.channels.SelectionKey> selectedKeys
           
private  java.util.Iterator<java.nio.channels.SelectionKey> selectionKeyIter
           
private  java.lang.Thread server
           
private  java.nio.channels.Selector socketListener
           
 
Constructor Summary
Server()
          Initializes registration lists and starts the main server thread.
 
Method Summary
private  void getActiveKeys()
          Get the set of keys that have incoming data and puts them into a set for processing.
 java.nio.channels.Selector getSelector()
           
private  boolean hasIncoming()
          Returns true if there is another key in the Selection set that needs to be processed.
 boolean isAlive()
           
 void kill()
          Kills the server by setting the alive boolean value to false, breaking out of main while loop
 void killAllModules()
          Kills all of the modules on the server.
 java.lang.String killClient(int id)
          Calls the selfDestruct() method of the ClientContainer to remove the Client with the given ID from the server.
 java.lang.String killClientAuth(int id, int chNum)
          Calls the selfDestruct() method of the ClientContainer to remove the Client with the given ID from thse server, this allows modules to pass their Challange key to disconnect themselves.
 java.lang.String killModule(int id)
          Calls the selfDestruct() method of the ModuleContainer to remove the Module with the given ID from thse server.
 java.lang.String killModuleAuth(int id, int chNum)
          Calls the selfDestruct() method of the ModuleContainer to remove the Module with the given ID from thse server, this allows modules to pass their Challange key to disconnect themselves.
 java.lang.String listClients()
          Returns a formatted string of the loaded client.
 java.lang.String listModules()
          Returns a formatted string of the loaded modules.
 java.lang.String loadModule(java.lang.String mod)
          Loads a module (by class name) dynamically to be run in the same VM as the server.
private  boolean open()
          Returns true if all of the server sockets have been successfully bound to the Selector.
private  void processIncoming()
          Processes an incoming message from the selector, it will register new clients or call the handleInput() method of the appropriate ConnectionContainer.
private  void registerClient()
          Adds a client to the client list and assigns it to a new ClientContainer.
private  void registerModule()
          Adds a module to the module list and assigns it to a new ModuleContainer.
private  void removeIncoming()
          Removes a client/module from the server by calling the selfDestruct() which will cancel its registration with the Selector and remove itself from the registration lists.
private  void run()
          The main server loop that listens for incoming messages and processes them.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

socketListener

private java.nio.channels.Selector socketListener

clientPort

private java.nio.channels.ServerSocketChannel clientPort

modulePort

private java.nio.channels.ServerSocketChannel modulePort

clientPortKey

private java.nio.channels.SelectionKey clientPortKey

modulePortKey

private java.nio.channels.SelectionKey modulePortKey

incomingKey

private java.nio.channels.SelectionKey incomingKey

incomingChannel

private java.nio.channels.SocketChannel incomingChannel

selectedKeys

private java.util.Set<java.nio.channels.SelectionKey> selectedKeys

selectionKeyIter

private java.util.Iterator<java.nio.channels.SelectionKey> selectionKeyIter

server

private java.lang.Thread server

alive

private boolean alive

MAX_BUFFER_SIZE

public final int MAX_BUFFER_SIZE
See Also:
Constant Field Values

clientList

java.util.HashMap<java.lang.Integer,ClientContainer> clientList

moduleList

java.util.HashMap<java.lang.Integer,ModuleContainer> moduleList
Constructor Detail

Server

public Server()
Initializes registration lists and starts the main server thread. 2006-08-15 Kyle Reed

Method Detail

open

private boolean open()
Returns true if all of the server sockets have been successfully bound to the Selector. 2006-08-15 Kyle Reed


run

private void run()
The main server loop that listens for incoming messages and processes them. 2006-08-15 Kyle Reed


getActiveKeys

private void getActiveKeys()
                    throws java.lang.Exception
Get the set of keys that have incoming data and puts them into a set for processing. 2006/08/10 Kyle Reed

Throws:
java.lang.Exception

hasIncoming

private boolean hasIncoming()
Returns true if there is another key in the Selection set that needs to be processed. 2006-08-15 Kyle Reed


processIncoming

private void processIncoming()
Processes an incoming message from the selector, it will register new clients or call the handleInput() method of the appropriate ConnectionContainer. 2006-08-15 Kyle Reed


removeIncoming

private void removeIncoming()
Removes a client/module from the server by calling the selfDestruct() which will cancel its registration with the Selector and remove itself from the registration lists.


registerModule

private void registerModule()
Adds a module to the module list and assigns it to a new ModuleContainer. 2006-08-15 Kyle Reed


registerClient

private void registerClient()
Adds a client to the client list and assigns it to a new ClientContainer. 2006-08-15 Kyle Reed


getSelector

public java.nio.channels.Selector getSelector()

isAlive

public boolean isAlive()

kill

public void kill()
Kills the server by setting the alive boolean value to false, breaking out of main while loop


loadModule

public java.lang.String loadModule(java.lang.String mod)
Loads a module (by class name) dynamically to be run in the same VM as the server. The module must be in the class path for the server so that it can be found. 2006-08-15 Kyle Reed


listModules

public java.lang.String listModules()
Returns a formatted string of the loaded modules. 2006-08-15 Kyle Reed


killModule

public java.lang.String killModule(int id)
Calls the selfDestruct() method of the ModuleContainer to remove the Module with the given ID from thse server. 2006-08-15 Kyle Reed


killModuleAuth

public java.lang.String killModuleAuth(int id,
                                       int chNum)
Calls the selfDestruct() method of the ModuleContainer to remove the Module with the given ID from thse server, this allows modules to pass their Challange key to disconnect themselves. 2006-08-15 Kyle Reed


killAllModules

public void killAllModules()
Kills all of the modules on the server. 2006-08-15 Kyle Reed


listClients

public java.lang.String listClients()
Returns a formatted string of the loaded client. 2006-08-15 Kyle Reed


killClient

public java.lang.String killClient(int id)
Calls the selfDestruct() method of the ClientContainer to remove the Client with the given ID from the server. 2006-08-15 Kyle Reed


killClientAuth

public java.lang.String killClientAuth(int id,
                                       int chNum)
Calls the selfDestruct() method of the ClientContainer to remove the Client with the given ID from thse server, this allows modules to pass their Challange key to disconnect themselves. 2006-08-15 Kyle Reed


Ver. 20060815