Browse Source

Synchronise the users map

Fixes issue 3771

Change-Id: I3b2a0489dc7e3b923f2ea24308d0cd14a5089238
Reviewed-on: http://gerrit.dmdirc.com/931
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.3^0
Gregory Holmes 14 years ago
parent
commit
abb27887b0
1 changed files with 17 additions and 10 deletions
  1. 17
    10
      src/com/dmdirc/parser/irc/IRCChannelInfo.java

+ 17
- 10
src/com/dmdirc/parser/irc/IRCChannelInfo.java View File

@@ -31,6 +31,7 @@ import com.dmdirc.parser.interfaces.Parser;
31 31
 import com.dmdirc.parser.common.QueuePriority;
32 32
 import java.util.ArrayList;
33 33
 import java.util.Collection;
34
+import java.util.Collections;
34 35
 import java.util.Hashtable;
35 36
 import java.util.HashMap;
36 37
 import java.util.LinkedList;
@@ -73,7 +74,7 @@ public class IRCChannelInfo implements ChannelInfo {
73 74
     private final String sName;
74 75
     
75 76
     /** Hashtable containing references to ChannelClients. */
76
-    private final Map<String, IRCChannelClientInfo> hChannelUserList = new Hashtable<String, IRCChannelClientInfo>();
77
+    private final Map<String, IRCChannelClientInfo> hChannelUserList = Collections.synchronizedMap(new Hashtable<String, IRCChannelClientInfo>());
77 78
     /** Hashtable storing values for modes set in the channel that use parameters. */
78 79
     private final Map<Character, String> hParamModes = new Hashtable<Character, String>();
79 80
     /** Hashtable storing list modes. */
@@ -275,7 +276,9 @@ public class IRCChannelInfo implements ChannelInfo {
275 276
     /** {@inheritDoc} */
276 277
         @Override
277 278
     public Collection<ChannelClientInfo> getChannelClients() {
278
-        return new ArrayList<ChannelClientInfo>(hChannelUserList.values());
279
+        synchronized(hChannelUserList) {
280
+            return new ArrayList<ChannelClientInfo>(hChannelUserList.values());
281
+        }
279 282
     }
280 283
     
281 284
     /**
@@ -283,11 +286,13 @@ public class IRCChannelInfo implements ChannelInfo {
283 286
      */
284 287
     protected void emptyChannel() {
285 288
         IRCClientInfo cTemp = null;
286
-        for (IRCChannelClientInfo client : hChannelUserList.values()) {
287
-            cTemp = client.getClient();
288
-            cTemp.delChannelClientInfo(client);
289
-            if (cTemp != myParser.getLocalClient() && !cTemp.checkVisibility()) {
290
-                myParser.removeClient(cTemp);
289
+        synchronized (hChannelUserList) {
290
+            for (IRCChannelClientInfo client : hChannelUserList.values()) {
291
+                cTemp = client.getClient();
292
+                cTemp.delChannelClientInfo(client);
293
+                if (cTemp != myParser.getLocalClient() && !cTemp.checkVisibility()) {
294
+                    myParser.removeClient(cTemp);
295
+                }
291 296
             }
292 297
         }
293 298
         hChannelUserList.clear();
@@ -316,9 +321,11 @@ public class IRCChannelInfo implements ChannelInfo {
316 321
     /** {@inheritDoc} */
317 322
     @Override
318 323
     public IRCChannelClientInfo getChannelClient(final ClientInfo client) {
319
-        for (IRCChannelClientInfo target : hChannelUserList.values()) {
320
-            if (target.getClient() == client) {
321
-                return target;
324
+        synchronized (hChannelUserList) {
325
+            for (IRCChannelClientInfo target : hChannelUserList.values()) {
326
+                if (target.getClient() == client) {
327
+                    return target;
328
+                }
322 329
             }
323 330
         }
324 331
         return null;

Loading…
Cancel
Save