better naming & interface for 3.1
This commit is contained in:
parent
b35ca92e48
commit
ceb6ea53db
@ -0,0 +1,15 @@
|
|||||||
|
package net.sergeych.parsec3
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transport level protocol (conforms to parsec 3.0). It is not specially secured could be used as is, as it provides bidirectional
|
||||||
|
* asynchronous (push capable) calls, but normally it should be used as a transport for parsec 3.1 secure
|
||||||
|
* protocol which uses this transport interface to run.
|
||||||
|
*/
|
||||||
|
interface Parsec3Transport<S> {
|
||||||
|
val connectedFlow: StateFlow<Boolean>
|
||||||
|
fun close()
|
||||||
|
|
||||||
|
suspend fun adapter(): Adapter<S>
|
||||||
|
}
|
@ -16,27 +16,27 @@ class Parsec3WSClient<S, H : CommandHost<S>>(
|
|||||||
val api: H,
|
val api: H,
|
||||||
val exceptionsRegistry: ExceptionsRegistry = ExceptionsRegistry(),
|
val exceptionsRegistry: ExceptionsRegistry = ExceptionsRegistry(),
|
||||||
f: AdapterBuilder<S, H>.() -> Unit,
|
f: AdapterBuilder<S, H>.() -> Unit,
|
||||||
) : LogTag("P3WSC") {
|
) : LogTag("P3WSC"), Parsec3Transport<S> {
|
||||||
|
|
||||||
val builder = AdapterBuilder(api, exceptionsRegistry, f)
|
val builder = AdapterBuilder(api, exceptionsRegistry, f)
|
||||||
|
|
||||||
private val _connectionFlow = MutableStateFlow(false)
|
private val _connectionFlow = MutableStateFlow(false)
|
||||||
private val closeFlow = MutableStateFlow(false)
|
private val closeFlow = MutableStateFlow(false)
|
||||||
val connectedFlow: StateFlow<Boolean> = _connectionFlow
|
override val connectedFlow: StateFlow<Boolean> = _connectionFlow
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
start()
|
start()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun close() {
|
override fun close() {
|
||||||
if( closeFlow.value == false ) closeFlow.value = true
|
if( closeFlow.value == false ) closeFlow.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
var deferredAdapter = CompletableDeferred<Adapter<S>>()
|
var deferredAdapter = CompletableDeferred<Adapter<S>>()
|
||||||
private set
|
private set
|
||||||
|
|
||||||
suspend fun adapter(): Adapter<S> = deferredAdapter.await()
|
override suspend fun adapter(): Adapter<S> = deferredAdapter.await()
|
||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
globalLaunch {
|
globalLaunch {
|
||||||
|
@ -10,7 +10,7 @@ import java.time.Duration
|
|||||||
import java.util.concurrent.atomic.AtomicInteger
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
import java.util.concurrent.atomic.AtomicLong
|
import java.util.concurrent.atomic.AtomicLong
|
||||||
|
|
||||||
fun <S, H : CommandHost<S>>Application.parsec3Server(
|
fun <S, H : CommandHost<S>>Application.parsec3TransportServer(
|
||||||
api: H,
|
api: H,
|
||||||
exceptionsRegistry: ExceptionsRegistry = ExceptionsRegistry(),
|
exceptionsRegistry: ExceptionsRegistry = ExceptionsRegistry(),
|
||||||
path: String = "/api/p3",
|
path: String = "/api/p3",
|
||||||
|
@ -21,7 +21,7 @@ internal class WsServerKtTest {
|
|||||||
fun testWsServer() {
|
fun testWsServer() {
|
||||||
|
|
||||||
embeddedServer(Netty, port = 8080) {
|
embeddedServer(Netty, port = 8080) {
|
||||||
parsec3Server(
|
parsec3TransportServer(
|
||||||
TestApiServer,
|
TestApiServer,
|
||||||
) {
|
) {
|
||||||
newSession { TestSession() }
|
newSession { TestSession() }
|
||||||
|
Loading…
Reference in New Issue
Block a user