sjrd.tricktakinggame.network.commands
Class CommandBasedConnection

java.lang.Object
  extended by sjrd.tricktakinggame.network.NetworkConnection
      extended by sjrd.tricktakinggame.network.ThreadedConnection
          extended by sjrd.tricktakinggame.network.commands.CommandBasedConnection
Direct Known Subclasses:
AdminResponder, ClientInitialConnection, ClientResponder, ServerResponder

public class CommandBasedConnection
extends ThreadedConnection

Connexion basée sur la réponse à des commandes

Author:
sjrd

Field Summary
protected  List<Command> commands
          Liste des commandes
private  boolean executingCommand
          Indique si une commande est en cours d'exécution
private  Object executingCommandLock
          Verrou de la propriété executingCommand
 
Fields inherited from class sjrd.tricktakinggame.network.NetworkConnection
reader, socket, writer
 
Constructor Summary
CommandBasedConnection(Socket aSocket)
          Crée une connexion base sur la réponse à des commandes
CommandBasedConnection(Socket aSocket, boolean createSuspended)
          Crée une connexion base sur la réponse à des commandes
 
Method Summary
protected  void checkParameters(Command command, String[] commandLine)
          Vérifie les paramètres pour une commande
protected  void execute()
          Lit et exécute une commande
protected  void executeCommand(Command command, String[] commandLine)
          Exécute une commande
protected  Command findCommandByName(String commandName)
          Trouve une commande à partir de son nom
 boolean isExecutingCommand()
          Indique si une commande est en train d'être exécutée
private  void setExecutingCommand(boolean value)
          Modifie l'état d'exécution de commande
 
Methods inherited from class sjrd.tricktakinggame.network.ThreadedConnection
getThread, onIOException, onNetworkException, onThreadTerminated, recreateThread
 
Methods inherited from class sjrd.tricktakinggame.network.NetworkConnection
close, getReader, getSocket, getWriter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

commands

protected final List<Command> commands
Liste des commandes


executingCommandLock

private final Object executingCommandLock
Verrou de la propriété executingCommand


executingCommand

private boolean executingCommand
Indique si une commande est en cours d'exécution

Constructor Detail

CommandBasedConnection

public CommandBasedConnection(Socket aSocket,
                              boolean createSuspended)
                       throws IOException
Crée une connexion base sur la réponse à des commandes

Parameters:
aSocket -
createSuspended -
Throws:
IOException

CommandBasedConnection

public CommandBasedConnection(Socket aSocket)
                       throws IOException
Crée une connexion base sur la réponse à des commandes

Parameters:
aSocket -
Throws:
IOException
Method Detail

isExecutingCommand

public boolean isExecutingCommand()
Indique si une commande est en train d'être exécutée

Returns:
true si en train d'exécuter une commande, false sinon

setExecutingCommand

private void setExecutingCommand(boolean value)
Modifie l'état d'exécution de commande

Parameters:
value - true si en train d'exécuter une commande, false sinon

findCommandByName

protected Command findCommandByName(String commandName)
Trouve une commande à partir de son nom

Parameters:
commandName - Nom de la commande
Returns:
Commande correspondant, ou null si non trouvée

checkParameters

protected void checkParameters(Command command,
                               String[] commandLine)
                        throws NetworkProtocolException
Vérifie les paramètres pour une commande

Parameters:
command - Commande
commandLine - Ligne de commande
Throws:
NetworkProtocolException - Paramètres invalides

executeCommand

protected void executeCommand(Command command,
                              String[] commandLine)
                       throws IOException
Exécute une commande

Parameters:
command - Commande à exécuter
commandLine - Ligne de commande
Throws:
NetworkProtocolException - Erreur de protocole
NetworkException - Erreur de réseau
IOException - Erreur de communication

execute

protected void execute()
                throws IOException
Lit et exécute une commande

Specified by:
execute in class ThreadedConnection
Throws:
NetworkException - Erreur réseau
IOException - Erreur I/O
See Also:
ThreadedConnection.execute()