Skip to content

Commit 12bb242

Browse files
committed
Refactorings
1 parent fe2c958 commit 12bb242

File tree

11 files changed

+57
-64
lines changed

11 files changed

+57
-64
lines changed

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
66
import util.libs
7+
import util.configureProjectReport
8+
import util.configureNpm
9+
import util.configureApiValidation
710

811
plugins {
912
alias(libs.plugins.serialization) apply false

gradle-conventions/common/src/main/kotlin/util/apiValidation.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ fun Project.configureApiValidation() {
1414
the<ApiValidationExtension>().apply {
1515
ignoredPackages.add("kotlinx.rpc.internal")
1616
ignoredPackages.add("kotlinx.rpc.krpc.internal")
17+
ignoredPackages.add("kotlinx.rpc.grpc.internal")
1718

1819
ignoredProjects.addAll(
1920
listOf(
2021
"compiler-plugin-tests",
2122
"krpc-test",
2223
"utils",
24+
"protobuf-plugin",
2325
)
2426
)
2527

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/GrpcClient.kt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,37 @@
44

55
package kotlinx.rpc.grpc
66

7+
import io.grpc.stub.AbstractStub
78
import kotlinx.coroutines.CoroutineScope
9+
import kotlinx.coroutines.Deferred
810
import kotlinx.coroutines.SupervisorJob
9-
import kotlinx.coroutines.flow.Flow
10-
import kotlinx.coroutines.flow.SharedFlow
11-
import kotlinx.coroutines.flow.StateFlow
1211
import kotlinx.coroutines.job
13-
import kotlinx.rpc.RPCCall
14-
import kotlinx.rpc.RPCClient
15-
import kotlinx.rpc.RPCField
12+
import kotlinx.rpc.RpcCall
13+
import kotlinx.rpc.RpcClient
14+
import kotlinx.rpc.descriptor.RpcServiceDescriptor
1615
import kotlin.coroutines.CoroutineContext
1716

18-
public class GrpcClient(
19-
private val channel: ManagedChannel,
20-
) : RPCClient {
17+
public class GrpcClient(private val channel: ManagedChannel) : RpcClient {
2118
override val coroutineContext: CoroutineContext = SupervisorJob()
2219

23-
override suspend fun <T> call(call: RPCCall): T {
24-
// todo perform call
25-
error("not implemented")
20+
override suspend fun <T> call(call: RpcCall): T {
21+
val stub = grpcStubByServiceDescriptor(call.descriptor)
22+
return invokeRpcMethodOnGrpcStub(stub, call)
2623
}
2724

28-
override fun <T> registerPlainFlowField(serviceScope: CoroutineScope, field: RPCField): Flow<T> {
29-
error("gRPC client does not support field declarations")
25+
private fun grpcStubByServiceDescriptor(descriptor: RpcServiceDescriptor<*>): AbstractStub<*> {
26+
error("Not yet implemented")
3027
}
3128

32-
override fun <T> registerSharedFlowField(serviceScope: CoroutineScope, field: RPCField): SharedFlow<T> {
33-
error("gRPC client does not support field declarations")
29+
private suspend fun <T> invokeRpcMethodOnGrpcStub(stub: AbstractStub<*>, call: RpcCall): T {
30+
error("Not yet implemented")
3431
}
3532

36-
override fun <T> registerStateFlowField(serviceScope: CoroutineScope, field: RPCField): StateFlow<T> {
37-
error("gRPC client does not support field declarations")
33+
override fun <T> callAsync(
34+
serviceScope: CoroutineScope,
35+
call: RpcCall,
36+
): Deferred<T> {
37+
TODO("Not yet implemented")
3838
}
3939

4040
override fun provideStubContext(serviceId: Long): CoroutineContext {
@@ -43,7 +43,7 @@ public class GrpcClient(
4343
}
4444
}
4545

46-
public fun grpcClient(
46+
public fun GrpcClient(
4747
name: String,
4848
port: Int,
4949
configure: ManagedChannelBuilder<*>.() -> Unit = {},
@@ -52,7 +52,7 @@ public fun grpcClient(
5252
return GrpcClient(channel)
5353
}
5454

55-
public fun grpcClient(
55+
public fun GrpcClient(
5656
target: String,
5757
configure: ManagedChannelBuilder<*>.() -> Unit = {},
5858
): GrpcClient {

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/GrpcServer.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ package kotlinx.rpc.grpc
66

77
import kotlinx.coroutines.SupervisorJob
88
import kotlinx.coroutines.job
9-
import kotlinx.rpc.RPC
10-
import kotlinx.rpc.RPCServer
9+
import kotlinx.rpc.RemoteService
10+
import kotlinx.rpc.RpcServer
1111
import kotlinx.rpc.grpc.internal.MutableHandlerRegistry
1212
import kotlinx.rpc.grpc.internal.ServerServiceDefinition
1313
import kotlin.coroutines.CoroutineContext
@@ -17,7 +17,7 @@ import kotlin.time.Duration
1717
public class GrpcServer internal constructor(
1818
override val port: Int = 8080,
1919
builder: ServerBuilder<*>.() -> Unit,
20-
) : RPCServer, Server {
20+
) : RpcServer, Server {
2121
private var isBuilt = false
2222
private lateinit var internalServer: Server
2323

@@ -29,7 +29,7 @@ public class GrpcServer internal constructor(
2929
override val coroutineContext: CoroutineContext
3030
get() = error("coroutineContext is not available for gRPC server builder")
3131

32-
override fun <Service : RPC> registerService(
32+
override fun <Service : RemoteService> registerService(
3333
serviceKClass: KClass<Service>,
3434
serviceFactory: (CoroutineContext) -> Service,
3535
) {
@@ -45,7 +45,7 @@ public class GrpcServer internal constructor(
4545
}
4646
}
4747

48-
private fun <Service : RPC> getDefinition(
48+
private fun <Service : RemoteService> getDefinition(
4949
service: Service,
5050
serviceKClass: KClass<Service>,
5151
): ServerServiceDefinition {
@@ -85,10 +85,10 @@ public class GrpcServer internal constructor(
8585
}
8686
}
8787

88-
public fun grpcServer(
88+
public fun GrpcServer(
8989
port: Int,
9090
configure: ServerBuilder<*>.() -> Unit = {},
91-
builder: RPCServer.() -> Unit = {},
91+
builder: RpcServer.() -> Unit = {},
9292
): GrpcServer {
9393
return GrpcServer(port, configure).apply(builder).apply { build() }
9494
}

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/ManagedChannel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface ManagedChannel {
1818
public fun shutdownNow(): ManagedChannel
1919
}
2020

21-
public expect abstract class ManagedChannelBuilder<T : io.grpc.ManagedChannelBuilder<T>>
21+
public expect abstract class ManagedChannelBuilder<T : ManagedChannelBuilder<T>>
2222

2323
public expect fun ManagedChannelBuilder(name: String, port: Int): ManagedChannelBuilder<*>
2424
public expect fun ManagedChannelBuilder(target: String): ManagedChannelBuilder<*>

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/Server.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,22 @@
22
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
6+
57
package kotlinx.rpc.grpc
68

9+
import kotlinx.rpc.grpc.internal.HandlerRegistry
10+
import kotlinx.rpc.grpc.internal.ServerServiceDefinition
711
import kotlin.time.Duration
812

13+
public expect abstract class ServerBuilder<T : ServerBuilder<T>> {
14+
public abstract fun addService(service: ServerServiceDefinition): T
15+
16+
public abstract fun fallbackHandlerRegistry(registry: HandlerRegistry?): T
17+
}
18+
19+
internal expect fun ServerBuilder(port: Int): ServerBuilder<*>
20+
921
public interface Server {
1022
public val port: Int
1123
public val isShutdown: Boolean

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/ServerBuilder.kt

Lines changed: 0 additions & 18 deletions
This file was deleted.

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/internal/MutableHandlerRegistry.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
package kotlinx.rpc.grpc.internal
88

9-
import kotlinx.rpc.internal.utils.InternalRPCApi
9+
import kotlinx.rpc.internal.utils.InternalRpcApi
1010

11-
@InternalRPCApi
11+
@InternalRpcApi
1212
public expect abstract class HandlerRegistry
1313

14-
@InternalRPCApi
14+
@InternalRpcApi
1515
public expect class MutableHandlerRegistry constructor() : HandlerRegistry {
1616
internal fun addService(service: ServerServiceDefinition): ServerServiceDefinition?
1717
}

grpc/grpc-core/src/commonMain/kotlin/kotlinx/rpc/grpc/internal/ServerServiceDefinition.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
package kotlinx.rpc.grpc.internal
88

9-
import kotlinx.rpc.internal.utils.InternalRPCApi
9+
import kotlinx.rpc.internal.utils.InternalRpcApi
1010

11-
@InternalRPCApi
11+
@InternalRpcApi
1212
public expect class ServerServiceDefinition

grpc/grpc-core/src/jvmMain/kotlin/kotlinx/rpc/grpc/Server.jvm.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import kotlinx.coroutines.withContext
99
import java.util.concurrent.TimeUnit
1010
import kotlin.time.Duration
1111

12+
public actual typealias ServerBuilder<T> = io.grpc.ServerBuilder<T>
13+
14+
internal actual fun ServerBuilder(port: Int): ServerBuilder<*> {
15+
return io.grpc.ServerBuilder.forPort(port)
16+
}
17+
18+
1219
internal actual fun Server(builder: ServerBuilder<*>): Server {
1320
return builder.build().toKotlin()
1421
}

0 commit comments

Comments
 (0)