Add: Extend UserRegistry to remove Disconnected User, reassign User to new session and get all users
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package ch.unibas.dmi.dbis.cs108.casono.server.domain.user;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.sessions.SessionId;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -49,4 +51,29 @@ public class UserRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public synchronized boolean removeIfStillDisconnected(UserId userId) {
|
||||
User user = byId.get(userId);
|
||||
if (user == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (user.getSessionId().isPresent()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
byId.remove(user.getId());
|
||||
return true;
|
||||
}
|
||||
|
||||
public synchronized Optional<User> reassignSession(UserId userId, SessionId sessionId) {
|
||||
User user = byId.get(userId);
|
||||
if (user == null) return Optional.empty();
|
||||
|
||||
user.reassignSession(sessionId);
|
||||
return Optional.of(user);
|
||||
}
|
||||
|
||||
public Collection<User> getAllUsers() {
|
||||
return byId.values();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user