Search in sources :

Example 11 with Table

use of mage.game.Table in project mage by magefree.

the class TableManagerImpl method checkTableHealthState.

private void checkTableHealthState() {
    if (logger.isDebugEnabled()) {
        debugServerState();
    }
    logger.debug("TABLE HEALTH CHECK");
    for (Table table : getTables()) {
        try {
            if (table.getState() != TableState.FINISHED && ((System.currentTimeMillis() - table.getStartTime().getTime()) / 1000) > 30) {
                // removeUserFromAllTablesAndChat only if table started longer than 30 seconds ago
                // removeUserFromAllTablesAndChat tables and games not valid anymore
                logger.debug(table.getId() + " [" + table.getName() + "] " + formatter.format(table.getStartTime() != null ? table.getStartTime() : table.getCreateTime()) + " (" + table.getState().toString() + ") " + (table.isTournament() ? "- Tournament" : ""));
                getController(table.getId()).ifPresent(tableController -> {
                    if ((table.isTournament() && !tableController.isTournamentStillValid()) || (!table.isTournament() && !tableController.isMatchTableStillValid())) {
                        try {
                            logger.warn("Removing unhealthy tableId " + table.getId());
                            removeTable(table.getId());
                        } catch (Exception e) {
                            logger.error(e);
                        }
                    }
                });
            }
        } catch (Exception ex) {
            logger.debug("Table Health check error tableId: " + table.getId());
            logger.debug(Arrays.toString(ex.getStackTrace()));
        }
    }
    logger.debug("TABLE HEALTH CHECK - END");
}
Also used : Table(mage.game.Table) MageException(mage.MageException) GameException(mage.game.GameException)

Example 12 with Table

use of mage.game.Table in project mage by magefree.

the class TableManagerImpl method getTables.

@Override
public Collection<Table> getTables() {
    Collection<Table> newTables = new ArrayList<>();
    final Lock r = tablesLock.readLock();
    r.lock();
    try {
        newTables.addAll(tables.values());
    } finally {
        r.unlock();
    }
    return newTables;
}
Also used : Table(mage.game.Table) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

Table (mage.game.Table)12 GameException (mage.game.GameException)4 MageException (mage.MageException)3 TournamentPlayer (mage.game.tournament.TournamentPlayer)3 TableView (mage.view.TableView)3 Lock (java.util.concurrent.locks.Lock)2 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 TableManager (mage.server.managers.TableManager)2 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Game (mage.game.Game)1 Match (mage.game.match.Match)1 MageVersionException (mage.remote.MageVersionException)1 User (mage.server.User)1 DraftSession (mage.server.draft.DraftSession)1 GameSessionPlayer (mage.server.game.GameSessionPlayer)1 MatchView (mage.view.MatchView)1 RoomUsersView (mage.view.RoomUsersView)1 UsersView (mage.view.UsersView)1