Skip to content

Commit

Permalink
wipi
Browse files Browse the repository at this point in the history
  • Loading branch information
whyoleg committed Dec 5, 2023
1 parent 3cf5622 commit 78391fa
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2015-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.rsocket.kotlin.configuration

import io.rsocket.kotlin.keepalive.*
import kotlin.time.*

public sealed interface KeepAliveConfiguration {
public fun receiver(handler: KeepAliveReceiver)
}

public sealed interface ClientKeepAliveConfiguration : KeepAliveConfiguration {
public fun interval(value: Duration)
public fun maxLifetime(value: Duration)
public fun dataGenerator(generator: KeepAliveDataGenerator)
}

public sealed interface ServerKeepAliveConfiguration : KeepAliveConfiguration {
public val interval: Duration
public val maxLifetime: Duration
public val sender: KeepAliveSender
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,9 @@ import kotlinx.coroutines.*
import kotlin.coroutines.*

public sealed interface RSocketClient : CoroutineScope {

public fun connect(
transport: RSocketClientTransport,
configurator: RSocketConfigurator<ClientSessionConfigurationV1>,
): RSocketSession = connectV1(transport, configurator)

public fun connectV1(
transport: RSocketClientTransport,
configurator: RSocketConfigurator<ClientSessionConfigurationV1>,
): RSocketSession

public fun connectV2(
transport: RSocketClientTransport,
configurator: RSocketConfigurator<ClientSessionConfigurationV2>,
configurator: RSocketSessionConfigurator<out ClientSessionConfiguration>,
): RSocketSession
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2015-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.rsocket.kotlin.configuration

import io.rsocket.kotlin.transport.*
import kotlinx.coroutines.*
import kotlin.coroutines.*

public sealed interface RSocketServer : CoroutineScope {
public suspend fun <Instance : RSocketServerInstance> start(
transport: RSocketServerTransport<Instance>,
configurator: RSocketSessionConfigurator<out ServerSessionConfiguration>,
): Instance
}

public sealed interface RSocketServerBuilder {

}

public fun RSocketServer(
context: CoroutineContext,
builder: RSocketServerBuilder.() -> Unit = {},
): RSocketServer {
TODO()
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ package io.rsocket.kotlin.configuration

// TODO: move to another package
public sealed interface RSocketSession

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
package io.rsocket.kotlin.configuration

// TODO: ???
public fun interface RSocketConfigurator<T : SessionConfiguration> {
public fun interface RSocketSessionConfigurator<T : SessionConfiguration> {
public suspend fun T.configure()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@

package io.rsocket.kotlin.configuration

public sealed interface ClientSessionConfiguration : SessionConfiguration
//TODO: naming
public sealed interface ReconnectConfiguration {
// if the connection establishment failed - what to do
public fun retryPredicate(predicate: suspend (cause: Throwable, attempt: Long) -> Boolean)

public sealed interface ClientSessionConfigurationV1 : ClientSessionConfiguration, SessionConfigurationV1
public sealed interface ClientSessionConfigurationV2 : ClientSessionConfiguration, SessionConfigurationV2
// if connection failed - what to do
public fun reconnectPredicate(predicate: suspend (cause: Throwable) -> Boolean)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ package io.rsocket.kotlin.configuration

public sealed interface SessionConfiguration

public sealed interface SessionConfigurationV1 : SessionConfiguration
public sealed interface SessionConfigurationV2 : SessionConfiguration
public sealed interface ClientSessionConfiguration : SessionConfiguration
public sealed interface ServerSessionConfiguration : SessionConfiguration


//public sealed interface SessionConfigurationV1 : RSocketSessionConfiguration
//public sealed interface SessionConfigurationV2 : RSocketSessionConfiguration

//public sealed interface ClientSessionConfigurationV1 : ClientSessionConfiguration, SessionConfigurationV1
//public sealed interface ClientSessionConfigurationV2 : ClientSessionConfiguration, SessionConfigurationV2
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2015-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.rsocket.kotlin.keepalive

import io.ktor.utils.io.core.*

//can be used by client only, `generateData` is called when new keep alive frame is generated,
// f.e. it can contain current timestamp to calculate latency
public fun interface KeepAliveDataGenerator {
public fun generateData(): ByteReadPacket
}

//can be registered by both client and server
//TODO: flow api
public fun interface KeepAliveReceiver {
public fun receiveKeepAlive(respond: Boolean, data: ByteReadPacket)
}

//implemented internally
//can be used by server only
//TODO: flow api
public sealed interface KeepAliveSender {
public suspend fun sendKeepAlive(data: ByteReadPacket)
}

0 comments on commit 78391fa

Please sign in to comment.