* Some changes to logging / server handling.

This commit is contained in:
LevelX2 2014-09-10 17:14:36 +02:00
parent e8f9c0822f
commit ddeb519848
5 changed files with 38 additions and 18 deletions

View file

@ -725,9 +725,7 @@ public class TableController {
user.showUserMessage("Match info", sb.toString());
}
// remove table from user - table manager holds table for display of finished matches
if (!table.isTournamentSubTable()) {
user.removeTable(entry.getValue());
}
user.removeTable(entry.getValue());
}
}
}
@ -870,6 +868,12 @@ public class TableController {
}
void cleanUp() {
for(Map.Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
User user = UserManager.getInstance().getUser(entry.getKey());
if (user != null) {
user.removeTable(entry.getValue());
}
}
ChatManager.getInstance().destroyChatSession(chatId);
}

View file

@ -333,17 +333,14 @@ public class TableManager {
}
public void removeTable(UUID tableId) {
if (tables.containsKey(tableId)) {
TableController tableController = controllers.get(tableId);
if (tableController != null) {
controllers.remove(tableId);
tableController.cleanUp();
}
TableController tableController = controllers.get(tableId);
if (tableController != null) {
controllers.remove(tableId);
tableController.cleanUp(); // deletes the table chat and references to users
Table table = tables.get(tableId);
tables.remove(tableId);
// If table is not finished, the table has to be removed completly because it's not a normal state (if finished it will be removed in GamesRoomImpl.Update())
if (!table.getState().equals(TableState.FINISHED)) {
GamesRoomManager.getInstance().removeTable(tableId);

View file

@ -333,26 +333,26 @@ public class User {
sideboarding.remove(tableId);
}
public void kill(DisconnectReason reason) {
logger.debug("Game sessions: " + gameSessions.size() );
public void remove(DisconnectReason reason) {
logger.debug("REMOVE " + getName() + " Game sessions: " + gameSessions.size() );
for (GameSession gameSession: gameSessions.values()) {
logger.debug("-- kill game session of gameId: " + gameSession.getGameId() );
gameSession.kill();
}
logger.debug("Draft sessions " + draftSessions.size());
logger.debug("REMOVE " + getName() + " Draft sessions " + draftSessions.size());
for (DraftSession draftSession: draftSessions.values()) {
draftSession.setKilled();
}
logger.debug("Tournament sessions " + tournamentSessions.size());
logger.debug("REMOVE " + getName() + " Tournament sessions " + tournamentSessions.size());
for (TournamentSession tournamentSession: tournamentSessions.values()) {
tournamentSession.setKilled();
}
logger.debug("Tables " + tables.size());
logger.debug("REMOVE " + getName() + " Tables " + tables.size());
for (Entry<UUID, Table> entry: tables.entrySet()) {
logger.debug("-- leave tableId: " + entry.getValue().getId());
TableManager.getInstance().leaveTable(userId, entry.getValue().getId());
}
logger.debug("Chat remove user");
logger.debug("REMOVE " + getName() + " Chats ");
ChatManager.getInstance().removeUser(userId, reason);
}

View file

@ -136,7 +136,7 @@ public class UserManager {
User user = users.get(userId);
if (user != null) {
logger.debug("User " + user.getName() + " will be removed (" + reason.toString() + ") userId: " + userId);
user.kill(reason);
user.remove(reason);
users.remove(userId);
logger.debug("User " + user.getName() + " removed");
} else {

View file

@ -31,6 +31,7 @@ package mage.server.util;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@ -55,10 +56,13 @@ public class ThreadExecutor {
static {
((ThreadPoolExecutor)callExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
((ThreadPoolExecutor)callExecutor).allowCoreThreadTimeOut(true);
((ThreadPoolExecutor)callExecutor).setThreadFactory(new XMageThreadFactory("CALL"));
((ThreadPoolExecutor)gameExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
((ThreadPoolExecutor)gameExecutor).allowCoreThreadTimeOut(true);
((ThreadPoolExecutor)callExecutor).setThreadFactory(new XMageThreadFactory("GAME"));
((ThreadPoolExecutor)timeoutExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
((ThreadPoolExecutor)timeoutExecutor).allowCoreThreadTimeOut(true);
((ThreadPoolExecutor)callExecutor).setThreadFactory(new XMageThreadFactory("TIME"));
}
private static final ThreadExecutor INSTANCE = new ThreadExecutor();
@ -82,3 +86,18 @@ public class ThreadExecutor {
}
}
class XMageThreadFactory implements ThreadFactory {
private final String prefix;
XMageThreadFactory(String prefix) {
this.prefix = prefix;
}
@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r);
thread.setName(prefix + " " + thread.getThreadGroup().getName() + "-" + thread.getId());
return thread;
}
}