mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 03:22:00 -08:00
Fixed that user expired sceduled job died without reporting causing error. Handling changed so that if an exception raises it does not prevent the server to check expired user next time. (Hope this will workaround the existing nasty problem in user handling and show the error causing code sequence).
This commit is contained in:
parent
ec692902c7
commit
628cf2e018
3 changed files with 44 additions and 51 deletions
|
|
@ -321,25 +321,19 @@ public class User {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void kill(DisconnectReason reason) {
|
public void kill(DisconnectReason reason) {
|
||||||
logger.debug("kill: game sessions " + gameSessions.size());
|
|
||||||
for (GameSession gameSession: gameSessions.values()) {
|
for (GameSession gameSession: gameSessions.values()) {
|
||||||
gameSession.kill();
|
gameSession.kill();
|
||||||
}
|
}
|
||||||
logger.debug("kill: draft sessions " + draftSessions.size());
|
|
||||||
for (DraftSession draftSession: draftSessions.values()) {
|
for (DraftSession draftSession: draftSessions.values()) {
|
||||||
draftSession.setKilled();
|
draftSession.setKilled();
|
||||||
}
|
}
|
||||||
logger.debug("kill: tournament sessions " + tournamentSessions.size());
|
|
||||||
for (TournamentSession tournamentSession: tournamentSessions.values()) {
|
for (TournamentSession tournamentSession: tournamentSessions.values()) {
|
||||||
tournamentSession.setKilled();
|
tournamentSession.setKilled();
|
||||||
}
|
}
|
||||||
logger.debug("kill: tables " + tables.size());
|
|
||||||
for (Entry<UUID, Table> entry: tables.entrySet()) {
|
for (Entry<UUID, Table> entry: tables.entrySet()) {
|
||||||
TableManager.getInstance().leaveTable(userId, entry.getValue().getId());
|
TableManager.getInstance().leaveTable(userId, entry.getValue().getId());
|
||||||
}
|
}
|
||||||
logger.debug("kill: remove user from chat before");
|
|
||||||
ChatManager.getInstance().removeUser(userId, reason);
|
ChatManager.getInstance().removeUser(userId, reason);
|
||||||
logger.debug("kill: remove user from chat after");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserData(UserData userData) {
|
public void setUserData(UserData userData) {
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,11 @@ import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import mage.server.util.ThreadExecutor;
|
||||||
import mage.view.ChatMessage.MessageColor;
|
import mage.view.ChatMessage.MessageColor;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
|
@ -57,23 +59,13 @@ public class UserManager {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserManager() {
|
private static final ExecutorService callExecutor = ThreadExecutor.getInstance().getCallExecutor();
|
||||||
|
|
||||||
Thread.setDefaultUncaughtExceptionHandler(
|
private UserManager() {
|
||||||
new Thread.UncaughtExceptionHandler() {
|
|
||||||
@Override
|
|
||||||
public void uncaughtException(Thread t, Throwable e) {
|
|
||||||
System.out.println(t.getName() + ": " + e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
expireExecutor.scheduleAtFixedRate(new Runnable() {
|
expireExecutor.scheduleAtFixedRate(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
logger.debug("Check expired start");
|
|
||||||
checkExpired();
|
checkExpired();
|
||||||
logger.debug("Check expired end");
|
|
||||||
}
|
}
|
||||||
}, 60, 60, TimeUnit.SECONDS);
|
}, 60, 60, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
@ -119,8 +111,6 @@ public class UserManager {
|
||||||
if (users.containsKey(userId)) {
|
if (users.containsKey(userId)) {
|
||||||
User user = users.get(userId);
|
User user = users.get(userId);
|
||||||
user.setSessionId(""); // Session will be set again with new id if user reconnects
|
user.setSessionId(""); // Session will be set again with new id if user reconnects
|
||||||
// ChatManager.getInstance().broadcast(userId, "has lost connection", MessageColor.BLACK);
|
|
||||||
logger.info(new StringBuilder("User ").append(user.getName()).append(" has lost connection userId:").append(userId));
|
|
||||||
}
|
}
|
||||||
ChatManager.getInstance().removeUser(userId, reason);
|
ChatManager.getInstance().removeUser(userId, reason);
|
||||||
}
|
}
|
||||||
|
|
@ -158,23 +148,40 @@ public class UserManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the connection lost for more than 3 minutes, the user will be removed (within 3 minutes he can reconnect)
|
* Is the connection lost for more than 3 minutes, the user will be removed (within 3 minutes the user can reconnect)
|
||||||
*/
|
*/
|
||||||
private void checkExpired() {
|
private void checkExpired() {
|
||||||
Calendar expired = Calendar.getInstance();
|
// calling this with executer saves the sceduled job to be dying becuase of exception.
|
||||||
expired.add(Calendar.MINUTE, -3) ;
|
// Also exceptions were not reported as now with this handling
|
||||||
List<User> usersToCheck = new ArrayList<>();
|
try {
|
||||||
usersToCheck.addAll(users.values());
|
callExecutor.execute(
|
||||||
for (User user: usersToCheck) {
|
new Runnable() {
|
||||||
if (user.isExpired(expired.getTime())) {
|
@Override
|
||||||
logger.info(new StringBuilder(user.getName()).append(" session expired userId: ").append(user.getId())
|
public void run() {
|
||||||
.append(" sessionId: ").append(user.getSessionId()));
|
Calendar expired = Calendar.getInstance();
|
||||||
user.kill(User.DisconnectReason.LostConnection);
|
expired.add(Calendar.MINUTE, -3);
|
||||||
logger.debug("check Expired: Removing user");
|
List<User> usersToCheck = new ArrayList<>();
|
||||||
users.remove(user.getId());
|
usersToCheck.addAll(users.values());
|
||||||
logger.debug("check Expired: user removed");
|
for (User user : usersToCheck) {
|
||||||
}
|
if (user.isExpired(expired.getTime())) {
|
||||||
|
logger.info(new StringBuilder(user.getName()).append(": session expired userId: ").append(user.getId())
|
||||||
|
.append(" Host: ").append(user.getHost()));
|
||||||
|
user.kill(User.DisconnectReason.LostConnection);
|
||||||
|
users.remove(user.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
handleException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void handleException(Exception ex) {
|
||||||
|
if (!ex.getMessage().equals("No message")) {
|
||||||
|
logger.fatal("", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,20 +28,17 @@
|
||||||
|
|
||||||
package mage.server.game;
|
package mage.server.game;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
import mage.game.match.Match;
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.server.User;
|
import mage.server.User;
|
||||||
import mage.server.UserManager;
|
import mage.server.UserManager;
|
||||||
import mage.view.GameClientMessage;
|
import mage.view.GameClientMessage;
|
||||||
|
import mage.view.GameEndView;
|
||||||
import mage.view.GameView;
|
import mage.view.GameView;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.rmi.RemoteException;
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.game.GameState;
|
|
||||||
import mage.game.match.Match;
|
|
||||||
import mage.view.GameEndView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
|
@ -74,10 +71,10 @@ public class GameWatcher {
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
User user = UserManager.getInstance().getUser(userId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
user.fireCallback(new ClientCallback("gameUpdate", game.getId(), getGameView()));
|
user.fireCallback(new ClientCallback("gameUpdate", game.getId(), getGameView()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,11 +114,6 @@ public class GameWatcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleRemoteException(RemoteException ex) {
|
|
||||||
logger.fatal("GameWatcher error", ex);
|
|
||||||
GameManager.getInstance().kill(game.getId(), userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKilled() {
|
public void setKilled() {
|
||||||
killed = true;
|
killed = true;
|
||||||
}
|
}
|
||||||
|
|
@ -137,5 +129,5 @@ public class GameWatcher {
|
||||||
public boolean isPlayer() {
|
public boolean isPlayer() {
|
||||||
return isPlayer;
|
return isPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue