Skip to content

Commit f285c5f

Browse files
committed
WIP transport API
1 parent 3e48909 commit f285c5f

File tree

5 files changed

+161
-0
lines changed

5 files changed

+161
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2015-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.rsocket.kotlin.transport
18+
19+
@SubclassOptInRequired(RSocketTransportApi::class)
20+
public interface RSocketClientTransport : RSocketTransport {
21+
@RSocketTransportApi
22+
public suspend fun connect(): RSocketTransportSession
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2015-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.rsocket.kotlin.transport
18+
19+
import kotlinx.coroutines.*
20+
21+
@SubclassOptInRequired(RSocketTransportApi::class)
22+
public interface RSocketServerTransport<Instance : RSocketServerInstance> : RSocketTransport {
23+
@RSocketTransportApi
24+
public suspend fun start(acceptor: RSocketServerAcceptor): Instance
25+
}
26+
27+
@RSocketTransportApi
28+
public interface RSocketServerAcceptor {
29+
public suspend fun accept(connection: RSocketTransportSession)
30+
}
31+
32+
// cancelling it will cancel server
33+
// coroutineContext of transport should contain SupervisorJob
34+
@SubclassOptInRequired(RSocketTransportApi::class)
35+
public interface RSocketServerInstance : CoroutineScope
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2015-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.rsocket.kotlin.transport
18+
19+
import kotlinx.coroutines.*
20+
import kotlin.coroutines.*
21+
22+
// coroutineContext of transport should contain SupervisorJob
23+
@SubclassOptInRequired(RSocketTransportApi::class)
24+
public interface RSocketTransport : CoroutineScope
25+
26+
// coroutineContext of transport should contain SupervisorJob
27+
@SubclassOptInRequired(RSocketTransportApi::class)
28+
public interface RSocketTransportEngine<Target, Transport : RSocketTransport> : CoroutineScope {
29+
public fun createTransport(target: Target): Transport
30+
}
31+
32+
// TODO: split into transport factory and RSocketTransportEngineFactory
33+
@SubclassOptInRequired(RSocketTransportApi::class)
34+
public interface RSocketTransportFactory<Target, Transport : RSocketTransport, Engine : RSocketTransportEngine<Target, Transport>, Builder> {
35+
public operator fun invoke(context: CoroutineContext, target: Target, block: Builder.() -> Unit = {}): Transport
36+
public fun Engine(context: CoroutineContext, block: Builder.() -> Unit = {}): Engine
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2015-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.rsocket.kotlin.transport
18+
19+
@RequiresOptIn(
20+
level = RequiresOptIn.Level.ERROR,
21+
message = """
22+
This is an API which is used to implement transport for RSocket, such as WS or TCP.
23+
This API should not be used from general code
24+
"""
25+
)
26+
public annotation class RSocketTransportApi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2015-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.rsocket.kotlin.transport
18+
19+
import io.ktor.utils.io.core.*
20+
import kotlinx.coroutines.*
21+
22+
// coroutineContext of session should NOT contain SupervisorJob
23+
@RSocketTransportApi
24+
public sealed interface RSocketTransportSession : CoroutineScope {
25+
public interface Sequential : RSocketTransportSession {
26+
public suspend fun sendFrame(frame: ByteReadPacket)
27+
public suspend fun receiveFrame(): ByteReadPacket
28+
}
29+
30+
public interface Multiplexed : RSocketTransportSession {
31+
public interface Stream : CoroutineScope {
32+
public fun prioritize()
33+
public suspend fun sendFrame(frame: ByteReadPacket)
34+
public suspend fun receiveFrame(): ByteReadPacket
35+
}
36+
37+
public suspend fun createStream(): Stream
38+
public suspend fun awaitStream(): Stream
39+
}
40+
}

0 commit comments

Comments
 (0)