diff options
author | kovalp <kovalp@google.com> | 2022-03-16 13:37:07 +0000 |
---|---|---|
committer | Polina Koval <kovalp@google.com> | 2022-03-16 14:29:12 +0000 |
commit | fec081a04f58523f6c2eec6844f95e6a6f8febf0 (patch) | |
tree | f7ce70eac3713b08d14710c4af1ce618329e0715 /android/testSrc | |
parent | e57cc9ea3b8df5726315ad143ddfe44fdd2ebedb (diff) | |
download | idea-fec081a04f58523f6c2eec6844f95e6a6f8febf0.tar.gz |
Use synchronizedMap for RunnableClientsService
Bug: n/a
Test: n/a
Change-Id: I9e9dda81c3e2f8d9ed971462bcf44ec4bde4753c
Diffstat (limited to 'android/testSrc')
-rw-r--r-- | android/testSrc/com/android/tools/idea/run/configuration/execution/RunnableClientService.kt | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/android/testSrc/com/android/tools/idea/run/configuration/execution/RunnableClientService.kt b/android/testSrc/com/android/tools/idea/run/configuration/execution/RunnableClientService.kt index 964c7f42990..ed7eb483204 100644 --- a/android/testSrc/com/android/tools/idea/run/configuration/execution/RunnableClientService.kt +++ b/android/testSrc/com/android/tools/idea/run/configuration/execution/RunnableClientService.kt @@ -31,6 +31,7 @@ import java.io.IOException import java.net.InetAddress import java.net.InetSocketAddress import java.net.ServerSocket +import java.util.Collections.synchronizedMap import java.util.concurrent.Executors import java.util.concurrent.Future import java.util.concurrent.atomic.AtomicBoolean @@ -42,7 +43,7 @@ import java.util.concurrent.atomic.AtomicBoolean * Client closes connection and "removed" from [DeploymentApplicationService] device when [stopClient] is invoked. */ internal class RunnableClientsService(testDisposable: Disposable) { - private val deviceToRunnableClients: MutableMap<IDevice, MutableMap<String, RunnableClient>> = mutableMapOf() + private val deviceToRunnableClients: MutableMap<IDevice, MutableMap<String, RunnableClient>> = synchronizedMap(mutableMapOf()) private val deploymentApplicationService = TestDeploymentApplicationService() init { @@ -52,12 +53,13 @@ internal class RunnableClientsService(testDisposable: Disposable) { fun stop() { deviceToRunnableClients.entries.forEach { (device, clients) -> - clients.keys.forEach { appId -> stopClient(device, appId) } + val appIds = clients.keys.toList() + appIds.forEach { appId -> stopClient(device, appId) } } } fun startClient(device: IDevice, appId: String): Client { - val clients = deviceToRunnableClients.computeIfAbsent(device) { mutableMapOf() } + val clients = deviceToRunnableClients.computeIfAbsent(device) { synchronizedMap(mutableMapOf()) } val runnableClient = RunnableClient.start(device, appId) clients[appId] = runnableClient deploymentApplicationService.addClient(device, appId, runnableClient.client) |