Skip to content

Commit 3e48909

Browse files
committed
hide ktor deprecation
* this API will be removed in Ktor 4.0 * possible replacement will be ready by Ktor 3.0 + kotlinx.io * most of the public declarations will be replaced in coming changes
1 parent 2900661 commit 3e48909

File tree

70 files changed

+238
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+238
-187
lines changed

rsocket-core/api/rsocket-core.api

+4
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,14 @@ public final class io/rsocket/kotlin/core/RSocketConnector {
212212
public final class io/rsocket/kotlin/core/RSocketConnectorBuilder {
213213
public final fun acceptor (Lio/rsocket/kotlin/ConnectionAcceptor;)V
214214
public final fun connectionConfig (Lkotlin/jvm/functions/Function1;)V
215+
public final fun getBufferPool ()Lio/ktor/utils/io/pool/ObjectPool;
215216
public final fun getLoggerFactory ()Lio/rsocket/kotlin/logging/LoggerFactory;
216217
public final fun getMaxFragmentSize ()I
217218
public final fun interceptors (Lkotlin/jvm/functions/Function1;)V
218219
public final fun reconnectable (JLkotlin/jvm/functions/Function2;)V
219220
public final fun reconnectable (Lkotlin/jvm/functions/Function3;)V
220221
public static synthetic fun reconnectable$default (Lio/rsocket/kotlin/core/RSocketConnectorBuilder;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
222+
public final fun setBufferPool (Lio/ktor/utils/io/pool/ObjectPool;)V
221223
public final fun setLoggerFactory (Lio/rsocket/kotlin/logging/LoggerFactory;)V
222224
public final fun setMaxFragmentSize (I)V
223225
}
@@ -242,9 +244,11 @@ public final class io/rsocket/kotlin/core/RSocketServer {
242244
}
243245

244246
public final class io/rsocket/kotlin/core/RSocketServerBuilder {
247+
public final fun getBufferPool ()Lio/ktor/utils/io/pool/ObjectPool;
245248
public final fun getLoggerFactory ()Lio/rsocket/kotlin/logging/LoggerFactory;
246249
public final fun getMaxFragmentSize ()I
247250
public final fun interceptors (Lkotlin/jvm/functions/Function1;)V
251+
public final fun setBufferPool (Lio/ktor/utils/io/pool/ObjectPool;)V
248252
public final fun setLoggerFactory (Lio/rsocket/kotlin/logging/LoggerFactory;)V
249253
public final fun setMaxFragmentSize (I)V
250254
}

rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/Connection.kt

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2022 the original author or authors.
2+
* Copyright 2015-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,17 +28,21 @@ import kotlinx.coroutines.*
2828
*/
2929
@TransportApi
3030
public interface Connection : CoroutineScope {
31-
public val pool: ObjectPool<ChunkBuffer> get() = ChunkBuffer.Pool
31+
@Suppress("DEPRECATION")
32+
@Deprecated(DEPRECATED_IN_KTOR, level = DeprecationLevel.ERROR)
33+
public val pool: ObjectPool<ChunkBuffer> get() = TODO("SHOULD NOT BE CALLED ANY MORE")
3234

3335
public suspend fun send(packet: ByteReadPacket)
3436
public suspend fun receive(): ByteReadPacket
3537
}
3638

39+
@Suppress("DEPRECATION")
3740
@OptIn(TransportApi::class)
38-
internal suspend inline fun <T> Connection.receiveFrame(block: (frame: Frame) -> T): T =
39-
receive().readFrame(pool).closeOnError(block)
41+
internal suspend inline fun <T> Connection.receiveFrame(bufferPool: ObjectPool<ChunkBuffer>, block: (frame: Frame) -> T): T =
42+
receive().readFrame(bufferPool).closeOnError(block)
4043

44+
@Suppress("DEPRECATION")
4145
@OptIn(TransportApi::class)
42-
internal suspend fun Connection.sendFrame(frame: Frame) {
43-
frame.toPacket(pool).closeOnError { send(it) }
46+
internal suspend fun Connection.sendFrame(bufferPool: ObjectPool<ChunkBuffer>, frame: Frame) {
47+
frame.toPacket(bufferPool).closeOnError { send(it) }
4448
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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
18+
19+
internal const val DEPRECATED_IN_KTOR = "Deprecated in Ktor"

rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketConnector.kt

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2022 the original author or authors.
2+
* Copyright 2015-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
1616

1717
package io.rsocket.kotlin.core
1818

19+
import io.ktor.utils.io.core.internal.*
20+
import io.ktor.utils.io.pool.*
1921
import io.rsocket.kotlin.*
2022
import io.rsocket.kotlin.frame.*
2123
import io.rsocket.kotlin.frame.io.*
@@ -32,6 +34,7 @@ public class RSocketConnector internal constructor(
3234
private val connectionConfigProvider: () -> ConnectionConfig,
3335
private val acceptor: ConnectionAcceptor,
3436
private val reconnectPredicate: ReconnectPredicate?,
37+
@Suppress("DEPRECATION") private val bufferPool: ObjectPool<ChunkBuffer>,
3538
) {
3639

3740
public suspend fun connect(transport: ClientTransport): RSocket = when (reconnectPredicate) {
@@ -68,9 +71,10 @@ public class RSocketConnector internal constructor(
6871
maxFragmentSize = maxFragmentSize,
6972
interceptors = interceptors,
7073
connectionConfig = connectionConfig,
71-
acceptor = acceptor
74+
acceptor = acceptor,
75+
bufferPool = bufferPool
7276
)
73-
connection.sendFrame(setupFrame)
77+
connection.sendFrame(bufferPool, setupFrame)
7478
return requester
7579
} catch (cause: Throwable) {
7680
connectionConfig.setupPayload.close()

rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketConnectorBuilder.kt

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2022 the original author or authors.
2+
* Copyright 2015-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
1616

1717
package io.rsocket.kotlin.core
1818

19+
import io.ktor.utils.io.core.internal.*
20+
import io.ktor.utils.io.pool.*
1921
import io.rsocket.kotlin.*
2022
import io.rsocket.kotlin.internal.*
2123
import io.rsocket.kotlin.keepalive.*
@@ -35,6 +37,10 @@ public class RSocketConnectorBuilder internal constructor() {
3537
field = value
3638
}
3739

40+
@Suppress("DEPRECATION")
41+
@Deprecated("Only for tests in rsocket", level = DeprecationLevel.ERROR)
42+
public var bufferPool: ObjectPool<ChunkBuffer> = ChunkBuffer.Pool
43+
3844
private val connectionConfig: ConnectionConfigBuilder = ConnectionConfigBuilder()
3945
private val interceptors: InterceptorsBuilder = InterceptorsBuilder()
4046
private var acceptor: ConnectionAcceptor? = null
@@ -101,14 +107,16 @@ public class RSocketConnectorBuilder internal constructor() {
101107
}
102108
}
103109

110+
@Suppress("DEPRECATION_ERROR")
104111
@OptIn(RSocketLoggingApi::class)
105112
internal fun build(): RSocketConnector = RSocketConnector(
106113
loggerFactory,
107114
maxFragmentSize,
108115
interceptors.build(),
109116
connectionConfig.producer(),
110117
acceptor ?: defaultAcceptor,
111-
reconnectPredicate
118+
reconnectPredicate,
119+
bufferPool
112120
)
113121

114122
private companion object {

rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketServer.kt

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2022 the original author or authors.
2+
* Copyright 2015-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
1616

1717
package io.rsocket.kotlin.core
1818

19+
import io.ktor.utils.io.core.internal.*
20+
import io.ktor.utils.io.pool.*
1921
import io.rsocket.kotlin.*
2022
import io.rsocket.kotlin.frame.*
2123
import io.rsocket.kotlin.frame.io.*
@@ -29,6 +31,7 @@ public class RSocketServer internal constructor(
2931
private val loggerFactory: LoggerFactory,
3032
private val maxFragmentSize: Int,
3133
private val interceptors: Interceptors,
34+
@Suppress("DEPRECATION") private val bufferPool: ObjectPool<ChunkBuffer>,
3235
) {
3336

3437
@DelicateCoroutinesApi
@@ -47,7 +50,7 @@ public class RSocketServer internal constructor(
4750
}
4851
}
4952

50-
private suspend fun Connection.bind(acceptor: ConnectionAcceptor): Job = receiveFrame { setupFrame ->
53+
private suspend fun Connection.bind(acceptor: ConnectionAcceptor): Job = receiveFrame(bufferPool) { setupFrame ->
5154
when {
5255
setupFrame !is SetupFrame -> failSetup(RSocketError.Setup.Invalid("Invalid setup frame: ${setupFrame.type}"))
5356
setupFrame.version != Version.Current -> failSetup(RSocketError.Setup.Unsupported("Unsupported version: ${setupFrame.version}"))
@@ -64,7 +67,8 @@ public class RSocketServer internal constructor(
6467
payloadMimeType = setupFrame.payloadMimeType,
6568
setupPayload = setupFrame.payload
6669
),
67-
acceptor = acceptor
70+
acceptor = acceptor,
71+
bufferPool = bufferPool
6872
)
6973
coroutineContext.job
7074
} catch (e: Throwable) {
@@ -75,7 +79,7 @@ public class RSocketServer internal constructor(
7579

7680
@Suppress("SuspendFunctionOnCoroutineScope")
7781
private suspend fun Connection.failSetup(error: RSocketError.Setup): Nothing {
78-
sendFrame(ErrorFrame(0, error))
82+
sendFrame(bufferPool, ErrorFrame(0, error))
7983
cancel("Connection establishment failed", error)
8084
throw error
8185
}

rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/core/RSocketServerBuilder.kt

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2022 the original author or authors.
2+
* Copyright 2015-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
1616

1717
package io.rsocket.kotlin.core
1818

19+
import io.ktor.utils.io.core.internal.*
20+
import io.ktor.utils.io.pool.*
1921
import io.rsocket.kotlin.*
2022
import io.rsocket.kotlin.logging.*
2123

@@ -30,14 +32,19 @@ public class RSocketServerBuilder internal constructor() {
3032
field = value
3133
}
3234

35+
@Suppress("DEPRECATION")
36+
@Deprecated("Only for tests in rsocket", level = DeprecationLevel.ERROR)
37+
public var bufferPool: ObjectPool<ChunkBuffer> = ChunkBuffer.Pool
38+
3339
private val interceptors: InterceptorsBuilder = InterceptorsBuilder()
3440

3541
public fun interceptors(configure: InterceptorsBuilder.() -> Unit) {
3642
interceptors.configure()
3743
}
3844

45+
@Suppress("DEPRECATION_ERROR")
3946
@OptIn(RSocketLoggingApi::class)
40-
internal fun build(): RSocketServer = RSocketServer(loggerFactory, maxFragmentSize, interceptors.build())
47+
internal fun build(): RSocketServer = RSocketServer(loggerFactory, maxFragmentSize, interceptors.build(), bufferPool)
4148
}
4249

4350
public fun RSocketServer(configure: RSocketServerBuilder.() -> Unit = {}): RSocketServer {

rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/ExtensionFrame.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2022 the original author or authors.
2+
* Copyright 2015-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,7 +49,11 @@ internal class ExtensionFrame(
4949
}
5050
}
5151

52-
internal fun ByteReadPacket.readExtension(pool: ObjectPool<ChunkBuffer>, streamId: Int, flags: Int): ExtensionFrame {
52+
internal fun ByteReadPacket.readExtension(
53+
@Suppress("DEPRECATION") pool: ObjectPool<ChunkBuffer>,
54+
streamId: Int,
55+
flags: Int,
56+
): ExtensionFrame {
5357
val extendedType = readInt()
5458
val payload = readPayload(pool, flags)
5559
return ExtensionFrame(streamId, extendedType, payload)

rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/Frame.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2022 the original author or authors.
2+
* Copyright 2015-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@ internal sealed class Frame : Closeable {
3333
protected abstract fun StringBuilder.appendFlags()
3434
protected abstract fun StringBuilder.appendSelf()
3535

36-
internal fun toPacket(pool: ObjectPool<ChunkBuffer>): ByteReadPacket {
36+
internal fun toPacket(@Suppress("DEPRECATION") pool: ObjectPool<ChunkBuffer>): ByteReadPacket {
3737
check(type.canHaveMetadata || !(flags check Flags.Metadata)) { "bad value for metadata flag" }
3838
return buildPacket(pool) {
3939
writeInt(streamId)
@@ -54,7 +54,7 @@ internal sealed class Frame : Closeable {
5454
}
5555
}
5656

57-
internal fun ByteReadPacket.readFrame(pool: ObjectPool<ChunkBuffer>): Frame = use {
57+
internal fun ByteReadPacket.readFrame(@Suppress("DEPRECATION") pool: ObjectPool<ChunkBuffer>): Frame = use {
5858
val streamId = readInt()
5959
val typeAndFlags = readShort().toInt() and 0xFFFF
6060
val flags = typeAndFlags and FlagsMask

rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/KeepAliveFrame.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2022 the original author or authors.
2+
* Copyright 2015-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ internal class KeepAliveFrame(
5151
}
5252
}
5353

54-
internal fun ByteReadPacket.readKeepAlive(pool: ObjectPool<ChunkBuffer>, flags: Int): KeepAliveFrame {
54+
internal fun ByteReadPacket.readKeepAlive(@Suppress("DEPRECATION") pool: ObjectPool<ChunkBuffer>, flags: Int): KeepAliveFrame {
5555
val respond = flags check RespondFlag
5656
val lastPosition = readLong()
5757
val data = readPacket(pool)

rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/LeaseFrame.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2022 the original author or authors.
2+
* Copyright 2015-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ internal class LeaseFrame(
5050
}
5151
}
5252

53-
internal fun ByteReadPacket.readLease(pool: ObjectPool<ChunkBuffer>, flags: Int): LeaseFrame {
53+
internal fun ByteReadPacket.readLease(@Suppress("DEPRECATION") pool: ObjectPool<ChunkBuffer>, flags: Int): LeaseFrame {
5454
val ttl = readInt()
5555
val numberOfRequests = readInt()
5656
val metadata = if (flags check Flags.Metadata) readMetadata(pool) else null

rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/MetadataPushFrame.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2022 the original author or authors.
2+
* Copyright 2015-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,5 +45,5 @@ internal class MetadataPushFrame(
4545
}
4646
}
4747

48-
internal fun ByteReadPacket.readMetadataPush(pool: ObjectPool<ChunkBuffer>): MetadataPushFrame =
48+
internal fun ByteReadPacket.readMetadataPush(@Suppress("DEPRECATION") pool: ObjectPool<ChunkBuffer>): MetadataPushFrame =
4949
MetadataPushFrame(readPacket(pool))

rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/RequestFrame.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2022 the original author or authors.
2+
* Copyright 2015-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -66,11 +66,11 @@ internal class RequestFrame(
6666
}
6767

6868
internal fun ByteReadPacket.readRequest(
69-
pool: ObjectPool<ChunkBuffer>,
69+
@Suppress("DEPRECATION") pool: ObjectPool<ChunkBuffer>,
7070
type: FrameType,
7171
streamId: Int,
7272
flags: Int,
73-
withInitial: Boolean
73+
withInitial: Boolean,
7474
): RequestFrame {
7575
val fragmentFollows = flags check Flags.Follows
7676
val complete = flags check Flags.Complete

rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/ResumeFrame.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2022 the original author or authors.
2+
* Copyright 2015-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ internal class ResumeFrame(
5050
}
5151
}
5252

53-
internal fun ByteReadPacket.readResume(pool: ObjectPool<ChunkBuffer>): ResumeFrame {
53+
internal fun ByteReadPacket.readResume(@Suppress("DEPRECATION") pool: ObjectPool<ChunkBuffer>): ResumeFrame {
5454
val version = readVersion()
5555
val resumeToken = readResumeToken(pool)
5656
val lastReceivedServerPosition = readLong()

rsocket-core/src/commonMain/kotlin/io/rsocket/kotlin/frame/SetupFrame.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2022 the original author or authors.
2+
* Copyright 2015-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -76,7 +76,7 @@ internal class SetupFrame(
7676
}
7777
}
7878

79-
internal fun ByteReadPacket.readSetup(pool: ObjectPool<ChunkBuffer>, flags: Int): SetupFrame {
79+
internal fun ByteReadPacket.readSetup(@Suppress("DEPRECATION") pool: ObjectPool<ChunkBuffer>, flags: Int): SetupFrame {
8080
val version = readVersion()
8181
val keepAlive = run {
8282
val interval = readInt()

0 commit comments

Comments
 (0)