From ddeb51984806349016030971344c03c0f2255232 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 10 Sep 2014 17:14:36 +0200 Subject: [PATCH] * Some changes to logging / server handling. --- .../java/mage/server/TableController.java | 10 +++++++--- .../main/java/mage/server/TableManager.java | 13 +++++-------- .../src/main/java/mage/server/User.java | 12 ++++++------ .../main/java/mage/server/UserManager.java | 2 +- .../java/mage/server/util/ThreadExecutor.java | 19 +++++++++++++++++++ 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/Mage.Server/src/main/java/mage/server/TableController.java b/Mage.Server/src/main/java/mage/server/TableController.java index c658d7074a..78d153316b 100644 --- a/Mage.Server/src/main/java/mage/server/TableController.java +++ b/Mage.Server/src/main/java/mage/server/TableController.java @@ -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 entry: userPlayerMap.entrySet()) { + User user = UserManager.getInstance().getUser(entry.getKey()); + if (user != null) { + user.removeTable(entry.getValue()); + } + } ChatManager.getInstance().destroyChatSession(chatId); } diff --git a/Mage.Server/src/main/java/mage/server/TableManager.java b/Mage.Server/src/main/java/mage/server/TableManager.java index 68a1da1265..0f42b66ddf 100644 --- a/Mage.Server/src/main/java/mage/server/TableManager.java +++ b/Mage.Server/src/main/java/mage/server/TableManager.java @@ -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); diff --git a/Mage.Server/src/main/java/mage/server/User.java b/Mage.Server/src/main/java/mage/server/User.java index 0c9806d075..639e44e13f 100644 --- a/Mage.Server/src/main/java/mage/server/User.java +++ b/Mage.Server/src/main/java/mage/server/User.java @@ -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 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); } diff --git a/Mage.Server/src/main/java/mage/server/UserManager.java b/Mage.Server/src/main/java/mage/server/UserManager.java index dad2fc575f..1a64bb93e0 100644 --- a/Mage.Server/src/main/java/mage/server/UserManager.java +++ b/Mage.Server/src/main/java/mage/server/UserManager.java @@ -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 { diff --git a/Mage.Server/src/main/java/mage/server/util/ThreadExecutor.java b/Mage.Server/src/main/java/mage/server/util/ThreadExecutor.java index 37eb7df4fc..b228e20e13 100644 --- a/Mage.Server/src/main/java/mage/server/util/ThreadExecutor.java +++ b/Mage.Server/src/main/java/mage/server/util/ThreadExecutor.java @@ -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; + } +} \ No newline at end of file