Commit 4d2dcdb9 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Modified #getSessionCount() to use AtomicInteger. JM-720

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4021 b35dd754-fafc-0310-a699-88a17e54d16e
parent 997afc80
...@@ -38,6 +38,7 @@ import org.xmpp.packet.Presence; ...@@ -38,6 +38,7 @@ import org.xmpp.packet.Presence;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* Manages the sessions associated with an account. The information * Manages the sessions associated with an account. The information
...@@ -57,6 +58,12 @@ public class SessionManager extends BasicModule { ...@@ -57,6 +58,12 @@ public class SessionManager extends BasicModule {
private UserManager userManager; private UserManager userManager;
private int conflictLimit; private int conflictLimit;
/**
* Counter of user sessions. A session is counted just after it was created and not
* after the user came available.
*/
private final AtomicInteger usersSessionsCounter = new AtomicInteger(0);
private ClientSessionListener clientSessionListener = new ClientSessionListener(); private ClientSessionListener clientSessionListener = new ClientSessionListener();
private ComponentSessionListener componentSessionListener = new ComponentSessionListener(); private ComponentSessionListener componentSessionListener = new ComponentSessionListener();
private IncomingServerSessionListener incomingServerListener = new IncomingServerSessionListener(); private IncomingServerSessionListener incomingServerListener = new IncomingServerSessionListener();
...@@ -511,6 +518,8 @@ public class SessionManager extends BasicModule { ...@@ -511,6 +518,8 @@ public class SessionManager extends BasicModule {
// Add to pre-authenticated sessions. // Add to pre-authenticated sessions.
preAuthenticatedSessions.put(session.getAddress().getResource(), session); preAuthenticatedSessions.put(session.getAddress().getResource(), session);
// Increment the counter of user sessions
usersSessionsCounter.incrementAndGet();
return session; return session;
} }
...@@ -1199,12 +1208,7 @@ public class SessionManager extends BasicModule { ...@@ -1199,12 +1208,7 @@ public class SessionManager extends BasicModule {
* @return number of client sessions that are connected to the server. * @return number of client sessions that are connected to the server.
*/ */
public int getSessionCount() { public int getSessionCount() {
int sessionCount = 0; return usersSessionsCounter.get();
for (String username : getSessionUsers()) {
sessionCount += getSessionCount(username);
}
sessionCount += anonymousSessions.size();
return sessionCount;
} }
/** /**
...@@ -1372,7 +1376,7 @@ public class SessionManager extends BasicModule { ...@@ -1372,7 +1376,7 @@ public class SessionManager extends BasicModule {
anonymousSessions.put(session.getAddress().getResource(), session); anonymousSessions.put(session.getAddress().getResource(), session);
// Remove the session from the pre-Authenticated sessions list // Remove the session from the pre-Authenticated sessions list
preAuthenticatedSessions.remove(session.getAddress().getResource()); preAuthenticatedSessions.remove(session.getAddress().getResource());
// Fire session event. // Fire session event.
SessionEventDispatcher.dispatchEvent(session, SessionEventDispatcher.dispatchEvent(session,
SessionEventDispatcher.EventType.anonymous_session_created); SessionEventDispatcher.EventType.anonymous_session_created);
...@@ -1420,6 +1424,8 @@ public class SessionManager extends BasicModule { ...@@ -1420,6 +1424,8 @@ public class SessionManager extends BasicModule {
finally { finally {
// Remove the session // Remove the session
removeSession(session); removeSession(session);
// Decrement the counter of user sessions
usersSessionsCounter.decrementAndGet();
} }
} }
catch (Exception e) { catch (Exception e) {
...@@ -1713,13 +1719,13 @@ public class SessionManager extends BasicModule { ...@@ -1713,13 +1719,13 @@ public class SessionManager extends BasicModule {
// Set the new property value // Set the new property value
JiveGlobals.setProperty("xmpp.server.session.idle", Integer.toString(idleTime)); JiveGlobals.setProperty("xmpp.server.session.idle", Integer.toString(idleTime));
if (idleTime <= 0 && isMultipleServerConnectionsAllowed() ) if (idleTime <= 0 && isMultipleServerConnectionsAllowed() )
{ {
Log.warn("Allowing multiple S2S connections for each domain, without setting a " + Log.warn("Allowing multiple S2S connections for each domain, without setting a " +
"maximum idle timeout for these connections, is unrecommended! Either " + "maximum idle timeout for these connections, is unrecommended! Either " +
"set xmpp.server.session.allowmultiple to 'false' or change " + "set xmpp.server.session.allowmultiple to 'false' or change " +
"xmpp.server.session.idle to a (large) positive value."); "xmpp.server.session.idle to a (large) positive value.");
} }
} }
public int getServerSessionIdleTime() { public int getServerSessionIdleTime() {
......
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