org.moyoman.comm.client
Class CommandExecutor

java.lang.Object
  |
  +--org.moyoman.comm.client.CommandExecutor
Direct Known Subclasses:
DirectCommandExecutor

public abstract class CommandExecutor
extends Object

Any class which implements this interface would be used by the client writer to communicate with the server. A single CommandExecutor object is used for all commands to a given server. Only direct method calls are supported now, but in the future, get() would take an argument indicating direct, remote protocol, CORBA, etc.


Field Summary
private static CommandExecutor ce
          The CommandExecutor object.
 
Constructor Summary
CommandExecutor()
           
 
Method Summary
abstract  void deleteActiveGame(String name)
          Delete a temporary game on the server.
abstract  void deleteSavedGame(String name)
          Delete a game from permanent storage on the server.
static CommandExecutor get()
          Get the CommandExecutor object.
protected abstract  Color getColor(String id)
          Get the color of the player associated with this game.
abstract  Debug[] getDebuggingInfo(String id, String name, DebugType[] types)
          Get debugging information about a module from the server.
abstract  GameRecord getGameRecord(String id)
          Get a game record from the server.
protected abstract  Handicap getHandicap(String id)
          Get the handicap for this game.
abstract  String[] getLanguageNames()
          Get all of the supported language names.
abstract  Stone getLastMoveKo(String id)
          Get the score from the server.
abstract  String getMessage(String name)
          Get the internationalized message of the given name.
protected abstract  Mode getMode(String id)
          Get the mode for this game.
abstract  short getMoveNumber(String id)
          Get the move number for the specified game.
abstract  MoveDescriptor getSuggestedMove(String id)
          Get the suggested move from the server.
abstract  Stone[] getSuicideMoves(String id)
           
abstract  Stone[] getSuperKoMoves(String id)
           
abstract  boolean isActive(String id)
          Determine if the game id is an active game.
abstract  String[] listActiveGames()
          List games that are currently active on the server.
abstract  String[] listDebuggingModules(String id, DebugType[] types)
          An array of all of the modules which have debugging information.
abstract  String[] listSavedGames()
          List games permanently stored on the server.
abstract  PlayerManager loadGame(String name)
          Load a game from the server.
abstract  MoveDescriptor makeMove(String id, Stone st)
          Make a move.
protected abstract  String newGeneratedGame(Color color, Handicap handicap, Mode mode)
          Create a new game on the server.
protected abstract  String newGeneratedGame(Color color, Handicap handicap, Mode mode, Rules rules, float komi)
          Create a new game on the server.
protected abstract  String newValidatedGame(Color color, Handicap handicap, Mode mode)
          Create a new game on the server.
protected abstract  String newValidatedGame(Color color, Handicap handicap, Mode mode, Rules rules, float komi)
          Create a new game on the server.
abstract  void onExit()
          This method is called before normal shutdown.
abstract  MoveDescriptor pass(String id)
          Pass in the specified game.
abstract  void registerNonvalidatedPlayerFactory(NonvalidatedPlayerFactory nvpf)
           
abstract  MoveDescriptor requestMove(String id)
          Request a move.
abstract  BooleanResponse requestResignation(String id)
          Request that the server resign.
abstract  void resignGame(String id)
          Resign the specified game.
abstract  PlayerManager resumeGame()
          Restart the most recent active game.
abstract  void saveGame(PlayerManager pm, String name)
          Save a game on the server.
abstract  void setLanguageName(String name)
          Set the default language name.
abstract  void setProperties(String id, Properties props)
          Set the properties for the given id.
abstract  BooleanResponse takeBackMove(PlayerManager pm)
          Take back a move in the specified game.
abstract  MoveDescriptor validateMove(String id, Stone st)
          Validate a move.
protected abstract  void writeLastGameInformation(String blackId, String whiteId)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ce

private static CommandExecutor ce
The CommandExecutor object.

Constructor Detail

CommandExecutor

public CommandExecutor()
Method Detail

get

public static CommandExecutor get()
                           throws InternalErrorException
Get the CommandExecutor object.

Returns:
The CommandExecutor object.
Throws:
InternalErrorException.
InternalErrorException

deleteSavedGame

public abstract void deleteSavedGame(String name)
                              throws NoSuchDataException,
                                     InternalErrorException
Delete a game from permanent storage on the server.

Parameters:
name - The name under which the game was saved.
Throws:
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

deleteActiveGame

public abstract void deleteActiveGame(String name)
                               throws NoSuchDataException,
                                      InternalErrorException
Delete a temporary game on the server.

Parameters:
name - The name under which the game was saved.
Throws:
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

getDebuggingInfo

public abstract Debug[] getDebuggingInfo(String id,
                                         String name,
                                         DebugType[] types)
                                  throws NoSuchDataException,
                                         InternalErrorException
Get debugging information about a module from the server.

Parameters:
id - The game id.
name - The name of the module. One of the String objects returned by the listDebuggingModules() method.
types - An array of DebugType objects supported by the caller.
Returns:
The Debug objects requested.
Throws:
NoSuchDataException - Thrown if the game id or module name do not exist.
InternalErrorException - Thrown if the operation fails for any reason.

getGameRecord

public abstract GameRecord getGameRecord(String id)
                                  throws NoSuchDataException,
                                         InternalErrorException
Get a game record from the server.

Parameters:
id - The game id.
Returns:
The GameRecord object.
Throws:
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

getLastMoveKo

public abstract Stone getLastMoveKo(String id)
                             throws NoSuchDataException,
                                    InternalErrorException
Get the score from the server.

Parameters:
id - The game id.
Returns:
The score object.
Throws:
Exception - Thrown if the operation fails. public abstract Score getScore(String id) throws Exception; NOT YET IMPLEMENTED
NoSuchDataException
InternalErrorException

getSuicideMoves

public abstract Stone[] getSuicideMoves(String id)
                                 throws NoSuchDataException,
                                        InternalErrorException
NoSuchDataException
InternalErrorException

getSuperKoMoves

public abstract Stone[] getSuperKoMoves(String id)
                                 throws NoSuchDataException,
                                        InternalErrorException
NoSuchDataException
InternalErrorException

setProperties

public abstract void setProperties(String id,
                                   Properties props)
                            throws NoSuchDataException,
                                   InternalErrorException
Set the properties for the given id.

Parameters:
id - The game id.
props - The properties.
Throws:
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

getSuggestedMove

public abstract MoveDescriptor getSuggestedMove(String id)
                                         throws NoSuchDataException,
                                                InternalErrorException
Get the suggested move from the server.

Parameters:
id - The game id.
Returns:
The SuggestedMove object.
Throws:
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

isActive

public abstract boolean isActive(String id)
                          throws InternalErrorException
Determine if the game id is an active game.

Parameters:
id - The game id.
Returns:
true if the game is active, or false.
Throws:
InternalErrorException - - Thrown if the operation fails for any reason.

listActiveGames

public abstract String[] listActiveGames()
                                  throws InternalErrorException
List games that are currently active on the server.

Returns:
All game ids.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

listSavedGames

public abstract String[] listSavedGames()
                                 throws InternalErrorException
List games permanently stored on the server.

Returns:
All game ids that are stored on the server.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

listDebuggingModules

public abstract String[] listDebuggingModules(String id,
                                              DebugType[] types)
                                       throws NoSuchDataException,
                                              InternalErrorException
An array of all of the modules which have debugging information. The types parameter acts as a filter, so that modules which only have debugging information that the client will not understand are not on the list.

Parameters:
id - The game id.
types - A filter which indicates the desired Debug types.
Returns:
An array of all of the module names with debug information.
Throws:
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

loadGame

public abstract PlayerManager loadGame(String name)
                                throws NoSuchDataException,
                                       InternalErrorException
Load a game from the server. This takes a game that was in permanent storage, and adds it to the active games in memory.

Parameters:
name - The name of the game to be loaded.
Returns:
A PlayerManager object for the loaded game.
Throws:
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

resumeGame

public abstract PlayerManager resumeGame()
                                  throws NoSuchDataException,
                                         InternalErrorException
Restart the most recent active game.

Returns:
A PlayerManager object for the resumed game.
Throws:
Exception - Thrown if the operation fails.
NoSuchDataException - Thrown if there is no game to resume.
InternalErrorException - Thrown if the operation fails for any reason.

requestResignation

public abstract BooleanResponse requestResignation(String id)
                                            throws NoSuchDataException,
                                                   InternalErrorException
Request that the server resign.

Parameters:
id - The game id.
Returns:
A BooleanResponse object.
Throws:
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

saveGame

public abstract void saveGame(PlayerManager pm,
                              String name)
                       throws NoSuchDataException,
                              DataAlreadyExistsException,
                              InternalErrorException
Save a game on the server. It is an error if the game is not an active game.

Parameters:
pm - The PlayerManager to be saved
name - The name to save the game as.
Throws:
NoSuchDataException - Thrown if the game does not exist
DataAlreadyExistsException - Thrown if the new id is already used.
InternalErrorException - Thrown if the operation fails for any reason.

takeBackMove

public abstract BooleanResponse takeBackMove(PlayerManager pm)
Take back a move in the specified game. The game is restored to the state that it was in before the users last move. If the user requests this while his current move is still being processed, then the net result is that the two requests cancel out.

Parameters:
pm - The PlayerManager for which the move is to be taken back.
Returns:
A BooleanResponse object indicating if the operation was successfully completed.

getMoveNumber

public abstract short getMoveNumber(String id)
                             throws InternalErrorException
Get the move number for the specified game.

Parameters:
id - - The game id.
Returns:
A short which is the move number.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

getLanguageNames

public abstract String[] getLanguageNames()
                                   throws InternalErrorException
Get all of the supported language names.

Returns:
An array of String objects.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

setLanguageName

public abstract void setLanguageName(String name)
                              throws NoSuchDataException,
                                     InternalErrorException
Set the default language name.

Parameters:
name -
Throws:
NoSuchDataException - Thrown if the language name does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

getMessage

public abstract String getMessage(String name)
                           throws InternalErrorException
Get the internationalized message of the given name.

Parameters:
name - The name of the message.
Returns:
A String which is the internationalized message.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

makeMove

public abstract MoveDescriptor makeMove(String id,
                                        Stone st)
                                 throws IllegalMoveException,
                                        NoSuchDataException,
                                        InternalErrorException
Make a move.

Parameters:
id - The game id.
st - The stone to be played. x or y parameters are out of range.
Throws:
IllegalMoveException - Thrown if the move is illegal.
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

validateMove

public abstract MoveDescriptor validateMove(String id,
                                            Stone st)
                                     throws IllegalMoveException,
                                            NoSuchDataException,
                                            InternalErrorException
Validate a move.

Parameters:
id - The game id.
st - The stone to be played. x or y parameters are out of range.
Throws:
IllegalMoveException - Thrown if the move is illegal.
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

newGeneratedGame

protected abstract String newGeneratedGame(Color color,
                                           Handicap handicap,
                                           Mode mode,
                                           Rules rules,
                                           float komi)
                                    throws InternalErrorException
Create a new game on the server.

Parameters:
color - The color of the client .
handicap - The handicap to be used. May be null for no handicap.
mode - One of BEST, FAST, or TOURNAMENT.
rules - The rule set, e.g, Japanese.
komi - The amount of the komi .
Returns:
An id which represents the game.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

newGeneratedGame

protected abstract String newGeneratedGame(Color color,
                                           Handicap handicap,
                                           Mode mode)
                                    throws InternalErrorException
Create a new game on the server.

Parameters:
color - The color of the client .
handicap - The handicap to be used. May be null for no handicap.
mode - One of BEST, FAST, or TOURNAMENT.
Returns:
An id which represents the game.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

newValidatedGame

protected abstract String newValidatedGame(Color color,
                                           Handicap handicap,
                                           Mode mode,
                                           Rules rules,
                                           float komi)
                                    throws InternalErrorException
Create a new game on the server.

Parameters:
color - The color of the client .
handicap - The handicap to be used. May be null for no handicap.
mode - One of BEST, FAST, or TOURNAMENT.
rules - The rule set, e.g, Japanese.
komi - The amount of the komi .
Returns:
An id which represents the game.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

newValidatedGame

protected abstract String newValidatedGame(Color color,
                                           Handicap handicap,
                                           Mode mode)
                                    throws InternalErrorException
Create a new game on the server.

Parameters:
color - The color of the client .
handicap - The handicap to be used. May be null for no handicap.
mode - One of BEST, FAST, or TOURNAMENT.
Returns:
An id which represents the game.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

pass

public abstract MoveDescriptor pass(String id)
                             throws NoSuchDataException,
                                    InternalErrorException
Pass in the specified game.

Parameters:
id - The game id.
Returns:
A MoveDescriptor which describes the move.
Throws:
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

requestMove

public abstract MoveDescriptor requestMove(String id)
                                    throws IllegalMoveException,
                                           NoSuchDataException,
                                           InternalErrorException
Request a move.

Parameters:
id - The game id.
Returns:
A MoveDescriptor object which describes the move.
Throws:
IllegalMoveException - Thrown if the move is illegal.
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

resignGame

public abstract void resignGame(String id)
                         throws NoSuchDataException,
                                InternalErrorException
Resign the specified game. End the game, and remove it from active storage.

Parameters:
id - The game id.
Throws:
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

writeLastGameInformation

protected abstract void writeLastGameInformation(String blackId,
                                                 String whiteId)

getColor

protected abstract Color getColor(String id)
                           throws NoSuchDataException,
                                  InternalErrorException
Get the color of the player associated with this game. Obviously, there are two players for any game, but the CommandExecutor object is only used by one of those players for that game id.

Parameters:
id - The game id
Returns:
A Color object.
Throws:
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

getHandicap

protected abstract Handicap getHandicap(String id)
                                 throws NoSuchDataException,
                                        InternalErrorException
Get the handicap for this game.

Parameters:
id - The game id
Returns:
A Handicap object.
Throws:
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

getMode

protected abstract Mode getMode(String id)
                         throws NoSuchDataException,
                                InternalErrorException
Get the mode for this game.

Parameters:
id - The game id
Returns:
The Mode object.
Throws:
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

registerNonvalidatedPlayerFactory

public abstract void registerNonvalidatedPlayerFactory(NonvalidatedPlayerFactory nvpf)

onExit

public abstract void onExit()
This method is called before normal shutdown.