mirror of
https://github.com/correl/mage.git
synced 2024-11-25 03:00:11 +00:00
* Fixed a problem that the table health check removed tables that were just created by adding 30 seconds check stop after table start to prevent checking while server still is initializing the table start.
This commit is contained in:
parent
878ba90625
commit
ee59ec80e2
2 changed files with 18 additions and 22 deletions
|
@ -24,10 +24,17 @@
|
||||||
* The views and conclusions contained in the software and documentation are those of the
|
* The views and conclusions contained in the software and documentation are those of the
|
||||||
* authors and should not be interpreted as representing official policies, either expressed
|
* authors and should not be interpreted as representing official policies, either expressed
|
||||||
* or implied, of BetaSteward_at_googlemail.com.
|
* or implied, of BetaSteward_at_googlemail.com.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package mage.server;
|
package mage.server;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
import mage.cards.decks.DeckCardLists;
|
import mage.cards.decks.DeckCardLists;
|
||||||
import mage.constants.TableState;
|
import mage.constants.TableState;
|
||||||
|
@ -47,15 +54,6 @@ import mage.server.game.GamesRoomManager;
|
||||||
import mage.server.util.ThreadExecutor;
|
import mage.server.util.ThreadExecutor;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
|
@ -64,7 +62,6 @@ public enum TableManager {
|
||||||
protected final ScheduledExecutorService expireExecutor = Executors.newSingleThreadScheduledExecutor();
|
protected final ScheduledExecutorService expireExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
|
||||||
// protected static ScheduledExecutorService expireExecutor = ThreadExecutor.getInstance().getExpireExecutor();
|
// protected static ScheduledExecutorService expireExecutor = ThreadExecutor.getInstance().getExpireExecutor();
|
||||||
|
|
||||||
private final Logger logger = Logger.getLogger(TableManager.class);
|
private final Logger logger = Logger.getLogger(TableManager.class);
|
||||||
private static final DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
|
private static final DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
|
||||||
|
|
||||||
|
@ -78,7 +75,6 @@ public enum TableManager {
|
||||||
*/
|
*/
|
||||||
private static final int EXPIRE_CHECK_PERIOD = 10;
|
private static final int EXPIRE_CHECK_PERIOD = 10;
|
||||||
|
|
||||||
|
|
||||||
TableManager() {
|
TableManager() {
|
||||||
expireExecutor.scheduleAtFixedRate(() -> {
|
expireExecutor.scheduleAtFixedRate(() -> {
|
||||||
try {
|
try {
|
||||||
|
@ -227,7 +223,7 @@ public enum TableManager {
|
||||||
/**
|
/**
|
||||||
* Starts the Match from a non tournament table
|
* Starts the Match from a non tournament table
|
||||||
*
|
*
|
||||||
* @param userId table owner
|
* @param userId table owner
|
||||||
* @param roomId
|
* @param roomId
|
||||||
* @param tableId
|
* @param tableId
|
||||||
*/
|
*/
|
||||||
|
@ -277,7 +273,6 @@ public enum TableManager {
|
||||||
// }
|
// }
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public void endGame(UUID tableId) {
|
public void endGame(UUID tableId) {
|
||||||
if (controllers.containsKey(tableId)) {
|
if (controllers.containsKey(tableId)) {
|
||||||
if (controllers.get(tableId).endGameAndStartNextGame()) {
|
if (controllers.get(tableId).endGameAndStartNextGame()) {
|
||||||
|
@ -326,7 +321,7 @@ public enum TableManager {
|
||||||
TableController tableController = controllers.get(tableId);
|
TableController tableController = controllers.get(tableId);
|
||||||
if (tableController != null) {
|
if (tableController != null) {
|
||||||
controllers.remove(tableId);
|
controllers.remove(tableId);
|
||||||
tableController.cleanUp(); // deletes the table chat and references to users
|
tableController.cleanUp(); // deletes the table chat and references to users
|
||||||
|
|
||||||
Table table = tables.get(tableId);
|
Table table = tables.get(tableId);
|
||||||
tables.remove(tableId);
|
tables.remove(tableId);
|
||||||
|
@ -390,12 +385,13 @@ public enum TableManager {
|
||||||
List<Table> tableCopy = new ArrayList<>(tables.values());
|
List<Table> tableCopy = new ArrayList<>(tables.values());
|
||||||
for (Table table : tableCopy) {
|
for (Table table : tableCopy) {
|
||||||
try {
|
try {
|
||||||
if (table.getState() != TableState.FINISHED) {
|
if (table.getState() != TableState.FINISHED
|
||||||
|
&& ((System.currentTimeMillis() - table.getStartTime().getTime()) / 1000) > 30) { // remove only if table started longer than 30 seconds ago
|
||||||
// remove tables and games not valid anymore
|
// remove tables and games not valid anymore
|
||||||
logger.debug(table.getId() + " [" + table.getName() + "] " + formatter.format(table.getStartTime() == null ? table.getCreateTime() : table.getCreateTime()) + " (" + table.getState().toString() + ") " + (table.isTournament() ? "- Tournament" : ""));
|
logger.debug(table.getId() + " [" + table.getName() + "] " + formatter.format(table.getStartTime() == null ? table.getCreateTime() : table.getCreateTime()) + " (" + table.getState().toString() + ") " + (table.isTournament() ? "- Tournament" : ""));
|
||||||
getController(table.getId()).ifPresent(tableController -> {
|
getController(table.getId()).ifPresent(tableController -> {
|
||||||
if ((table.isTournament() && !tableController.isTournamentStillValid()) ||
|
if ((table.isTournament() && !tableController.isTournamentStillValid())
|
||||||
(!table.isTournament() && !tableController.isMatchTableStillValid())) {
|
|| (!table.isTournament() && !tableController.isMatchTableStillValid())) {
|
||||||
try {
|
try {
|
||||||
logger.warn("Removing unhealthy tableId " + table.getId());
|
logger.warn("Removing unhealthy tableId " + table.getId());
|
||||||
removeTable(table.getId());
|
removeTable(table.getId());
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
*/
|
*/
|
||||||
package mage.game;
|
package mage.game;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.*;
|
||||||
import mage.cards.decks.DeckValidator;
|
import mage.cards.decks.DeckValidator;
|
||||||
import mage.constants.TableState;
|
import mage.constants.TableState;
|
||||||
import mage.game.events.Listener;
|
import mage.game.events.Listener;
|
||||||
|
@ -38,9 +40,6 @@ import mage.game.tournament.Tournament;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.players.PlayerType;
|
import mage.players.PlayerType;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
|
@ -65,6 +64,7 @@ public class Table implements Serializable {
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface TableRecorder {
|
public interface TableRecorder {
|
||||||
|
|
||||||
void record(Table table);
|
void record(Table table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue