Package rea

Class Manager

java.lang.Object
rea.Manager

@Service public class Manager extends Object
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 Details

    • KEEP_AFTER_END

      static final long KEEP_AFTER_END
      Default time in milliseconds to keep a game instance after it has ended.
      See Also:
  • Method Details

    • getInstance

      public static Manager getInstance() throws ReaException
      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

      void setGameplayFactory(AbstractGameplayFactory gameplayFactory)
      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

      void reset() throws ReaException
      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

      public void addGamesUpdateListener(UpdateListener<GamesUpdateEvent> listener)
      Add a listener to the games update event.
      Parameters:
      listener - of events
    • getAvailableGames

      public Set<String> 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

      public GameInstance createGameInstance(String gameName)
      Create a game instance with the given name. and add it to the pool. The recycleGameInstances() method is called to remove old game instances. Changes in the created game are broadcasted to all GamesUpdateEvent listeners.
      Parameters:
      gameName - the name of the game.
      Returns:
      the game instance.
    • deleteGameInstance

      public void deleteGameInstance(GameInstance gameInstance)
      Delete a game instance from the pool, if it can be deleted. Changes in the list of games about to start are broadcasted to all GamesUpdateEvent listeners.
      Parameters:
      gameInstance - the game instance to delete.
      See Also:
    • getGameInstances

      public List<GameInstance> 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 than keepAfterEnd milliseconds ago.