org.moyoman.comm.client
Class DirectCommandExecutor

java.lang.Object
  |
  +--org.moyoman.comm.client.CommandExecutor
        |
        +--org.moyoman.comm.client.DirectCommandExecutor

public class DirectCommandExecutor
extends CommandExecutor

This interface would be used by the client writer to communicate with the server. It makes method calls directly, so the client and server must be on the same machine running in the same virtual machine.


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

Field Detail

controllers

private static HashMap controllers
The key is the game id, and the value is the Controller object.


symbolicName

private String symbolicName
The name of the language to be used by this object.


nvPlayerFactory

private NonvalidatedPlayerFactory nvPlayerFactory
Constructor Detail

DirectCommandExecutor

protected DirectCommandExecutor()
Create a new DirectCommandExecutor object.

Method Detail

deleteSavedGame

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

Specified by:
deleteSavedGame in class CommandExecutor
Parameters:
name - The name under which the game was saved.
Throws:
NoSuchDataException - - Thrown if the id is not a saved game.
InternalErrorException - Thrown if the operation fails for any reason.

deleteActiveGame

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

Specified by:
deleteActiveGame in class CommandExecutor
Parameters:
name - The name under which the game was saved.
Throws:
NoSuchDataException - - Thrown if the id is not an active game.
InternalErrorException - Thrown if the operation fails for any reason.

getDebuggingInfo

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

Specified by:
getDebuggingInfo in class CommandExecutor
Parameters:
id - The game id.
name - One of the String objects returned by the listDebuggingModules() method. It is of the form: moduletype - modulename.
types - An array of DebugType objects supported by the caller.
Returns:
The Debug objects requested.
Throws:
NoSuchDataException - - Thrown if the id is not an active game.
InternalErrorException - Thrown if the operation fails for any reason.

getGameRecord

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

Specified by:
getGameRecord in class CommandExecutor
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.

setProperties

public void setProperties(String id,
                          Properties props)
Set the properties for the id.

Specified by:
setProperties in class CommandExecutor
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.

getLastMoveKo

public Stone getLastMoveKo(String id)
                    throws NoSuchDataException,
                           InternalErrorException
Description copied from class: CommandExecutor
Get the score from the server.

Specified by:
getLastMoveKo in class CommandExecutor
Parameters:
id - The game id.
Returns:
The score object.
NoSuchDataException
InternalErrorException

getSuicideMoves

public Stone[] getSuicideMoves(String id)
                        throws NoSuchDataException,
                               InternalErrorException
Specified by:
getSuicideMoves in class CommandExecutor
NoSuchDataException
InternalErrorException

getSuperKoMoves

public Stone[] getSuperKoMoves(String id)
                        throws NoSuchDataException,
                               InternalErrorException
Specified by:
getSuperKoMoves in class CommandExecutor
NoSuchDataException
InternalErrorException

getSuggestedMove

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

Specified by:
getSuggestedMove in class CommandExecutor
Parameters:
id - The game id.
Returns:
The MoveDescriptor object.
Throws:
NoSuchDataException - - Thrown if the id is not an active game.
InternalErrorException - Thrown if the operation fails for any reason.

isActive

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

Specified by:
isActive in class CommandExecutor
Parameters:
id - The game in question.
Returns:
true if the game is active, or false.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

listActiveGames

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

Specified by:
listActiveGames in class CommandExecutor
Returns:
All game ids.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

listSavedGames

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

Specified by:
listSavedGames in class CommandExecutor
Returns:
All game ids that are stored on the server.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

listDebuggingModules

public 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.

Specified by:
listDebuggingModules in class CommandExecutor
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 id is not an active game.
InternalErrorException - Thrown if the operation fails for any reason.

loadGame

public 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.

Specified by:
loadGame in class CommandExecutor
Parameters:
name - The name of the game to be loaded.
Returns:
The new id of the game.
Throws:
NoSuchDataException - - Thrown if the id is not a saved game.
InternalErrorException - Thrown if the operation fails for any reason.

createPlayerManager

private PlayerManager createPlayerManager(Controller black,
                                          Controller white)
                                   throws InternalErrorException
InternalErrorException

resumeGame

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

Specified by:
resumeGame in class CommandExecutor
Returns:
An id which represents the game.
Throws:
NoSuchDataException - - Thrown if there is no game to resume.
InternalErrorException - Thrown if the operation fails for any reason.

makeMove

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

Specified by:
makeMove in class CommandExecutor
Parameters:
id - The game id.
st - The stone to be played.
Throws:
NoSuchDataException - - Thrown if id is not an active game.
InternalErrorException - Thrown if the operation fails for any reason.
IllegalMoveException - Thrown if the move is illegal.

validateMove

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

Specified by:
validateMove in class CommandExecutor
Parameters:
id - The game id.
st - The stone to be played.
Throws:
NoSuchDataException - - Thrown if id is not an active game.
InternalErrorException - Thrown if the operation fails for any reason.
IllegalMoveException - Thrown if the move is illegal.

newGeneratedGame

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

Specified by:
newGeneratedGame in class CommandExecutor
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 String newGeneratedGame(Color color,
                                  Handicap handicap,
                                  Mode mode)
                           throws InternalErrorException
Create a new game on the server.

Specified by:
newGeneratedGame in class CommandExecutor
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 String newValidatedGame(Color color,
                                  Handicap handicap,
                                  Mode mode,
                                  Rules rules,
                                  float komi)
                           throws InternalErrorException
Create a new game on the server.

Specified by:
newValidatedGame in class CommandExecutor
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 String newValidatedGame(Color color,
                                  Handicap handicap,
                                  Mode mode)
                           throws InternalErrorException
Create a new game on the server.

Specified by:
newValidatedGame in class CommandExecutor
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 MoveDescriptor pass(String id)
                    throws NoSuchDataException,
                           InternalErrorException
Pass in the specified game.

Specified by:
pass in class CommandExecutor
Parameters:
id - The game id.
Returns:
A MoveDescriptor which describes the move.
Throws:
NoSuchDataException - - Thrown if id is not an active game.
InternalErrorException - Thrown if the operation fails for any reason.

requestMove

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

Specified by:
requestMove in class CommandExecutor
Parameters:
id - The game id.
Returns:
A MoveDescriptor object which describes the move.
Throws:
IllegalMoveException - - Thrown if the move is illegal.
NoSuchDataException - - Thrown if id is not an active game.
InternalErrorException - Thrown if the operation fails for any reason.

requestResignation

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

Specified by:
requestResignation in class CommandExecutor
Parameters:
id - The game id.
Returns:
A BooleanResponse object.
Throws:
NoSuchDataException - - Thrown if id is not an active game.
InternalErrorException - Thrown if the operation fails for any reason.

resignGame

public void resignGame(String id)
                throws NoSuchDataException,
                       InternalErrorException
Resign the specified game.

Specified by:
resignGame in class CommandExecutor
Parameters:
id - The game id.
Throws:
NoSuchDataException - - Thrown if id is not an active game.
InternalErrorException - Thrown if the operation fails for any reason.

saveGame

public 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. This method does not check to see if it is overwriting an already existing game.

Specified by:
saveGame in class CommandExecutor
Parameters:
pm - The PlayerManager to be saved
name - The name to save the game as.
Throws:
NoSuchDataException - - Thrown if id is not an active game.
DataAlreadyExists - - Thrown if the newid is already used for storing a game.
InternalErrorException - Thrown if the operation fails for any reason.
DataAlreadyExistsException - Thrown if the new id is already used.

takeBackMove

public 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.

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

writeLastGameInformation

protected void writeLastGameInformation(String blackId,
                                        String whiteId)
Specified by:
writeLastGameInformation in class CommandExecutor

getMoveNumber

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

Specified by:
getMoveNumber in class CommandExecutor
Parameters:
id - - The game id.
Returns:
A short which is the move number of the next move.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

getLanguageNames

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

Specified by:
getLanguageNames in class CommandExecutor
Returns:
An array of String objects.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

setLanguageName

public void setLanguageName(String symName)
                     throws NoSuchDataException,
                            InternalErrorException
Set the language for each game loaded in this controller.

Specified by:
setLanguageName in class CommandExecutor
Parameters:
symName -
Throws:
NoSuchDataException - - Thrown if symName is not a valid language name.
InternalErrorException - Thrown if the operation fails for any reason.

getMessage

public String getMessage(String name)
                  throws InternalErrorException
Get the message in the specified language.

Specified by:
getMessage in class CommandExecutor
Parameters:
name - - The message name.
Returns:
A String which is the internationalized message.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

getColor

protected Color getColor(String id)
                  throws NoSuchDataException,
                         InternalErrorException
Get the color to move for the specified game.

Specified by:
getColor in class CommandExecutor
Parameters:
id - The game in question.
Returns:
A Color object.
Throws:
NoSuchDataException - - Thrown if id is not an active game.
InternalErrorException - Thrown if the operation fails for any reason.

getHandicap

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

Specified by:
getHandicap in class CommandExecutor
Parameters:
id - The game in question.
Returns:
A Handicap object.
Throws:
NoSuchDataException - - Thrown if id is not an active game.
InternalErrorException - Thrown if the operation fails for any reason.

getMode

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

Specified by:
getMode in class CommandExecutor
Parameters:
id - The game in question.
Returns:
A Mode object.
Throws:
NoSuchDataException - - Thrown if id is not an active game.
InternalErrorException - Thrown if the operation fails for any reason.

registerNonvalidatedPlayerFactory

public void registerNonvalidatedPlayerFactory(NonvalidatedPlayerFactory nvpf)
Specified by:
registerNonvalidatedPlayerFactory in class CommandExecutor

onExit

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

Specified by:
onExit in class CommandExecutor