1
1
/*
2
+ * Copyright (c) 2024.
3
+ *
2
4
* Licensed under the Apache License, Version 2.0 (the "License");
3
5
* you may not use this file except in compliance with the License.
4
6
* You may obtain a copy of the License at
11
13
* See the License for the specific language governing permissions and
12
14
* limitations under the License.
13
15
*/
14
- package org.modelix.model.server.handlers
16
+
17
+ package org.modelix.client.light
15
18
16
19
import io.ktor.server.application.Application
17
20
import io.ktor.server.request.host
@@ -22,8 +25,6 @@ import io.ktor.server.websocket.webSocket
22
25
import io.ktor.websocket.Frame
23
26
import io.ktor.websocket.readText
24
27
import io.ktor.websocket.send
25
- import kotlinx.coroutines.ExperimentalCoroutinesApi
26
- import kotlinx.coroutines.channels.Channel
27
28
import kotlinx.coroutines.launch
28
29
import kotlinx.coroutines.sync.Mutex
29
30
import kotlinx.coroutines.sync.withLock
@@ -55,14 +56,17 @@ import org.modelix.model.server.api.OperationData
55
56
import org.modelix.model.server.api.SetPropertyOpData
56
57
import org.modelix.model.server.api.SetReferenceOpData
57
58
import org.modelix.model.server.api.VersionData
59
+ import org.modelix.model.server.handlers.RepositoriesManager
58
60
import org.modelix.model.server.store.ContextScopedStoreClient
59
61
import org.modelix.model.server.store.LocalModelClient
60
62
import java.util.Date
61
- import kotlin.collections.set
62
63
63
64
private val LOG = KotlinLogging .logger {}
64
65
65
- class LightModelServer (val client : LocalModelClient , val repositoriesManager : RepositoriesManager ) {
66
+ /* *
67
+ * Simplified fake implementation of [org.modelix.model.server.light.LightModelServer].
68
+ */
69
+ class FakeLightModelServer (val client : LocalModelClient , val repositoriesManager : RepositoriesManager ) {
66
70
67
71
fun init (application : Application ) {
68
72
application.routing {
@@ -193,7 +197,16 @@ class LightModelServer(val client: LocalModelClient, val repositoriesManager: Re
193
197
}
194
198
}
195
199
} catch (ex: Exception ) {
196
- send(MessageFromServer (exception = ExceptionData (RuntimeException (" Failed to process message: $text " , ex))).toJson())
200
+ send(
201
+ MessageFromServer (
202
+ exception = ExceptionData (
203
+ RuntimeException (
204
+ " Failed to process message: $text " ,
205
+ ex,
206
+ ),
207
+ ),
208
+ ).toJson(),
209
+ )
197
210
}
198
211
}
199
212
else -> {}
@@ -365,10 +378,3 @@ class LightModelServer(val client: LocalModelClient, val repositoriesManager: Re
365
378
}
366
379
}
367
380
}
368
-
369
- @OptIn(ExperimentalCoroutinesApi ::class )
370
- private suspend fun <T > Channel<T>.receiveLast (): T {
371
- var latest = receive()
372
- while (! isEmpty) latest = receive()
373
- return latest
374
- }
0 commit comments