Commit e983d2b9 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Fixed problem with client session counter. JM-793

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4770 b35dd754-fafc-0310-a699-88a17e54d16e
parent 50ef6008
...@@ -363,14 +363,16 @@ public class SessionManager extends BasicModule { ...@@ -363,14 +363,16 @@ public class SessionManager extends BasicModule {
/** /**
* Remove a session from the manager. * Remove a session from the manager.
* *
* @param session The session to remove * @param session The session to remove.
* @return true if the session was present in the map and was removed.
*/ */
void removeSession(Session session) { boolean removeSession(Session session) {
String resource = session.getAddress().getResource(); String resource = session.getAddress().getResource();
resources.remove(resource); boolean removed = resources.remove(resource) != null;
synchronized (priorityList) { synchronized (priorityList) {
priorityList.remove(resource); priorityList.remove(resource);
} }
return removed;
} }
/** /**
...@@ -1351,17 +1353,21 @@ public class SessionManager extends BasicModule { ...@@ -1351,17 +1353,21 @@ public class SessionManager extends BasicModule {
* Removes a session. * Removes a session.
* *
* @param session the session. * @param session the session.
* @return true if the requested session was successfully removed.
*/ */
public void removeSession(ClientSession session) { public boolean removeSession(ClientSession session) {
// Do nothing if session is null or if the server is shutting down. Note: When the server // Do nothing if session is null or if the server is shutting down. Note: When the server
// is shutting down the serverName will be null. // is shutting down the serverName will be null.
if (session == null || serverName == null) { if (session == null || serverName == null) {
return; return false;
} }
boolean auth_removed = false;
if (anonymousSessions.remove(session.getAddress().getResource()) != null) { if (anonymousSessions.remove(session.getAddress().getResource()) != null) {
// Fire session event. // Fire session event.
SessionEventDispatcher.dispatchEvent(session, SessionEventDispatcher.dispatchEvent(session,
SessionEventDispatcher.EventType.anonymous_session_destroyed); SessionEventDispatcher.EventType.anonymous_session_destroyed);
// Set that the session was found and removed
auth_removed = true;
} }
else { else {
// If this is a non-anonymous session then remove the session from the SessionMap // If this is a non-anonymous session then remove the session from the SessionMap
...@@ -1370,13 +1376,13 @@ public class SessionManager extends BasicModule { ...@@ -1370,13 +1376,13 @@ public class SessionManager extends BasicModule {
SessionMap sessionMap = sessions.get(username); SessionMap sessionMap = sessions.get(username);
if (sessionMap != null) { if (sessionMap != null) {
synchronized (username.intern()) { synchronized (username.intern()) {
sessionMap.removeSession(session); auth_removed = sessionMap.removeSession(session);
} }
if (sessionMap.isEmpty()) { if (sessionMap.isEmpty()) {
sessions.remove(username); sessions.remove(username);
} }
} }
if (sessionMap != null) { if (auth_removed) {
// Fire session event. // Fire session event.
SessionEventDispatcher.dispatchEvent(session, SessionEventDispatcher.dispatchEvent(session,
SessionEventDispatcher.EventType.session_destroyed); SessionEventDispatcher.EventType.session_destroyed);
...@@ -1384,7 +1390,8 @@ public class SessionManager extends BasicModule { ...@@ -1384,7 +1390,8 @@ public class SessionManager extends BasicModule {
} }
} }
// Remove the session from the pre-Authenticated sessions list (if present) // Remove the session from the pre-Authenticated sessions list (if present)
preAuthenticatedSessions.remove(session.getAddress().getResource()); boolean preauth_removed =
preAuthenticatedSessions.remove(session.getAddress().getResource()) != null;
// If the user is still available then send an unavailable presence // If the user is still available then send an unavailable presence
Presence presence = session.getPresence(); Presence presence = session.getPresence();
if (presence.isAvailable()) { if (presence.isAvailable()) {
...@@ -1394,6 +1401,7 @@ public class SessionManager extends BasicModule { ...@@ -1394,6 +1401,7 @@ public class SessionManager extends BasicModule {
offline.setType(Presence.Type.unavailable); offline.setType(Presence.Type.unavailable);
router.route(offline); router.route(offline);
} }
return auth_removed || preauth_removed;
} }
public void addAnonymousSession(ClientSession session) { public void addAnonymousSession(ClientSession session) {
...@@ -1433,7 +1441,7 @@ public class SessionManager extends BasicModule { ...@@ -1433,7 +1441,7 @@ public class SessionManager extends BasicModule {
*/ */
public void onConnectionClose(Object handback) { public void onConnectionClose(Object handback) {
try { try {
ClientSession session = (ClientSession)handback; ClientSession session = (ClientSession) handback;
try { try {
if (session.getPresence().isAvailable() || !session.wasAvailable()) { if (session.getPresence().isAvailable() || !session.wasAvailable()) {
// Send an unavailable presence to the user's subscribers // Send an unavailable presence to the user's subscribers
...@@ -1447,9 +1455,10 @@ public class SessionManager extends BasicModule { ...@@ -1447,9 +1455,10 @@ public class SessionManager extends BasicModule {
} }
finally { finally {
// Remove the session // Remove the session
removeSession(session); if (removeSession(session)) {
// Decrement the counter of user sessions // Decrement the counter of user sessions
usersSessionsCounter.decrementAndGet(); usersSessionsCounter.decrementAndGet();
}
} }
} }
catch (Exception e) { catch (Exception e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment