Improved sceduled logic to remove bugged tables. Reactivated logic to show the list of the last finished 50 matches (no replay possible).

This commit is contained in:
LevelX2 2013-03-27 16:58:34 +01:00
parent 30b738b3ad
commit 7014b28797
4 changed files with 44 additions and 17 deletions

View file

@ -99,8 +99,7 @@ public class TablesPanel extends javax.swing.JPanel {
initComponents();
tableModel.setSession(session);
// disable replays
chkShowCompleted.setVisible(false);
chkShowCompleted.setVisible(true);
tableTables.createDefaultColumnsFromModel();
chatPanel.useExtendedView(ChatPanel.VIEW_MODE.NONE);
@ -167,7 +166,8 @@ public class TablesPanel extends javax.swing.JPanel {
session.watchTable(roomId, tableId);
} else if (state.equals("Replay")) {
logger.info("Replaying game " + gameId);
session.replayGame(gameId);
// no replay because of memory leaks
// session.replayGame(gameId);
}
}
};
@ -178,7 +178,7 @@ public class TablesPanel extends javax.swing.JPanel {
public void actionPerformed(ActionEvent e)
{
int modelRow = Integer.valueOf( e.getActionCommand() );
List<UUID> games = (List<UUID>)matchesModel.getValueAt(modelRow, 7);
List<UUID> games = (List<UUID>)matchesModel.getValueAt(modelRow, 6);
if (games.size() == 1) {
session.replayGame(games.get(0));
}
@ -659,7 +659,7 @@ class TableTableModel extends AbstractTableModel {
if (session != null && owner.equals(session.getUserName())) {
return "Remove";
}
return "Replay";
return "None";
default:
return "";
}
@ -828,7 +828,7 @@ class MatchesTableModel extends AbstractTableModel {
case 4:
return matches[arg0].getResult();
case 5:
return "Replay";
return "None";
case 6:
return matches[arg0].getGames();
}

View file

@ -420,8 +420,10 @@ public class TableController {
UUID choosingPlayerId = match.getChooser();
match.endGame();
table.endGame();
//if (!match.getGame().isSimulation())
//GameManager.getInstance().saveGame(match.getGame().getId());
// Saving of games caused memory leaks - so save is deactivated
// if (!match.getGame().isSimulation()) {
// GameManager.getInstance().saveGame(match.getGame().getId());
// }
GameManager.getInstance().removeGame(match.getGame().getId());
try {
if (!match.isMatchOver()) {
@ -432,10 +434,7 @@ public class TableController {
startGame(choosingPlayerId);
}
else {
GamesRoomManager.getInstance().removeTable(table.getId());
match.getGames().clear();
match = null;
table = null;
}
} catch (GameException ex) {
logger.fatal(null, ex);

View file

@ -47,6 +47,8 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import mage.Constants;
import mage.game.match.MatchPlayer;
/**
*
@ -68,7 +70,7 @@ public class TableManager {
* In minutes.
*/
private static final int EXPIRE_CHECK_PERIOD = 10;
/**
* This parameters defines when table can be counted as expired.
* Uses EXPIRE_TIME_UNIT_VALUE as unit of measurement.
@ -274,10 +276,27 @@ public class TableManager {
Date now = new Date();
List<UUID> toRemove = new ArrayList<UUID>();
for (Table table : tables.values()) {
long diff = (now.getTime() - table.getCreateTime().getTime()) / EXPIRE_TIME_UNIT_VALUE;
if (diff >= EXPIRE_TIME) {
logger.info("Table expired: id = " + table.getId() + ", created_by=" + table.getControllerName() + ". Removing...");
toRemove.add(table.getId());
if (!table.getState().equals(Constants.TableState.FINISHED)) {
// remove all tables created more than expire_time ago
long diff = (now.getTime() - table.getCreateTime().getTime()) / EXPIRE_TIME_UNIT_VALUE;
if (diff >= EXPIRE_TIME) {
logger.info("Table expired: id = " + table.getId() + ", created_by=" + table.getControllerName() + ". Removing...");
toRemove.add(table.getId());
}
// remove immediately non tournament tables with no human players
else if (!table.isTournament()) {
boolean canBeRemoved = true;
for (MatchPlayer matchPlayer :table.getMatch().getPlayers()) {
Player player = matchPlayer.getPlayer();
if (player != null && player.isHuman()) {
canBeRemoved = false;
}
}
if (canBeRemoved) {
logger.info("Table with no human player: id = " + table.getId() + ", created_by=" + table.getControllerName() + ". Removing...");
toRemove.add(table.getId());
}
}
}
}
for (UUID tableId : toRemove) {

View file

@ -43,6 +43,7 @@ import mage.MageException;
import mage.cards.decks.DeckCardLists;
import mage.game.GameException;
import mage.game.Table;
import mage.game.match.Match;
import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentOptions;
import mage.server.RoomImpl;
@ -88,13 +89,21 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
ArrayList<MatchView> matchList = new ArrayList<MatchView>();
List<Table> t = new ArrayList<Table>(tables.values());
Collections.sort(t, new TimestampSorter());
Collections.reverse(t);
for (Table table: t) {
if (table.getState() != TableState.FINISHED) {
tableList.add(new TableView(table));
}
else if (matchList.size() < 50) {
matchList.add(new MatchView(table.getMatch()));
}
} else {
// more since 50 matches finished since this match so remobe it
if (table.isTournament()) {
// is this possible?
// Any special action needed?
}
this.removeTable(table.getId());
}
}
tableView = tableList;
matchView = matchList;