Firebase 1.7.2 is just about to be released and even though this is a small release I figured I can go through some of the additions.
Asynchronous Messaging
Want to start your own thread from within a Game and then send GameActions to clients from that thread, then this is for you. Some processes might take a lot of time and instead of blocking execution of the game if often makes sense to fork off the process to a separate thread. Historically you had to wrap this in your own Service but the new provided Router Service will provide this functionality for you.
Getting the Router Service from either the Service Registry or Guice as below (read more about looking up services).
Service Registry:
RouterService router = serviceRegistry.getServiceInstance(RouterService.class);
Guice:
@Service RouterService router;
How to use in a separate thread (incomplete code example) started from playerJoined():
public void playerJoined(Table table, GenericPlayer player) { Worker worker = new Worker(table.getId(), player.getPlayerId()); executor.execute(worker); ... }
private class Worker implements Runnable { private final int tableId; private final int playerId; public Worker(int tableId, int playerId) { this.tableId = tableId; this.playerId = playerId; } public void run() { Thread.sleep(3000); TableChatAction chat = new TableChatAction(playerId, tableId, "Callback from async thread"); router.getRouter().dispatchToPlayer(playerId, chat); } }
Mapped Diagnostic Context
We have added MDC to the server.log and error.log in the default Log4J configuration. MDC allows you to put diagnostic context in the log entries. Read here for more information.
The context added are;
- Table ID – Mapped by tableid.
- Tournament ID – Mapped by tournid.
- Player ID – Mapped by playerid.
Context attributes are added in Log4J Conversion Pattern by wrapping them in %X{…}. Thus, the default Log4J in 1.7.2 looks like:
<param name="ConversionPattern" value="%d %-5p - T[%X{tableid}] P[%X{playerid}] M[%X{tournid}] %t %c{4} - %m%n"/>
In the log file(s) it will look like:
2011-02-16 15:17:32,932 INFO - T[2] P[23423] M[] ReceivingGameEventDaemon-11 cubeia.games.poker.PokerTableListener - Fork off worker tread
Where T = Table ID, P = Player ID and M = Tournament ID.
Lobby Statistics
We have included more and better statistics for the Lobby through JMX. The dumpSubscriptionInfoToLog now writes on INFO level for instance (you can now also get it returned as String through JMX) and you can inspect the number of subscribers and packets held by the system. You can also get information on which player subscribes to what node in the Lobby. This makes trouble shooting subscription issues much easier.
Be aware though that the Operations exposed through JMX for the Lobby can be very resource intense if you have a lot of players connected.
Lobby Fitness Improved
Some long term memory leaks that would occur during certain circumstances in the lobby have also been fixed.