org.moyoman.framework
Interface Persister

All Known Implementing Classes:
FSPersister

public interface Persister

This specifies the interface for saving and restoring games.


Method Summary
 void cleanup()
          Perform any necessary clean up before normal shutdown of the server.
 void delete(PersistedGame game)
          Delete a game in permanent storage.
 void deleteTemporaryState(PersistedGame game)
          Delete a game in temporary storage.
 PersistedGame getSavedPersistedGame(String name)
           
 PersistedGame getTemporaryPersistedGame(String name)
           
 PersistedGame[] listPermanentGames()
          Return an array of all games in permanent storage.
 PersistedGame[] listTemporaryGames()
          Return an array of all games in temporary storage.
 boolean permanentStateExists(GameId id)
           
 boolean permanentStateExists(PersistedGame game)
          Return true if the permanent state exists.
 Controller restore(GameId id)
          Restore a game from permanent storage.
 Controller restoreMostRecentTemporaryState(Color color)
          Restore the most recent game in temporary storage to the latest saved state.
 Controller restoreTemporaryState(GameId id)
          Restore a game from temporary storage to the latest saved state.
 Controller restoreTemporaryState(GameId id, int number)
          Restore a game from temporary storage to the given move number.
 void save(PersistedGame game)
          Save the game to permanent storage.
 void saveTemporaryGame(GameId black, GameId white)
           
 void saveTemporaryState(GameId id, Controller c, int move)
          Save the game to temporary storage.
 boolean temporaryStateExists(GameId id)
           
 boolean temporaryStateExists(GameId id, int move)
          Return true if the temporary state exists for a given move.
 boolean temporaryStateExists(PersistedGame game)
          Return true if the temporary state exists.
 void writeLastGameInformation(GameId black, GameId white)
           
 

Method Detail

delete

public void delete(PersistedGame game)
            throws PermissionsException,
                   NoSuchDataException,
                   InternalErrorException
Delete a game in permanent storage.

Parameters:
game - The game to delete.
Throws:
PermissionsException - Thrown if the game cannot be deleted.
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

deleteTemporaryState

public void deleteTemporaryState(PersistedGame game)
                          throws PermissionsException,
                                 NoSuchDataException,
                                 InternalErrorException
Delete a game in temporary storage.

Parameters:
game - The game to delete.
Throws:
PermissionsException - Thrown if the game cannot be deleted.
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

restore

public Controller restore(GameId id)
                   throws NoSuchDataException,
                          InternalErrorException
Restore a game from permanent storage.

Parameters:
id - The id of the game.
Returns:
The Controller object representing the game in its current state.
Throws:
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

restoreTemporaryState

public Controller restoreTemporaryState(GameId id,
                                        int number)
                                 throws NoSuchDataException,
                                        InternalErrorException
Restore a game from temporary storage to the given move number.

Parameters:
id - The id of the game.
number - The move number to restore to.
Returns:
The Controller object representing the game in its current state.
Throws:
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

restoreTemporaryState

public Controller restoreTemporaryState(GameId id)
                                 throws NoSuchDataException,
                                        InternalErrorException
Restore a game from temporary storage to the latest saved state.

Parameters:
id - The id of the game.
Returns:
The Controller object representing the game in its current state.
Throws:
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

restoreMostRecentTemporaryState

public Controller restoreMostRecentTemporaryState(Color color)
                                           throws NoSuchDataException,
                                                  InternalErrorException
Restore the most recent game in temporary storage to the latest saved state.

Parameters:
color - The color of the player to restore.
Returns:
The Controller object representing the game in its current state.
Throws:
NoSuchDataException - Thrown if the game does not exist.
InternalErrorException - Thrown if the operation fails for any reason.

save

public void save(PersistedGame game)
          throws DataAlreadyExistsException,
                 InternalErrorException
Save the game to permanent storage.

Parameters:
game - The game to be saved.
Throws:
DataAlreadyExistsException - Thrown if the new id already exists.
InternalErrorException - Thrown if the operation fails for any reason.

saveTemporaryState

public void saveTemporaryState(GameId id,
                               Controller c,
                               int move)
                        throws InternalErrorException
Save the game to temporary storage. This operation will be called frequently throughout the game, after every move or every other move. Therefore, this method is also responsible for deleting the state information for older moves, depending on how many previous moves are to be saved as defined in the configuration files.

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

saveTemporaryGame

public void saveTemporaryGame(GameId black,
                              GameId white)
                       throws InternalErrorException
InternalErrorException

temporaryStateExists

public boolean temporaryStateExists(PersistedGame game)
                             throws InternalErrorException
Return true if the temporary state exists.

Parameters:
game - The game being checked.
Returns:
true if the game exists, or false.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

temporaryStateExists

public boolean temporaryStateExists(GameId id)
                             throws InternalErrorException
InternalErrorException

permanentStateExists

public boolean permanentStateExists(PersistedGame game)
                             throws InternalErrorException
Return true if the permanent state exists.

Parameters:
game - The game being checked.
Returns:
true if the game exists, or false.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

permanentStateExists

public boolean permanentStateExists(GameId id)
                             throws InternalErrorException
InternalErrorException

temporaryStateExists

public boolean temporaryStateExists(GameId id,
                                    int move)
                             throws InternalErrorException
Return true if the temporary state exists for a given move.

Parameters:
id - The game being checked.
move - The move of the game being checked.
Returns:
true if the game exists for the given move, or false.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

listTemporaryGames

public PersistedGame[] listTemporaryGames()
                                   throws InternalErrorException
Return an array of all games in temporary storage.

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

listPermanentGames

public PersistedGame[] listPermanentGames()
                                   throws InternalErrorException
Return an array of all games in permanent storage.

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

getTemporaryPersistedGame

public PersistedGame getTemporaryPersistedGame(String name)
                                        throws NoSuchDataException,
                                               InternalErrorException
NoSuchDataException
InternalErrorException

getSavedPersistedGame

public PersistedGame getSavedPersistedGame(String name)
                                    throws NoSuchDataException,
                                           InternalErrorException
NoSuchDataException
InternalErrorException

writeLastGameInformation

public void writeLastGameInformation(GameId black,
                                     GameId white)

cleanup

public void cleanup()
             throws InternalErrorException
Perform any necessary clean up before normal shutdown of the server.

Throws:
InternalErrorException - Thrown if the operation fails for any reason.