fr.lip6.sma.simulacion.server.http
Class HTTPServer

java.lang.Object
  extended by java.lang.Thread
      extended by fr.lip6.sma.simulacion.app.CLIApplication
          extended by fr.lip6.sma.simulacion.server.http.HTTPServer
All Implemented Interfaces:
com.kallisys.zeroconf.MulticastDNSClient, Runnable, XmlRpcHandler

public class HTTPServer
extends CLIApplication
implements com.kallisys.zeroconf.MulticastDNSClient, XmlRpcHandler

Classe pour le serveur HTTP qui gère les différents clients.

Version:
$Revision: 3 $
Author:
Paul Guyot
See Also:
HTTPServerTest

Nested Class Summary
private  class HTTPServer.ClientData
          Classe pour les données sur un client.
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
private  Map mAgentsRegistry
          La liste des agents enregistrés.
private  int mClientNextID
          ID du prochain client.
private  Map mClients
          La liste des événements pour les clients.
private  String mGameID
          Identification du jeu.
private  int mMDNSRegistrationOpID
          Registration operation ID or 0 if we don't register to the mDNS server.
private  com.kallisys.zeroconf.MulticastDNSServer mMDNSServer
          Reference to the mDNS server (or null if we don't publish the server over mDNS).
private  int mOperationNextID
          ID de la prochaine opération.
private  Map mPendingOperations
          La liste des opérations en cours.
private  WebServer mServer
          Référence sur le serveur.
private  boolean mVerboseMode
          If we're in verbose mode.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface com.kallisys.zeroconf.MulticastDNSClient
BROWSERFLAG_MORECOMING, BROWSERFLAG_REMOVE
 
Constructor Summary
HTTPServer(String[] inArgs)
          Constructeur à partir des arguments.
 
Method Summary
protected  void displayHelp(String inLine)
          Display the help.
private  void endClient(int inClientID)
          Fin d'un client.
 Object execute(String inMethod, Vector inParams)
          Point d'entrée du serveur XML-RPC.
private  String executeAgentMethod(int inClientID, String inAgentClass, String inAgentName, String inMethodName, Map inParams)
          Exécute une méthode sur un agent.
private  void executeAgentMethodAsync(int inClientID, String inAgentClass, String inAgentName, String inMethodName, Map inParams)
          Exécute une méthode sur un agent de manière asynchrone.
private  void filterEvents(List inEventList)
          Filter an event list by removing unnecessary events (register & unregister events).
protected  void init()
          Method called at the beginning of the application.
private  List listen(int inClientID)
          Envoie à un client tous les nouveaux événements.
private  void logExecuteAgentMethodVerbose(int inClientID, String inAgentClass, String inAgentName, String inMethodName, Map inParams, String inResult)
          Affiche l'exécution d'une méthode sur un agent.
static void main(String[] inArgs)
          Point d'entrée du serveur.
 void multicastDNSBrowserCallBack(int inRequestID, int inBrowserFlags, com.kallisys.zeroconf.NetService inService, IOException inException)
           Ignored.
 void multicastDNSRegistrationCallBack(int inRequestID, com.kallisys.zeroconf.NetService inService, IOException inException)
          
 void multicastDNSResolutionCallBack(int inRequestID, com.kallisys.zeroconf.NetService inService, IOException inException)
           Ignored.
private  int newClient()
          Nouveau client.
private  void postEvent(int inClientID, Map inEvent)
          Nouvel événement pour un client.
private  void postEventToAll(Map inEvent)
          Nouvel événement pour tous les clients.
protected  boolean processCommand(String inCommand, String inLine)
          Method called to process commands.
private static void queueEventInList(List inEventList, Map inEvent)
          Add an event in a list.
protected  void quit()
          Method called to quit the application.
private  boolean register(int inClientID, String inAgentClass, String inAgentName)
          Enregistre un agent.
private  void shutdown()
          Arrête le serveur.
private  void unregister(int inClientID, String inAgentClass, String inAgentName)
          Désenregistre un agent.
private static void usage()
          Affiche la syntaxe de ce programme sur radio stderr.
 
Methods inherited from class fr.lip6.sma.simulacion.app.CLIApplication
flush, print, println, printStackTrace, run
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, 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

mVerboseMode

private final boolean mVerboseMode
If we're in verbose mode.


mServer

private final WebServer mServer
Référence sur le serveur.


mMDNSServer

private final com.kallisys.zeroconf.MulticastDNSServer mMDNSServer
Reference to the mDNS server (or null if we don't publish the server over mDNS).


mMDNSRegistrationOpID

private final int mMDNSRegistrationOpID
Registration operation ID or 0 if we don't register to the mDNS server.


mGameID

private final String mGameID
Identification du jeu.


mClients

private final Map mClients
La liste des événements pour les clients. Les clés sont les identifiants des clients et les valeurs des ClientData.


mClientNextID

private int mClientNextID
ID du prochain client.


mPendingOperations

private final Map mPendingOperations
La liste des opérations en cours. Les clés sont les identifiants des opérations et les valeurs des vecteurs à un élément pour accueillir le résultat.


mOperationNextID

private int mOperationNextID
ID de la prochaine opération. Remarque: une opération a une durée de vie limitée, par conséquent ce nombre peut être sur 32 bits.


mAgentsRegistry

private final Map mAgentsRegistry
La liste des agents enregistrés. Les clés sont les clés de la forme Classe:Nom. Les valeurs sont les ID des clients correspondant.

Constructor Detail

HTTPServer

public HTTPServer(String[] inArgs)
Constructeur à partir des arguments.

Parameters:
inArgs - arguments sur la ligne de commande
Method Detail

usage

private static void usage()
Affiche la syntaxe de ce programme sur radio stderr.


init

protected void init()
Method called at the beginning of the application. Starts the server.

Overrides:
init in class CLIApplication

quit

protected void quit()
Method called to quit the application.

Overrides:
quit in class CLIApplication

shutdown

private void shutdown()
Arrête le serveur.


execute

public Object execute(String inMethod,
                      Vector inParams)
               throws Exception
Point d'entrée du serveur XML-RPC. Cette méthode est ré-entrante et appelée à chaque requête.

Specified by:
execute in interface XmlRpcHandler
Parameters:
inMethod - nom de la méthode appelée (objet.nom).
inParams - liste des paramètres.
Returns:
une chaîne décrivant le jeu (et la version) de ce serveur.
Throws:
Exception - si un problème est survenu.

newClient

private int newClient()
Nouveau client.

Returns:
l'ID du nouveau client (qui est l'indice dans la liste des événements).

listen

private List listen(int inClientID)
Envoie à un client tous les nouveaux événements. Attend au plus LISTEN_TIMEOUT pour les nouveaux événements.

Parameters:
inClientID - le numéro du client.
Returns:
une liste d'événements pour le client.

endClient

private void endClient(int inClientID)
Fin d'un client. Désenregistre tous ses agents.

Parameters:
inClientID - le numéro du client.

register

private boolean register(int inClientID,
                         String inAgentClass,
                         String inAgentName)
Enregistre un agent.

Parameters:
inClientID - le numéro du client.
inAgentClass - la classe de l'agent.
inAgentName - le nom de l'agent.
Returns:
true si l'enregistrement a réussi.

unregister

private void unregister(int inClientID,
                        String inAgentClass,
                        String inAgentName)
Désenregistre un agent.

Parameters:
inClientID - le numéro du client.
inAgentClass - la classe de l'agent.
inAgentName - le nom de l'agent.

executeAgentMethod

private String executeAgentMethod(int inClientID,
                                  String inAgentClass,
                                  String inAgentName,
                                  String inMethodName,
                                  Map inParams)
                           throws NetworkAgentException
Exécute une méthode sur un agent.

Parameters:
inClientID - le numéro du client.
inAgentClass - la classe de l'agent.
inAgentName - le nom de l'agent.
inMethodName - la méthode à exécuter.
inParams - les paramètres de l'agent.
Returns:
le résultat de la méthode ou null si on n'a jamais eu le résultat.
Throws:
NetworkAgentException - si un problème est survenu.

executeAgentMethodAsync

private void executeAgentMethodAsync(int inClientID,
                                     String inAgentClass,
                                     String inAgentName,
                                     String inMethodName,
                                     Map inParams)
                              throws NetworkAgentException
Exécute une méthode sur un agent de manière asynchrone.

Parameters:
inClientID - le numéro du client.
inAgentClass - la classe de l'agent.
inAgentName - le nom de l'agent.
inMethodName - la méthode à exécuter.
inParams - les paramètres de l'agent.
Throws:
NetworkAgentException - si un problème est survenu.

logExecuteAgentMethodVerbose

private void logExecuteAgentMethodVerbose(int inClientID,
                                          String inAgentClass,
                                          String inAgentName,
                                          String inMethodName,
                                          Map inParams,
                                          String inResult)
Affiche l'exécution d'une méthode sur un agent.

Parameters:
inClientID - le numéro du client.
inAgentClass - la classe de l'agent.
inAgentName - le nom de l'agent.
inMethodName - la méthode à exécuter.
inParams - les paramètres de l'agent.
inResult - résultat.

filterEvents

private void filterEvents(List inEventList)
Filter an event list by removing unnecessary events (register & unregister events).

Parameters:
inEventList - list of event where to insert the event.

queueEventInList

private static void queueEventInList(List inEventList,
                                     Map inEvent)
Add an event in a list.

Parameters:
inEventList - list of event where to insert the event.
inEvent - event to insert.

postEvent

private void postEvent(int inClientID,
                       Map inEvent)
Nouvel événement pour un client.

Parameters:
inClientID - le numéro du client.
inEvent - un dictionnaire qui décrit l'événement.

postEventToAll

private void postEventToAll(Map inEvent)
Nouvel événement pour tous les clients.

Parameters:
inEvent - un dictionnaire qui décrit l'événement.

processCommand

protected boolean processCommand(String inCommand,
                                 String inLine)
Method called to process commands.

Overrides:
processCommand in class CLIApplication
Parameters:
inCommand - command to parse (in uppercase).
inLine - the full line.
Returns:
false if the command was unknown, true otherwise.

displayHelp

protected void displayHelp(String inLine)
Display the help.

Overrides:
displayHelp in class CLIApplication
Parameters:
inLine - line for the help command (unused).

multicastDNSRegistrationCallBack

public final void multicastDNSRegistrationCallBack(int inRequestID,
                                                   com.kallisys.zeroconf.NetService inService,
                                                   IOException inException)

Specified by:
multicastDNSRegistrationCallBack in interface com.kallisys.zeroconf.MulticastDNSClient

multicastDNSResolutionCallBack

public final void multicastDNSResolutionCallBack(int inRequestID,
                                                 com.kallisys.zeroconf.NetService inService,
                                                 IOException inException)
Ignored.

Specified by:
multicastDNSResolutionCallBack in interface com.kallisys.zeroconf.MulticastDNSClient

multicastDNSBrowserCallBack

public final void multicastDNSBrowserCallBack(int inRequestID,
                                              int inBrowserFlags,
                                              com.kallisys.zeroconf.NetService inService,
                                              IOException inException)
Ignored.

Specified by:
multicastDNSBrowserCallBack in interface com.kallisys.zeroconf.MulticastDNSClient

main

public static void main(String[] inArgs)
Point d'entrée du serveur. Syntaxe: java ... HTTPServer <fichier de configuration>

Parameters:
inArgs - arguments sur la ligne de commande.