refactoring
This commit is contained in:
@@ -21,6 +21,7 @@ public class Lobby {
|
||||
|
||||
private final Map<UUID, Session> sessions = new ConcurrentHashMap<>();
|
||||
private final List<Player> players = new ArrayList<>();
|
||||
// read lock is required whenever players are read or sessions are modified, write lock is required when players are modified
|
||||
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
||||
private Lobby() {}
|
||||
@@ -79,6 +80,9 @@ public class Lobby {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a player to the lobby.
|
||||
*/
|
||||
public void join(Player player) {
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
@@ -89,6 +93,11 @@ public class Lobby {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a player from the lobby. It is ensured that no further lobby related messages
|
||||
* ({@link SessionCreatedMessage}, {@link SessionModifiedMessage}, {@link SessionRemovedMessage}) are set to this
|
||||
* player after the call to this method returns.
|
||||
*/
|
||||
public void leave(Player player) {
|
||||
lock.writeLock().lock();
|
||||
try {
|
||||
|
Reference in New Issue
Block a user