* Changes to session lock handling.

This commit is contained in:
LevelX2 2014-12-05 20:14:28 +01:00
parent cee5d0d487
commit c5bc99b8de
4 changed files with 14 additions and 24 deletions

View file

@ -213,10 +213,9 @@ public class Main {
// So it should be possible to reconnect to server and continue games if DisconnectReason is set to LostConnection
//SessionManager.getInstance().disconnect(client.getSessionId(), DisconnectReason.Disconnected);
SessionManager.getInstance().disconnect(client.getSessionId(), DisconnectReason.LostConnection);
logger.info("CLIENT DISCONNECTED - " + sessionInfo, throwable);
logger.info("CLIENT DISCONNECTED - " + sessionInfo);
logger.debug("Stack Trace", throwable);
}
else {
} else {
SessionManager.getInstance().disconnect(client.getSessionId(), DisconnectReason.LostConnection);
logger.info("LOST CONNECTION - " + sessionInfo);
if (logger.isDebugEnabled()) {

View file

@ -83,6 +83,10 @@ public class Session {
return returnMessage;
}
public boolean isLocked() {
return lock.isLocked();
}
public String registerUserHandling(String userName) throws MageException {
this.isAdmin = false;
if (userName.equals("Admin")) {
@ -216,6 +220,7 @@ public class Session {
try {
if(lock.tryLock(500, TimeUnit.MILLISECONDS)) {
lockSet = true;
logger.debug("SESSION LOCK SET sessionId: " + sessionId);
User user = UserManager.getInstance().getUser(userId);
if (user == null || !user.isConnected()) {
return; //user was already disconnected by other thread
@ -236,6 +241,7 @@ public class Session {
finally {
if (lockSet) {
lock.unlock();
logger.debug("SESSION LOCK UNLOCK sessionId: " + sessionId);
}
}
@ -246,6 +252,7 @@ public class Session {
try {
if(lock.tryLock(500, TimeUnit.MILLISECONDS)) {
lockSet = true;
logger.debug("SESSION LOCK SET sessionId: " + sessionId);
UserManager.getInstance().removeUser(userId, reason);
} else {
logger.error("SESSION LOCK - kill: userId " + userId);
@ -256,22 +263,17 @@ public class Session {
finally {
if (lockSet) {
lock.unlock();
logger.debug("SESSION LOCK UNLOCK sessionId: " + sessionId);
}
}
}
public void fireCallback(final ClientCallback call) {
boolean lockSet = false;
try {
if (lock.tryLock(500, TimeUnit.MILLISECONDS)) {
lockSet = true;
call.setMessageId(messageId++);
callbackHandler.handleCallbackOneway(new Callback(call));
} else {
logger.error("SESSION LOCK callback: userId " + userId);
logger.error(" - method: " + call.getMethod());
}
} catch (HandleCallbackException ex) {
User user = UserManager.getInstance().getUser(userId);
logger.warn("SESSION CALLBACK EXCEPTION - " + (user != null ? user.getName():"") + " userId " + userId);
@ -279,16 +281,6 @@ public class Session {
logger.warn(" - cause: " + getBasicCause(ex).toString());
logger.trace("Stack trace:", ex);
userLostConnection();
} catch (InterruptedException ex) {
logger.error("SESSION LOCK callback -userId: " + userId);
logger.error(" - method: " + call.getMethod());
logger.error(" - cause: " + getBasicCause(ex).toString());
logger.trace("Stack trace:", ex);
}
finally {
if (lockSet) {
lock.unlock();
}
}
}

View file

@ -362,9 +362,9 @@ public class TableManager {
public void debugServerState() {
logger.debug("--- Server state ----------------------------------------------");
Collection<User> users = UserManager.getInstance().getUsers();
logger.debug("--------User: " + users.size() + " [userId | since | name -----------------------");
logger.debug("--------User: " + users.size() + " [userId | since | lock | name -----------------------");
for (User user :users) {
logger.debug(user.getId() + " | " + formatter.format(user.getConnectionTime()) + " | " + user.getName() +" (" +user.getUserState().toString() + " - " + user.getPingInfo() + ")");
logger.debug(user.getId() + " | " + formatter.format(user.getConnectionTime()) + " | " + (SessionManager.getInstance().getSession(user.getSessionId()).isLocked()?"L":"-") + " | " + user.getName() +" (" +user.getUserState().toString() + " - " + user.getPingInfo() + ")");
}
ArrayList<ChatSession> chatSessions = ChatManager.getInstance().getChatSessions();
logger.debug("------- ChatSessions: " + chatSessions.size() + " ----------------------------------");

View file

@ -142,7 +142,7 @@ public class UserManager {
@Override
public void run() {
try {
logger.debug("USER REMOVE - " + user.getName() + " (" + reason.toString() + ") userId: " + userId);
logger.info("USER REMOVE - " + user.getName() + " (" + reason.toString() + ") userId: " + userId);
user.remove(reason);
logger.debug("USER REMOVE END - " + user.getName());
} catch (Exception ex) {
@ -180,7 +180,6 @@ public class UserManager {
usersToCheck.addAll(users.values());
for (User user : usersToCheck) {
if (!user.getUserState().equals(UserState.Expired) && user.isExpired(calendar.getTime())) {
logger.info(user.getName() + ": session expired userId: "+ user.getId() + " Host: " + user.getHost());
removeUser(user.getId(), DisconnectReason.SessionExpired);
}
}