Loading src/dlt/src/main/kotlin/Main.kt +7 −0 Original line number Diff line number Diff line Loading @@ -60,4 +60,11 @@ suspend fun main(args: Array<String>) { } catch (e: ClientRequestException) { println(e.response.status) } try { val config = client.get<ByteArray>("http://localhost:8080/dlt/configure") println(DltConfig.parseFrom(config)) } catch (e: ClientRequestException) { println(e.response.status) } } No newline at end of file src/dlt/src/main/kotlin/http/Server.kt +25 −3 Original line number Diff line number Diff line Loading @@ -5,15 +5,24 @@ import io.ktor.application.* import io.ktor.features.* import io.ktor.http.* import io.ktor.request.* import io.ktor.response.* import io.ktor.routing.* import io.ktor.server.engine.* import io.ktor.server.netty.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.withContext import proto.Config.DltConfig.parseFrom class Server { var connector: FabricConnector? = null val port = 8080 val mutex = Mutex() } fun main() { embeddedServer(Netty, port = 8080) { val server = Server() embeddedServer(Netty, port = server.port) { install(ContentNegotiation) routing { post("/dlt/configure") { Loading @@ -22,8 +31,10 @@ fun main() { val data = call.receiveStream() val config = parseFrom(data) println(config) val connector = FabricConnector(config) connector.connect() server.mutex.lock() server.connector = FabricConnector(config) server.mutex.unlock() server.connector!!.connect() call.response.status(HttpStatusCode.Created) } // TODO: catch exceptions one by one Loading @@ -33,6 +44,17 @@ fun main() { } } } get("/dlt/configure") { server.mutex.lock() if (server.connector == null) { server.mutex.unlock() call.respond(HttpStatusCode.NotFound) } else { val configBytes = server.connector!!.config.toByteArray() server.mutex.unlock() call.respond(HttpStatusCode.OK, configBytes) } } } }.start(wait = true) } Loading
src/dlt/src/main/kotlin/Main.kt +7 −0 Original line number Diff line number Diff line Loading @@ -60,4 +60,11 @@ suspend fun main(args: Array<String>) { } catch (e: ClientRequestException) { println(e.response.status) } try { val config = client.get<ByteArray>("http://localhost:8080/dlt/configure") println(DltConfig.parseFrom(config)) } catch (e: ClientRequestException) { println(e.response.status) } } No newline at end of file
src/dlt/src/main/kotlin/http/Server.kt +25 −3 Original line number Diff line number Diff line Loading @@ -5,15 +5,24 @@ import io.ktor.application.* import io.ktor.features.* import io.ktor.http.* import io.ktor.request.* import io.ktor.response.* import io.ktor.routing.* import io.ktor.server.engine.* import io.ktor.server.netty.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.withContext import proto.Config.DltConfig.parseFrom class Server { var connector: FabricConnector? = null val port = 8080 val mutex = Mutex() } fun main() { embeddedServer(Netty, port = 8080) { val server = Server() embeddedServer(Netty, port = server.port) { install(ContentNegotiation) routing { post("/dlt/configure") { Loading @@ -22,8 +31,10 @@ fun main() { val data = call.receiveStream() val config = parseFrom(data) println(config) val connector = FabricConnector(config) connector.connect() server.mutex.lock() server.connector = FabricConnector(config) server.mutex.unlock() server.connector!!.connect() call.response.status(HttpStatusCode.Created) } // TODO: catch exceptions one by one Loading @@ -33,6 +44,17 @@ fun main() { } } } get("/dlt/configure") { server.mutex.lock() if (server.connector == null) { server.mutex.unlock() call.respond(HttpStatusCode.NotFound) } else { val configBytes = server.connector!!.config.toByteArray() server.mutex.unlock() call.respond(HttpStatusCode.OK, configBytes) } } } }.start(wait = true) }