added additional logging + keep session alive for most connection errors

This commit is contained in:
BetaSteward 2011-05-10 23:57:47 -04:00
parent 0dff1ac743
commit b9eac322d2
4 changed files with 13 additions and 7 deletions

View file

@ -705,11 +705,15 @@ public class Session {
}
private void handleRemoteException(RemoteException ex) {
server = null;
logger.log(Level.SEVERE, "Connection to server lost", ex);
frame.setStatusText("Not connected");
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Connection to server lost.", "Error", JOptionPane.ERROR_MESSAGE);
frame.disableButtons();
logger.log(Level.SEVERE, "Communication error", ex);
if (ex instanceof java.rmi.ConnectException) {
server = null;
frame.setStatusText("Not connected");
frame.disableButtons();
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Communication error - disconnecting.", "Error", JOptionPane.ERROR_MESSAGE);
}
else
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Communication error.", "Error", JOptionPane.ERROR_MESSAGE);
}
private void handleMageException(MageException ex) {

View file

@ -74,6 +74,7 @@ public class ChatSession {
public void broadcast(String userName, String message, MessageColor color) {
Calendar cal = new GregorianCalendar();
final String msg = timeFormatter.format(cal.getTime()) + " " + userName + ":" + message;
logger.debug("Broadcasting '" + msg + "' for " + chatId);
for (UUID sessionId: clients.keySet()) {
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)

View file

@ -113,7 +113,7 @@ public class ServerImpl extends RemoteServer implements Server {
if (version.compareTo(Main.getVersion()) != 0)
throw new MageException("Wrong client version " + version + ", expecting version " + Main.getVersion());
sessionId = SessionManager.getInstance().createSession(userName, clientId);
logger.info("Session " + sessionId + " created for user " + userName + " at " + getClientHost());
logger.info("User " + userName + " connected from " + getClientHost());
} catch (Exception ex) {
handleException(ex);
}

View file

@ -56,7 +56,7 @@ public class SessionManager {
for (Session session: sessions.values()) {
if (session.getUsername().equals(userName)) {
if (session.getClientId().equals(clientId)) {
logger.info("reconnecting session for " + userName);
logger.info("Reconnecting session " + session.getId() + " for " + userName);
return session.getId();
}
else {
@ -66,6 +66,7 @@ public class SessionManager {
}
Session session = new Session(userName, clientId);
sessions.put(session.getId(), session);
logger.info("Session " + session.getId() + " created for user " + userName);
return session.getId();
}