com.sun.sgs.example.hack.server

Class Lobby

    • Method Detail

      • getInstance

        public static Lobby getInstance(GameChangeManager gcm)
        Provides access to the single instance of Lobby. If the lobby hasn't already been created, then a new instance is created and added as a registered ManagedObject. If the lobby already exists then nothing new is created.

        This method implements the pattern described in the programmer's notes document, so that it's safe against multiple simultaneous accesses when the lobby doesn't already exist. In practice, this isn't actually a concern in this app, because this method is never called by more than once party. Still, it's good defensive programming to protect against future models that may change our current access assumptions.

        Parameters:
        gcm - the manager we'll notify when lobby membership counts change
        Returns:
        the single Lobby
      • join

        public MessageHandler join(Player player)
        Joins a player to the lobby. This is done when a player first connects, and whenever they leave an active game.
        Specified by:
        join in interface Game
        Parameters:
        player - the Player joining the lobby
        Returns:
        the MessageHandler that will process the provided player's messages
      • leave

        public void leave(Player player)
        Removes the player from the lobby.
        Specified by:
        leave in interface Game
        Parameters:
        player - the Player leaving the lobby
      • getName

        public String getName()
        Returns the name of the lobby. This is also specified by the local field IDENTIFIER.
        Specified by:
        getName in interface Game
        Returns:
        the name
      • numPlayers

        public int numPlayers()
        Returns the number of players currently in the lobby.
        Specified by:
        numPlayers in interface Game
        Returns:
        the number of players in the lobby
      • gameAdded

        public void gameAdded(Collection<String> added)
        Notifies the listener that some games were added to the app.
        Specified by:
        gameAdded in interface GameChangeListener
        Parameters:
        games - the games that were added
      • gameRemoved

        public void gameRemoved(Collection<String> removed)
        Notifies the listener that some games were removed from the app.
        Specified by:
        gameRemoved in interface GameChangeListener
        Parameters:
        games - the games that were removed
      • membershipChanged

        public void membershipChanged(Collection<GameMembershipDetail> details)
        Called when it's time to send out membership change messages. This method will broadcast changes to all current members of the lobby.
        Specified by:
        membershipChanged in interface GameChangeListener
        Parameters:
        details - the membership details

Copyright © 2013. All Rights Reserved.