From 1c0b4e150b1d9cfd205600b69bed1dcd047edf8b Mon Sep 17 00:00:00 2001 From: Daniel Gerhardt <daniel.gerhardt@mni.thm.de> Date: Sat, 9 Mar 2013 17:45:03 +0100 Subject: [PATCH] Inform clients in sessions affected by scheduled legacy map cleanup via Socket.IO about changed active user count. --- .../de/thm/arsnova/services/UserService.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/thm/arsnova/services/UserService.java b/src/main/java/de/thm/arsnova/services/UserService.java index 8db052e0..9d206c44 100644 --- a/src/main/java/de/thm/arsnova/services/UserService.java +++ b/src/main/java/de/thm/arsnova/services/UserService.java @@ -38,9 +38,14 @@ import com.github.leleuj.ss.oauth.client.authentication.OAuthAuthenticationToken import de.thm.arsnova.dao.IDatabaseDao; import de.thm.arsnova.entities.User; import de.thm.arsnova.exceptions.UnauthorizedException; +import de.thm.arsnova.socket.ARSnovaSocketIOServer; public class UserService implements IUserService, InitializingBean, DisposableBean { + private static final int DEFAULT_SCHEDULER_DELAY_MS = 60000; + + private static final int MAX_USER_INACTIVE_SECONDS = 120; + public static final Logger LOGGER = LoggerFactory.getLogger(UserService.class); private static final ConcurrentHashMap<UUID, User> socketid2user = new ConcurrentHashMap<UUID, User>(); @@ -54,13 +59,13 @@ public class UserService implements IUserService, InitializingBean, DisposableBe @Autowired private IDatabaseDao databaseDao; - private static final int DEFAULT_SCHEDULER_DELAY_MS = 60000; - - private static final int MAX_USER_INACTIVE_SECONDS = 120; + @Autowired + private ARSnovaSocketIOServer socketIoServer; @Scheduled(fixedDelay = DEFAULT_SCHEDULER_DELAY_MS) public final void removeInactiveUsersFromLegacyMap() { List<String> usernames = databaseDao.getInactiveUsers(MAX_USER_INACTIVE_SECONDS); + Set<String> affectedSessions = new HashSet<String>(); LOGGER.info( "Inactive users count: {}, user2sessionLegacy count: {}", usernames.size(), user2sessionLegacy.size() @@ -72,10 +77,15 @@ public class UserService implements IUserService, InitializingBean, DisposableBe String username = key.getUsername(); LOGGER.debug("username: {}", username); if (usernames.contains(username)) { + affectedSessions.add(e.getValue()); LOGGER.debug("Removing user {} from user2sessionLegacy", e.getKey()); user2sessionLegacy.remove(e.getKey()); } } + + for (String sessionKeyword : affectedSessions) { + socketIoServer.reportActiveUserCountForSession(sessionKeyword); + } } @Override -- GitLab