org.moyoman.framework
Class ControllerState

java.lang.Object
  |
  +--org.moyoman.framework.ControllerState

class ControllerState
extends Object

This class is used to prevent multiple operations from occuring on the same game simultaneously. Errors could occur if a game was being saved while the server was also making a move. This class provides methods for synchronizing access to a game. Note that the endGame method is not synchronized, since the user may wish to terminate a game without having to wait for the next move to be generated.


Field Summary
private static ArrayList games
          Each element is a GameId of active games.
private static ArrayList operations
          Each element is a GameId which has an operation actively executing.
private static ArrayList terminated
          Each element is a GameId which has had endGame() called on it.
 
Constructor Summary
(package private) ControllerState()
           
 
Method Summary
protected static void endGame(GameId id)
          Remove the specified game as being active.
protected static void endOperation(GameId id)
          End the operation on the specified game.
protected static void startGame(GameId id)
          Start a new game.
protected static void startOperation(GameId id)
          Start an operation on the specified game if none are in progress.
private static void wait(GameId id)
          Wait until the current operation on the game has ended.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

games

private static ArrayList games
Each element is a GameId of active games.


operations

private static ArrayList operations
Each element is a GameId which has an operation actively executing.


terminated

private static ArrayList terminated
Each element is a GameId which has had endGame() called on it.

Constructor Detail

ControllerState

ControllerState()
Method Detail

startGame

protected static void startGame(GameId id)
                         throws InconsistentStateException
Start a new game. A game may not be started if the id is already actively used.

Parameters:
id - The GameId object.
Throws:
InconsistentStateException - - Thrown if the id is already active.

startOperation

protected static void startOperation(GameId id)
                              throws InconsistentStateException
Start an operation on the specified game if none are in progress. The way that this method works is as follows:

endOperation

protected static void endOperation(GameId id)
End the operation on the specified game.

Parameters:
id - The GameId object.

endGame

protected static void endGame(GameId id)
Remove the specified game as being active. The game is also marked as having terminated so that endOperation() does not throw an exception.

Parameters:
id - The GameId object.
Throws:
InconsistentStateException - - Thrown if the game is not active.

wait

private static void wait(GameId id)
Wait until the current operation on the game has ended.

Parameters:
id - The GameId object.