|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.moyoman.framework.FSPersister
This class saves and restores games using the file system. It implements the Persister interface, and uses the Java serialization functionality to accomplish this.
Field Summary | |
private static String |
LAST_GAME_FILE_NAME
This is the name of the last game file. |
private static String |
MOVE_PREFIX
This string is used as part of the filename of a temporary game at a particular move. |
private static String |
PERMANENT_DIR
The directory under which permanent games are stored. |
private static String |
PG_SUFFIX
This is the suffix appended to a persisted game name to get the file name. |
private static ServerConfig |
sc
The ServerConfig object. |
private static String |
TEMPORARY_DIR
The directory under which temporary games are stored. |
private static String |
topDir
The top level directory where the moyoman distribution is installed. |
Constructor Summary | |
(package private) |
FSPersister()
Create a new FSPersister object. |
Method Summary | |
private static void |
checkTempGames(long cutoff)
Delete all temporary games which have expired. |
private static void |
checkTempGames(ServerConfig sc)
Delete all temporary games which have expired. |
void |
cleanup()
Delete all temporary game files. |
void |
delete(PersistedGame game)
Delete a game in permanent storage. |
private void |
deleteTemporaryState(GameId id)
|
void |
deleteTemporaryState(PersistedGame game)
Delete a game in temporary storage. |
private Controller |
getController(String fname)
Deserialize the file and create a Controller object. |
private String |
getLastGameFileName()
|
private static String |
getPermanentDirectory()
Get the name of the directory where the permanent games are stored. |
private String |
getPermanentFileName(GameId id)
|
private String |
getPermanentFileName(String id)
Get the filename for the game id in permanent storage. |
private PersistedGame |
getPersistedGame(String fname)
|
private String |
getPersistedGameId(String fname,
Color color)
|
private String |
getSavedGameFileName(String name)
|
PersistedGame |
getSavedPersistedGame(String name)
|
private static String |
getTemporaryDirectory()
Get the name of the directory where the temporary games are stored. |
private String |
getTemporaryDirectoryName(GameId id)
|
private String |
getTemporaryDirectoryName(String id)
Get the directory name for the game id in temporary storage. |
private String |
getTemporaryFileName(GameId id)
Get the name of the most recent file for the particular game. |
private String |
getTemporaryFileName(GameId id,
int move)
Get the filename for the game id in temporary storage. |
private String |
getTemporaryGameFileName(String name)
|
PersistedGame |
getTemporaryPersistedGame(String name)
|
private PersistedGame[] |
listGames(String fname)
|
PersistedGame[] |
listPermanentGames()
Return an array of all the games in permanent storage. |
PersistedGame[] |
listTemporaryGames()
Return an array of all the games in temporary storage. |
boolean |
permanentStateExists(GameId id)
|
boolean |
permanentStateExists(PersistedGame game)
Return whether the game exists in permanent storage. |
Controller |
restore(GameId id)
Restore a game from permanent storage. |
Controller |
restoreMostRecentTemporaryState(Color color)
Restore the most recent game in temporary storage. |
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 specified move. |
private void |
save(GameId id,
Controller cont)
Save the game to permanent storage. |
void |
save(PersistedGame game)
Save the game to permanent storage. |
private void |
saveController(Controller c,
String fname)
Serialize the Controller object and write it out to disk. |
void |
saveTemporaryGame(GameId black,
GameId white)
|
void |
saveTemporaryState(GameId id,
Controller cont,
int move)
Save the game to temporary storage for a particular move. |
boolean |
temporaryStateExists(GameId id)
|
boolean |
temporaryStateExists(GameId id,
int move)
Return whether the game exists in temporary storage for the given move. |
boolean |
temporaryStateExists(PersistedGame game)
Return whether the game exists in temporary storage. |
private void |
updateLastMove(GameId id,
int move)
Update the last_move file. |
private void |
writeGameFile(String fname,
GameId black,
GameId white)
|
private void |
writeLastGameFile(GameId black,
GameId white)
|
void |
writeLastGameInformation(GameId black,
GameId white)
|
private void |
writeSavedGameFile(PersistedGame game)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final String TEMPORARY_DIR
private static final String PERMANENT_DIR
private static final String MOVE_PREFIX
private static String PG_SUFFIX
private static String LAST_GAME_FILE_NAME
private static final ServerConfig sc
private static final String topDir
Constructor Detail |
FSPersister() throws InternalErrorException
InternalErrorException
- Thrown if the operation fails for any reason.Method Detail |
private static String getTemporaryDirectory()
private static String getPermanentDirectory()
private static void checkTempGames(ServerConfig sc) throws InternalErrorException
sc
- The ServerConfig object.
InternalErrorException
- Thrown if the operation fails for any reason.private static void checkTempGames(long cutoff) throws InternalErrorException
cutoff
- The time before which files should be deleted.
InternalErrorException
- Thrown if the operation fails for any reason.public void delete(PersistedGame game) throws InternalErrorException, PermissionsException, NoSuchDataException
delete
in interface Persister
game
- The game to delete.
PermissionsException
- Thrown if the delete operation fails.
NoSuchDataException
- Thrown if the file does not exist.
InternalErrorException
- Thrown if the operation fails for any reason.public void deleteTemporaryState(PersistedGame game) throws InternalErrorException, PermissionsException, NoSuchDataException
deleteTemporaryState
in interface Persister
game
- The game to delete.
PermissionsException
- Thrown if the delete operation fails.
NoSuchDataException
- Thrown if the file does not exist.
InternalErrorException
- Thrown if the operation fails for any reason.private void deleteTemporaryState(GameId id) throws PermissionsException, NoSuchDataException
PermissionsException
NoSuchDataException
public Controller restore(GameId id) throws NoSuchDataException, InternalErrorException
restore
in interface Persister
id
- The id of the game.
NoSuchDataException
- Thrown if the saved game does not exist.
InternalErrorException
- Thrown if the operation fails for any reason.public Controller restoreTemporaryState(GameId id) throws NoSuchDataException, InternalErrorException
restoreTemporaryState
in interface Persister
id
- The id of the game.
NoSuchDataException
- Thrown if the temporary game does not exist.
InternalErrorException
- Thrown if the operation fails for any reason.public Controller restoreMostRecentTemporaryState(Color color) throws NoSuchDataException, InternalErrorException
restoreMostRecentTemporaryState
in interface Persister
color
- The color of the player to restore.
NoSuchDataException
- Thrown if no temporary game exists.
InternalErrorException
- Thrown if the operation fails for any reason.public Controller restoreTemporaryState(GameId id, int number) throws NoSuchDataException, InternalErrorException
restoreTemporaryState
in interface Persister
id
- The id of the game.number
- The move number to restore to.
NoSuchDataException
- Thrown if the information for the temporary game and move do not exist.
InternalErrorException
- Thrown if the operation fails for any reason.private void save(GameId id, Controller cont) throws DataAlreadyExistsException, InternalErrorException
id
- The name to save the game as.cont
- The controller with the game information.
DataAlreadyExistsException
- Thrown if the id is already used.
InternalErrorException
- Thrown if the operation fails for any reason.public void save(PersistedGame game) throws DataAlreadyExistsException, InternalErrorException
Persister
save
in interface Persister
game
- The game to be saved.
DataAlreadyExistsException
- Thrown if the new id already exists.
InternalErrorException
- Thrown if the operation fails for any reason.public void saveTemporaryGame(GameId black, GameId white) throws InternalErrorException
saveTemporaryGame
in interface Persister
InternalErrorException
public void saveTemporaryState(GameId id, Controller cont, int move) throws InternalErrorException
saveTemporaryState
in interface Persister
id
- The id of the gamecont
- The Controller with the state information.
InternalErrorException
- Thrown if the operation fails for any reason.private void updateLastMove(GameId id, int move) throws NoSuchDataException, InternalErrorException
NoSuchDataException
- Thrown if the information for the temporary game and move do not exist.
InternalErrorException
- Thrown if the operation fails for any reason.public boolean permanentStateExists(GameId id)
permanentStateExists
in interface Persister
public boolean permanentStateExists(PersistedGame game)
permanentStateExists
in interface Persister
game
- The game being checked.
public boolean temporaryStateExists(GameId id) throws InternalErrorException
temporaryStateExists
in interface Persister
InternalErrorException
public boolean temporaryStateExists(PersistedGame game) throws InternalErrorException
temporaryStateExists
in interface Persister
game
- The game being checked.
InternalErrorException
- Thrown if the operation fails for any reason.public boolean temporaryStateExists(GameId id, int move)
temporaryStateExists
in interface Persister
id
- The id of the game.move
- The move number of the game.
private void saveController(Controller c, String fname) throws InternalErrorException
c
- The Controller to be serialized.fname
- The filename of the serialized file.
InternalErrorException
- Thrown if the operation fails for any reason.private Controller getController(String fname) throws NoSuchDataException, InternalErrorException
fname
- The file name of the serialized file.
NoSuchDataException
- Thrown if the serialized file does not exist.
InternalErrorException
- Thrown if the operation fails for any reason.private String getPermanentFileName(String id)
id
- The game id.
private String getPermanentFileName(GameId id)
private String getTemporaryDirectoryName(String id)
id
- The game id.
private String getTemporaryDirectoryName(GameId id)
private String getTemporaryFileName(GameId id, int move)
id
- The game id.
private String getTemporaryFileName(GameId id) throws NoSuchDataException, InternalErrorException
id
- The game id.
InternalErrorException
- Thrown if the operation fails for any reason.
NoSuchDataException
public PersistedGame[] listTemporaryGames() throws InternalErrorException
listTemporaryGames
in interface Persister
InternalErrorException
- Thrown if the operation fails for any reason.private PersistedGame[] listGames(String fname) throws InternalErrorException
InternalErrorException
public PersistedGame[] listPermanentGames() throws InternalErrorException
listPermanentGames
in interface Persister
InternalErrorException
- Thrown if the operation fails for any reason.private String getTemporaryGameFileName(String name)
private String getLastGameFileName()
private String getSavedGameFileName(String name)
public void writeLastGameInformation(GameId black, GameId white)
writeLastGameInformation
in interface Persister
private void writeLastGameFile(GameId black, GameId white)
private void writeSavedGameFile(PersistedGame game)
private void writeGameFile(String fname, GameId black, GameId white)
private String getPersistedGameId(String fname, Color color) throws NoSuchDataException, InternalErrorException
NoSuchDataException
InternalErrorException
private PersistedGame getPersistedGame(String fname) throws NoSuchDataException, InternalErrorException
NoSuchDataException
InternalErrorException
public PersistedGame getTemporaryPersistedGame(String name) throws NoSuchDataException, InternalErrorException
getTemporaryPersistedGame
in interface Persister
NoSuchDataException
InternalErrorException
public PersistedGame getSavedPersistedGame(String name) throws NoSuchDataException, InternalErrorException
getSavedPersistedGame
in interface Persister
NoSuchDataException
InternalErrorException
public void cleanup() throws InternalErrorException
cleanup
in interface Persister
InternalErrorException
- Thrown if the operation fails for any reason.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |