Package rea
Class Manager
java.lang.Object
rea.Manager
A pool of game instances.
It is responsible for creating and managing game instances.
It can also be used to get the names of the available games,
and the available game instances. A listener can be added to
be notified of changes in the list of games about to start.
- Author:
- José Paulo Leal
jpleal@fc.up.pt
- Implementation Note:
- follows the Singleton design pattern.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final long
Default time in milliseconds to keep a game instance after it has ended. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addGamesUpdateListener
(UpdateListener<GamesUpdateEvent> listener) Add a listener to the games update event.(package private) void
Broadcast an update in the list of games about to start.createGameInstance
(String gameName) Create a game instance with the given name.void
deleteGameInstance
(GameInstance gameInstance) Delete a game instance from the pool, if it can be deleted.Get the names available games.Get all the game instances.(package private) AbstractGameplayFactory
Get the gameplay factory.(package private) List
<GameInstance> Get the games instances about to start.static Manager
Get the instance of the game instance pool.(package private) static long
Get the time in milliseconds to keep a game instance after it has ended.void
Remove game instances that have ended more thankeepAfterEnd
milliseconds ago.(package private) void
reset()
Reset the pool to its initial state.(package private) void
setGameplayFactory
(AbstractGameplayFactory gameplayFactory) Set the gameplay factory.(package private) static void
setKeepAfterEnd
(long keepAfterEnd) Set the time in milliseconds to keep a game instance after it has ended.
-
Field Details
-
KEEP_AFTER_END
static final long KEEP_AFTER_ENDDefault time in milliseconds to keep a game instance after it has ended.- See Also:
-
-
Method Details
-
getInstance
Get the instance of the game instance pool.- Returns:
- the instance of the game instance pool.
- Throws:
ReaException
- if the instance cannot be created.
-
setGameplayFactory
Set the gameplay factory. Use only for testing.- Parameters:
gameplayFactory
- the gameplay factory to set.
-
getGameplayFactory
AbstractGameplayFactory getGameplayFactory()Get the gameplay factory. Use only for testing.- Returns:
- the gameplay factory.
-
reset
Reset the pool to its initial state. Clears the list of games and sets the gameplay factory to a new instance. Use only for testing.- Throws:
ReaException
- if the gameplay factory cannot be created.
-
addGamesUpdateListener
Add a listener to the games update event.- Parameters:
listener
- of events
-
getAvailableGames
Get the names available games. These are the names of the gameplays available in the gameplay factory.- Returns:
- set with available games' names.
-
createGameInstance
Create a game instance with the given name. and add it to the pool. TherecycleGameInstances()
method is called to remove old game instances. Changes in the created game are broadcasted to allGamesUpdateEvent
listeners.- Parameters:
gameName
- the name of the game.- Returns:
- the game instance.
-
deleteGameInstance
Delete a game instance from the pool, if it can be deleted. Changes in the list of games about to start are broadcasted to allGamesUpdateEvent
listeners.- Parameters:
gameInstance
- the game instance to delete.- See Also:
-
getGameInstances
Get all the game instances.- Returns:
- the game instances.
-
broadcastGamesUpdate
void broadcastGamesUpdate()Broadcast an update in the list of games about to start. -
getGamesInstancesAboutToStart
List<GameInstance> getGamesInstancesAboutToStart()Get the games instances about to start.- Returns:
- the instances of games about to start.
-
getKeepAfterEnd
static long getKeepAfterEnd()Get the time in milliseconds to keep a game instance after it has ended. By default, it is 5 minutes.- Returns:
- the time to keep a game instance after it has ended.
-
setKeepAfterEnd
static void setKeepAfterEnd(long keepAfterEnd) Set the time in milliseconds to keep a game instance after it has ended. By default, it is 5 minutes.- Parameters:
keepAfterEnd
- the time to keep a game instance after it has ended.
-
recycleGameInstances
public void recycleGameInstances()Remove game instances that have ended more thankeepAfterEnd
milliseconds ago.
-