@@ -23,17 +23,36 @@ public void createRoom(Long roomId) {
2323 roomParticipants .computeIfAbsent (roomId , k -> ConcurrentHashMap .newKeySet ());
2424 }
2525
26+ // public void addParticipant(Long roomId, Long memberId, int limit) {
27+ // Set<Long> participants = getRoomParticipants(roomId);
28+ //
29+ // if (participants.contains(memberId)) return;
30+ //
31+ // synchronized (participants) {
32+ // if (participants.size() >= limit) {
33+ // throw new ErrorException(UNAUTHORIZED_LIMIT_PARTICIPANT);
34+ // }
35+ // participants.add(memberId);
36+ // }
37+ // }
38+
2639 public void addParticipant (Long roomId , Long memberId , int limit ) {
27- Set <Long > participants = getRoomParticipants (roomId );
40+ roomParticipants .compute (roomId , (id , participants ) -> {
41+ participants = getRoomParticipants (roomId );
2842
29- if (participants .contains (memberId )) return ;
43+ // 중복 참가자일 경우 그대로 반환 (변화 없음)
44+ if (participants .contains (memberId )) {
45+ return participants ;
46+ }
3047
31- synchronized ( participants ) {
48+ // 인원 초과 시 예외 발생
3249 if (participants .size () >= limit ) {
3350 throw new ErrorException (UNAUTHORIZED_LIMIT_PARTICIPANT );
3451 }
52+
3553 participants .add (memberId );
36- }
54+ return participants ;
55+ });
3756 }
3857
3958 public void removeParticipant (Long memberId , Long roomId ) {
0 commit comments