All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.caesarealabs.rpc4k.runtime.user.ServerUsage.kt Maven / Gradle / Ivy

There is a newer version: 0.13.0
Show newest version
package com.caesarealabs.rpc4k.runtime.user

import com.caesarealabs.rpc4k.runtime.api.EventManager
import com.caesarealabs.rpc4k.runtime.api.Rpc4kSCServerSuite
import com.caesarealabs.rpc4k.runtime.api.RpcServerEngine
import com.caesarealabs.rpc4k.runtime.api.SerializationFormat
import com.caesarealabs.rpc4k.runtime.api.ServerConfig
import com.caesarealabs.rpc4k.runtime.api.components.JsonFormat
import com.caesarealabs.rpc4k.runtime.api.components.MemoryEventManager
import com.caesarealabs.rpc4k.runtime.api.start
import com.caesarealabs.rpc4k.runtime.implementation.createHandlerConfig


public fun  Rpc4kIndex.startDedicatedServer(
    //TODO: MP default
    engine: RpcServerEngine.MultiCall /*= KtorManagedRpcServer()*/,
    format: SerializationFormat = JsonFormat(),
    eventManager: EventManager = MemoryEventManager(),
    wait: Boolean = true,
    service: (I) -> S,
) {
    createDedicatedServer(engine, format, eventManager, service).start(wait)
}

/**
 * Creates a MultiCall server
 */
public fun  Rpc4kIndex.createDedicatedServer(
    //TODO: MP default
    engine: RpcServerEngine.MultiCall /*= KtorManagedRpcServer()*/,
    format: SerializationFormat = JsonFormat(),
    eventManager: EventManager = MemoryEventManager(),
    service: (I) -> S
): Rpc4kSCServerSuite {
    val config = createHandlerConfig(format, eventManager, engine, service)
    val serverConfig = ServerConfig(router, config)
    return Rpc4kSCServerSuite(
        engine.create(serverConfig), serverConfig, config.handler, config.invoker
    )
}

/**
 * Creates a SingleCall server
 */
public fun  Rpc4kIndex.createSingleCallServer(
    engine: E,
    format: SerializationFormat = JsonFormat(),
    eventManager: EventManager = MemoryEventManager(),
    service: (Inv) -> S
): Rpc4kSCServerSuite {
    val config = createHandlerConfig(format, eventManager, engine, service)
    val serverConfig = ServerConfig(router, config)
    return Rpc4kSCServerSuite(
        engine, serverConfig, config.handler, config.invoker
    )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy