com.threerings.parlor.server
Class TableManager

java.lang.Object
  extended by com.threerings.parlor.server.TableManager
All Implemented Interfaces:
ParlorCodes, TableProvider, InvocationCodes, InvocationProvider

public class TableManager
extends Object
implements ParlorCodes, TableProvider

A table manager can be used by a place manager (or other entity) to take care of the management of a table matchmaking service on a particular distributed object.


Nested Class Summary
protected  class TableManager.GameListener
          Listens to all games and updates the table objects as necessary.
protected  class TableManager.UserListener
          Listens to all users who have joined a table, takes care of removing them as necessary.
 
Field Summary
protected  boolean _allowBooting
          Whether or not tables should support booting.
protected  IntMap<Table> _boidMap
          A mapping from body oid to table.
protected  DObject _dobj
          A reference to the distributed object in which we're managing tables.
protected  ChangeListener _gameListener
          A listener that prunes tables after the game dies.
protected  IntMap<Table> _goidMap
          Once a game starts, a mapping from gameOid to table.
protected  InvocationManager _invmgr
           
protected  RootDObjectManager _omgr
           
protected  ChangeListener _placeListener
          Listens for players leaving the place that contains our tables.
protected  PlaceRegistry _plreg
           
protected  Class<? extends Table> _tableClass
          The class of table we instantiate.
protected  IntMap<Table> _tables
          The table of pending tables.
protected  TableLobbyObject _tlobj
          A reference to our distributed object casted to a table lobby object.
protected  ChangeListener _userListener
          A listener that removes users from tables when they're no longer able to play.
 
Fields inherited from interface com.threerings.parlor.data.ParlorCodes
ALREADY_AT_TABLE, BANNED_FROM_TABLE, GAME_ALREADY_STARTED, INVALID_TABLE_POSITION, INVITATION_ACCEPTED, INVITATION_COUNTERED, INVITATION_REFUSED, INVITEE_NOT_ONLINE, MUST_BE_CREATOR, NO_SELF_BOOT, NO_SUCH_TABLE, NOT_AT_TABLE, PARLOR_GROUP, TABLE_POSITION_OCCUPIED
 
Fields inherited from interface com.threerings.presents.data.InvocationCodes
ACCESS_DENIED, E_ACCESS_DENIED, E_INTERNAL_ERROR, GLOBAL_GROUP, INTERNAL_ERROR
 
Constructor Summary
TableManager(RootDObjectManager omgr, InvocationManager invmgr, PlaceRegistry plreg, DObject tableObject)
          Creates a table manager that will manage tables in the supplied distributed object (which must implement TableLobbyObject.
 
Method Summary
protected  void addTableToLobby(Table table)
          Add the table to the lobby object, after it has already been validated as being publishable.
protected  void bodyLeft(int bodyOid)
          Called when a body is known to have left either the room that contains our tables or logged off of the server.
 void bootPlayer(ClientObject caller, int tableId, Name target, InvocationService.InvocationListener listener)
          Handles a TableService.bootPlayer(int, com.threerings.util.Name, com.threerings.presents.client.InvocationService.InvocationListener) request.
protected  GameConfig createConfig(Table table)
          This method should validate that the (client provided) configuration in the supplied Table object is valid and fill in any extra information that is the purview of the server.
protected  int createGame(Table table)
          Called when we're ready to create a game (either an invitation has been accepted or a table is ready to start.
protected  GameManager createGameManager(GameConfig config)
          Creates a GameManager using the supplied config.
 Table createTable(BodyObject creator, TableConfig tableConfig, GameConfig config)
          Creates a table for the specified creator and returns said table.
 void createTable(ClientObject caller, TableConfig tableConfig, GameConfig config, InvocationService.ResultListener listener)
          Handles a TableService.createTable(com.threerings.parlor.data.TableConfig, com.threerings.parlor.game.data.GameConfig, com.threerings.presents.client.InvocationService.ResultListener) request.
protected  void gameCreated(Table table, GameObject gameobj, GameManager gmgr)
          Called when our game has been created, we take this opportunity to clean up the table and transition it to "in play" mode.
 int getTableCount()
          Returns the number of tables being managed currently.
 void joinTable(ClientObject caller, int tableId, int position, InvocationService.InvocationListener listener)
          Handles a TableService.joinTable(int, int, com.threerings.presents.client.InvocationService.InvocationListener) request.
 void leaveTable(ClientObject caller, int tableId, InvocationService.InvocationListener listener)
          Handles a TableService.leaveTable(int, com.threerings.presents.client.InvocationService.InvocationListener) request.
protected  void notePlayerAdded(Table table, BodyObject body)
          Called when a player is added to a table to set up our mappings.
protected  Table notePlayerRemoved(int playerOid)
          Called when a player leaves the room and we're not sure if the user is still online.
protected  Table notePlayerRemoved(int playerOid, BodyObject body)
          Called when a player leaves a table to clear our mappings.
protected  void purgeTable(Table table)
          Removes the table from all of our internal tables and from its lobby's distributed object.
protected  void removeTableFromLobby(Integer tableId)
          Safely remove the table from the lobby.
 void setAllowBooting(boolean allowBooting)
          Allow a player in the first position of a table to boot others.
 void setTableClass(Class<? extends Table> tableClass)
          Set the subclass of Table that this instance should generate.
 void setTableObject(DObject tableObject)
          Initialize the TableLobbyObject.
protected  boolean shouldPublish(Table table)
          Derived classes can override this method to filter certain tables from being published in the lobby object.
 void shutdown()
          This must be called when the table manager is no longer needed.
 void startTableNow(ClientObject caller, int tableId, InvocationService.InvocationListener listener)
          Handles a TableService.startTableNow(int, com.threerings.presents.client.InvocationService.InvocationListener) request.
protected  void tableCreated(Table table)
          Publishes a newly created table to the lobby object.
protected  void unmapTable(int gameOid)
          Called when a game created from a table managed by this table manager was destroyed.
protected  void updateOccupants(int gameOid)
          Called when the occupants in a game change: publishes new info.
protected  void updateTableInLobby(Table table)
          Safely update the table in the lobby, if it's there.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_placeListener

protected ChangeListener _placeListener
Listens for players leaving the place that contains our tables.


_dobj

protected DObject _dobj
A reference to the distributed object in which we're managing tables.


_tlobj

protected TableLobbyObject _tlobj
A reference to our distributed object casted to a table lobby object.


_tableClass

protected Class<? extends Table> _tableClass
The class of table we instantiate.


_tables

protected IntMap<Table> _tables
The table of pending tables.


_boidMap

protected IntMap<Table> _boidMap
A mapping from body oid to table.


_goidMap

protected IntMap<Table> _goidMap
Once a game starts, a mapping from gameOid to table.


_gameListener

protected ChangeListener _gameListener
A listener that prunes tables after the game dies.


_userListener

protected ChangeListener _userListener
A listener that removes users from tables when they're no longer able to play.


_allowBooting

protected boolean _allowBooting
Whether or not tables should support booting.


_omgr

protected RootDObjectManager _omgr

_invmgr

protected InvocationManager _invmgr

_plreg

protected PlaceRegistry _plreg
Constructor Detail

TableManager

public TableManager(RootDObjectManager omgr,
                    InvocationManager invmgr,
                    PlaceRegistry plreg,
                    DObject tableObject)
Creates a table manager that will manage tables in the supplied distributed object (which must implement TableLobbyObject.

Method Detail

setTableObject

public void setTableObject(DObject tableObject)
Initialize the TableLobbyObject. Do not call this more than once.


getTableCount

public int getTableCount()
Returns the number of tables being managed currently.


shutdown

public void shutdown()
This must be called when the table manager is no longer needed.


setTableClass

public void setTableClass(Class<? extends Table> tableClass)
Set the subclass of Table that this instance should generate.


setAllowBooting

public void setAllowBooting(boolean allowBooting)
Allow a player in the first position of a table to boot others.


createTable

public Table createTable(BodyObject creator,
                         TableConfig tableConfig,
                         GameConfig config)
                  throws InvocationException
Creates a table for the specified creator and returns said table.

Throws:
InvocationException - thrown if the table could not be created for any reason.

createTable

public void createTable(ClientObject caller,
                        TableConfig tableConfig,
                        GameConfig config,
                        InvocationService.ResultListener listener)
                 throws InvocationException
Description copied from interface: TableProvider
Handles a TableService.createTable(com.threerings.parlor.data.TableConfig, com.threerings.parlor.game.data.GameConfig, com.threerings.presents.client.InvocationService.ResultListener) request.

Specified by:
createTable in interface TableProvider
Throws:
InvocationException

joinTable

public void joinTable(ClientObject caller,
                      int tableId,
                      int position,
                      InvocationService.InvocationListener listener)
               throws InvocationException
Description copied from interface: TableProvider
Handles a TableService.joinTable(int, int, com.threerings.presents.client.InvocationService.InvocationListener) request.

Specified by:
joinTable in interface TableProvider
Throws:
InvocationException

leaveTable

public void leaveTable(ClientObject caller,
                       int tableId,
                       InvocationService.InvocationListener listener)
                throws InvocationException
Description copied from interface: TableProvider
Handles a TableService.leaveTable(int, com.threerings.presents.client.InvocationService.InvocationListener) request.

Specified by:
leaveTable in interface TableProvider
Throws:
InvocationException

startTableNow

public void startTableNow(ClientObject caller,
                          int tableId,
                          InvocationService.InvocationListener listener)
                   throws InvocationException
Description copied from interface: TableProvider
Handles a TableService.startTableNow(int, com.threerings.presents.client.InvocationService.InvocationListener) request.

Specified by:
startTableNow in interface TableProvider
Throws:
InvocationException

bootPlayer

public void bootPlayer(ClientObject caller,
                       int tableId,
                       Name target,
                       InvocationService.InvocationListener listener)
                throws InvocationException
Description copied from interface: TableProvider
Handles a TableService.bootPlayer(int, com.threerings.util.Name, com.threerings.presents.client.InvocationService.InvocationListener) request.

Specified by:
bootPlayer in interface TableProvider
Throws:
InvocationException

tableCreated

protected void tableCreated(Table table)
Publishes a newly created table to the lobby object. Can also be overridden by custom managers that want to react to table creation.


purgeTable

protected void purgeTable(Table table)
Removes the table from all of our internal tables and from its lobby's distributed object.


notePlayerAdded

protected void notePlayerAdded(Table table,
                               BodyObject body)
Called when a player is added to a table to set up our mappings.


notePlayerRemoved

protected final Table notePlayerRemoved(int playerOid)
Called when a player leaves the room and we're not sure if the user is still online.


notePlayerRemoved

protected Table notePlayerRemoved(int playerOid,
                                  BodyObject body)
Called when a player leaves a table to clear our mappings.

Parameters:
body - will be non-null if the user is still online.

createGame

protected int createGame(Table table)
                  throws InvocationException
Called when we're ready to create a game (either an invitation has been accepted or a table is ready to start. If there is a problem creating the game manager, it should be reported in the logs.

Returns:
the oid of the newly-created game.
Throws:
InvocationException

createConfig

protected GameConfig createConfig(Table table)
This method should validate that the (client provided) configuration in the supplied Table object is valid and fill in any extra information that is the purview of the server.


createGameManager

protected GameManager createGameManager(GameConfig config)
                                 throws InstantiationException,
                                        InvocationException
Creates a GameManager using the supplied config. Used by createGame(com.threerings.parlor.data.Table), but extracted into a method to allow customization of this process.

Throws:
InstantiationException
InvocationException

gameCreated

protected void gameCreated(Table table,
                           GameObject gameobj,
                           GameManager gmgr)
Called when our game has been created, we take this opportunity to clean up the table and transition it to "in play" mode.


unmapTable

protected void unmapTable(int gameOid)
Called when a game created from a table managed by this table manager was destroyed. We remove the associated table.


updateOccupants

protected void updateOccupants(int gameOid)
Called when the occupants in a game change: publishes new info.


bodyLeft

protected void bodyLeft(int bodyOid)
Called when a body is known to have left either the room that contains our tables or logged off of the server.


shouldPublish

protected boolean shouldPublish(Table table)
Derived classes can override this method to filter certain tables from being published in the lobby object. Such tables are probably unwatchable and unjoinable and thus just take up space in the lobby object for no good reason. This will be checked when the table is first created and when the table's game transitions to in-play.


addTableToLobby

protected void addTableToLobby(Table table)
Add the table to the lobby object, after it has already been validated as being publishable.


updateTableInLobby

protected void updateTableInLobby(Table table)
Safely update the table in the lobby, if it's there.


removeTableFromLobby

protected void removeTableFromLobby(Integer tableId)
Safely remove the table from the lobby. Broken out for overriding.