@@ -31,6 +31,8 @@ import com.jetbrains.gateway.ssh.ClientOverSshTunnelConnector
31
31
import com.jetbrains.gateway.ssh.SshHostTunnelConnector
32
32
import com.jetbrains.gateway.thinClientLink.ThinClientHandle
33
33
import com.jetbrains.rd.util.URI
34
+ import com.jetbrains.rd.util.addUnique
35
+ import com.jetbrains.rd.util.concurrentMapOf
34
36
import com.jetbrains.rd.util.lifetime.Lifetime
35
37
import io.gitpod.gitpodprotocol.api.entities.WorkspaceInstance
36
38
import io.gitpod.jetbrains.icons.GitpodIcons
@@ -47,9 +49,12 @@ import javax.swing.JComponent
47
49
import javax.swing.JLabel
48
50
import kotlin.coroutines.coroutineContext
49
51
52
+ class GitpodConnection (val gitpodHost : String , val workspaceId : String , val backendPort : String? ) {}
53
+
50
54
@Suppress(" UnstableApiUsage" , " OPT_IN_USAGE" )
51
55
class GitpodConnectionProvider : GatewayConnectionProvider {
52
-
56
+ // private val activeConnections = mutableListOf<GitpodConnection>()
57
+ private val activeConnectionsC = concurrentMapOf<String , Boolean >()
53
58
private val gitpod = service<GitpodConnectionService >()
54
59
55
60
private val httpClient = HttpClient .newBuilder()
@@ -74,6 +79,16 @@ class GitpodConnectionProvider : GatewayConnectionProvider {
74
79
parameters[" workspaceId" ]!! ,
75
80
parameters[" backendPort" ]
76
81
)
82
+
83
+ val connectionKeyId = " ${connectParams.gitpodHost} -${connectParams.workspaceId} -${connectParams.backendPort} "
84
+
85
+ if (activeConnectionsC.containsKey(connectionKeyId)) {
86
+ thisLogger().warn(" THE CONNECTION ALREADY EXISTS!!" )
87
+ throw IllegalArgumentException (" THE CONNECTION ALREADY EXISTS!!" )
88
+ } else {
89
+ thisLogger().warn(" NEW CONNECTION!!!!!" )
90
+ }
91
+
77
92
val client = gitpod.obtainClient(connectParams.gitpodHost)
78
93
val connectionLifetime = Lifetime .Eternal .createNested()
79
94
val updates = client.listenToWorkspace(connectionLifetime, connectParams.workspaceId)
@@ -230,6 +245,15 @@ class GitpodConnectionProvider : GatewayConnectionProvider {
230
245
setErrorMessage(" failed to fetch JetBrains Gateway Join Link." )
231
246
return @launch
232
247
}
248
+
249
+ // TODO: is this the right place?
250
+ // val newConnection = GitpodConnection(connectParams.gitpodHost, connectParams.workspaceId, connectParams.backendPort)
251
+ // activeConnections.add(newConnection)
252
+ val connectionKeyId = " ${connectParams.gitpodHost} -${connectParams.workspaceId} -${connectParams.backendPort} "
253
+ activeConnectionsC[connectionKeyId] = true
254
+
255
+ thisLogger().warn(" Storing connection for ${connectParams.gitpodHost} - ${connectParams.workspaceId} - ${connectParams.backendPort} " )
256
+
233
257
val connector = ClientOverSshTunnelConnector (
234
258
connectionLifetime,
235
259
SshHostTunnelConnector (credentials),
@@ -239,6 +263,7 @@ class GitpodConnectionProvider : GatewayConnectionProvider {
239
263
clientHandle.clientClosed.advise(connectionLifetime) {
240
264
application.invokeLater {
241
265
connectionLifetime.terminate()
266
+ // todo: remove this connection from activeConnections
242
267
}
243
268
}
244
269
clientHandle.onClientPresenceChanged.advise(connectionLifetime) {
0 commit comments