Remove games from the ticker if their AI goes rogue so one game blowing up doesn't cause all games to stop ticking

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@627 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Charlie Groves
2008-06-16 06:21:52 +00:00
parent 5c4a033cdc
commit 5cc2e4b3f3
@@ -21,8 +21,12 @@
package com.threerings.parlor.game.server; package com.threerings.parlor.game.server;
import java.util.Iterator; import static com.threerings.parlor.Log.log;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.samskivert.util.Interval; import com.samskivert.util.Interval;
@@ -63,7 +67,7 @@ public class AIGameTicker extends Interval
private AIGameTicker () private AIGameTicker ()
{ {
super(CrowdServer.omgr); super(CrowdServer.omgr);
_games = new HashSet(); _games = Sets.newHashSet();
schedule(TICK_FREQUENCY, true); schedule(TICK_FREQUENCY, true);
} }
@@ -93,16 +97,30 @@ public class AIGameTicker extends Interval
/** /**
* Tick all the game AIs while on the dobj thread. * Tick all the game AIs while on the dobj thread.
*/ */
@Override
public void expired () public void expired ()
{ {
Iterator iter = _games.iterator(); List<GameManager> busted = null;
while (iter.hasNext()) { for (GameManager game : _games) {
((GameManager) iter.next()).tickAIs(); try {
game.tickAIs();
} catch (Throwable t) {
log.warning("Game AI going rogue, removing from ticker", "game", game, t);
if (busted == null) {
busted = Lists.newArrayList();
}
busted.add(game);
}
}
if (busted != null) {
for (GameManager game : busted) {
removeAIGame(game);
}
} }
} }
/** Our set of ai games. */ /** Our set of ai games. */
protected HashSet _games; protected HashSet<GameManager> _games;
/** Our single ticker for all AI games. */ /** Our single ticker for all AI games. */
protected static AIGameTicker _ticker; protected static AIGameTicker _ticker;