Merge pull request #10164 from abextm/threadsafety

runelite-client/chat: Be more thread safe
This commit is contained in:
Adam
2019-10-31 22:01:43 -04:00
committed by GitHub
3 changed files with 6 additions and 13 deletions

View File

@@ -24,8 +24,8 @@
*/
package net.runelite.client.chat;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
@@ -43,7 +43,7 @@ import net.runelite.client.events.PrivateMessageInput;
@Singleton
public class ChatCommandManager implements ChatboxInputListener
{
private final Map<String, ChatCommand> commands = new HashMap<>();
private final Map<String, ChatCommand> commands = new ConcurrentHashMap<>();
private final Client client;
private final ScheduledExecutorService scheduledExecutorService;

View File

@@ -556,16 +556,9 @@ public class ChatMessageManager
public void process()
{
if (!queuedMessages.isEmpty())
for (QueuedMessage msg; (msg = queuedMessages.poll()) != null; )
{
try
{
queuedMessages.forEach(this::add);
}
finally
{
queuedMessages.clear();
}
add(msg);
}
}

View File

@@ -25,9 +25,9 @@
*/
package net.runelite.client.chat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
@@ -55,7 +55,7 @@ public class CommandManager
private final ClientThread clientThread;
private boolean sending;
private final List<ChatboxInputListener> chatboxInputListenerList = new ArrayList<>();
private final List<ChatboxInputListener> chatboxInputListenerList = new CopyOnWriteArrayList<>();
@Inject
private CommandManager(Client client, EventBus eventBus, ClientThread clientThread)