Skip to content
Snippets Groups Projects
Commit 1c0b4e15 authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

Inform clients in sessions affected by scheduled legacy map cleanup via

Socket.IO about changed active user count.
parent 50a9ccc4
Branches
Tags
No related merge requests found
......@@ -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
......
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