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

Refactoring work.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3748 b35dd754-fafc-0310-a699-88a17e54d16e
parent cb520e28
...@@ -45,7 +45,6 @@ import java.util.concurrent.CopyOnWriteArrayList; ...@@ -45,7 +45,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
*/ */
public class SessionManager extends BasicModule { public class SessionManager extends BasicModule {
private int sessionCount = 0;
public static final int NEVER_KICK = -1; public static final int NEVER_KICK = -1;
private PresenceUpdateHandler presenceHandler; private PresenceUpdateHandler presenceHandler;
...@@ -847,6 +846,12 @@ public class SessionManager extends BasicModule { ...@@ -847,6 +846,12 @@ public class SessionManager extends BasicModule {
return session; return session;
} }
/**
* Returns a list that contains all client sessions connected to the server. The list
* contains sessions of anonymous and non-anonymous users.
*
* @return a list that contains all client sessions connected to the server.
*/
public Collection<ClientSession> getSessions() { public Collection<ClientSession> getSessions() {
List<ClientSession> allSessions = new ArrayList<ClientSession>(); List<ClientSession> allSessions = new ArrayList<ClientSession>();
copyUserSessions(allSessions); copyUserSessions(allSessions);
...@@ -1057,10 +1062,12 @@ public class SessionManager extends BasicModule { ...@@ -1057,10 +1062,12 @@ public class SessionManager extends BasicModule {
return sessionList; return sessionList;
} }
public int getTotalSessionCount() { /**
return sessionCount; * Returns number of client sessions that are connected to the server. Anonymous users
} * are included too.
*
* @return number of client sessions that are connected to the server.
*/
public int getSessionCount() { public int getSessionCount() {
int sessionCount = 0; int sessionCount = 0;
for (String username : getSessionUsers()) { for (String username : getSessionUsers()) {
...@@ -1070,6 +1077,22 @@ public class SessionManager extends BasicModule { ...@@ -1070,6 +1077,22 @@ public class SessionManager extends BasicModule {
return sessionCount; return sessionCount;
} }
/**
* Returns number of client sessions that are available. Anonymous users
* are included too.
*
* @return number of client sessions that are available.
*/
public int getActiveSessionCount() {
int sessionCount = 0;
for (ClientSession session : getSessions()) {
if (session.getPresence().isAvailable()) {
sessionCount++;
}
}
return sessionCount;
}
public int getAnonymousSessionCount() { public int getAnonymousSessionCount() {
return anonymousSessions.size(); return anonymousSessions.size();
} }
...@@ -1182,8 +1205,7 @@ public class SessionManager extends BasicModule { ...@@ -1182,8 +1205,7 @@ public class SessionManager extends BasicModule {
SessionMap sessionMap; SessionMap sessionMap;
if (anonymousSessions.containsValue(session)) { if (anonymousSessions.containsValue(session)) {
anonymousSessions.remove(session.getAddress().getResource()); anonymousSessions.remove(session.getAddress().getResource());
sessionCount--;
// Fire session event. // Fire session event.
SessionEventDispatcher.dispatchEvent(session, SessionEventDispatcher.dispatchEvent(session,
SessionEventDispatcher.EventType.anonymous_session_destroyed); SessionEventDispatcher.EventType.anonymous_session_destroyed);
...@@ -1197,7 +1219,6 @@ public class SessionManager extends BasicModule { ...@@ -1197,7 +1219,6 @@ public class SessionManager extends BasicModule {
sessionMap = sessions.get(username); sessionMap = sessions.get(username);
if (sessionMap != null) { if (sessionMap != null) {
sessionMap.removeSession(session); sessionMap.removeSession(session);
sessionCount--;
if (sessionMap.isEmpty()) { if (sessionMap.isEmpty()) {
sessions.remove(username); sessions.remove(username);
} }
......
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