Skip to content
Permalink
Browse files

Basic gRPC runtime server

  • Loading branch information...
JoeHegarty committed Aug 9, 2019
1 parent 5e33b63 commit b414c32e298ac155daad46edaad3d5cd88b65bcb
@@ -24,10 +24,16 @@ configureProject(":src:orbit-proto", [withJava])


buildscript {
ext.kotlinVersion = "1.3.41"
// TODO: Upgrade once bug is fixed with orbit-core doc generation - https://github.com/Kotlin/dokka/issues/455
ext.dokkaVersion = "0.9.17"
ext.dokkaRepo = "https://dl.bintray.com/kotlin/dokka"
ext {
kotlinVersion = "1.3.41"
// TODO: Upgrade once bug is fixed with orbit-core doc generation - https://github.com/Kotlin/dokka/issues/455
dokkaVersion = "0.9.17"
dokkaRepo = "https://dl.bintray.com/kotlin/dokka"

protobufVersion = "3.9.1"
protobufPluginVersion = "0.8.10"
grpcVersion = "1.22.1"
}

repositories {
mavenCentral()
@@ -71,6 +77,7 @@ allprojects {

repositories {
mavenCentral()
jcenter()
maven { url(dokkaRepo) }
}
}
@@ -13,4 +13,6 @@ dependencies {

// TODO: Probably want a better logger
implementation("org.slf4j:slf4j-simple:$slf4jVersion")
implementation("org.slf4j:jul-to-slf4j:$slf4jVersion")

}
@@ -6,9 +6,10 @@

package orbit.application

import orbit.server.OrbitConfig
import orbit.server.OrbitServer

fun main() {
val server = OrbitServer()
val server = OrbitServer(OrbitConfig())
server.start()
}
@@ -5,10 +5,6 @@
*/

buildscript {
ext {
protobufVersion = "3.9.1"
protobufPluginVersion = "0.8.10"
}
repositories {
mavenCentral()
}
@@ -21,10 +17,29 @@ apply plugin: "com.google.protobuf"

dependencies {
api("com.google.protobuf:protobuf-java:$protobufVersion")
api("io.grpc:grpc-protobuf:$grpcVersion")
api("io.grpc:grpc-stub:$grpcVersion")
}

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:$protobufVersion"
}

plugins {
grpc { artifact = "io.grpc:protoc-gen-grpc-java:$grpcVersion" }
}

generateProtoTasks {
all()*.plugins { grpc {} }
}
}

sourceSets {
main {
java {
srcDirs("build/generated/source/proto/main/grpc")
srcDirs("build/generated/source/proto/main/java")
}
}
}
File renamed without changes.
@@ -7,4 +7,9 @@
dependencies {
implementation(project(":src:orbit-commons"))
implementation(project(":src:orbit-proto"))

implementation("org.kodein.di:kodein-di-erased-jvm:6.3.3")

implementation("io.grpc:grpc-netty-shaded:$grpcVersion")

}
@@ -0,0 +1,11 @@
/*
Copyright (C) 2015 - 2019 Electronic Arts Inc. All rights reserved.
This file is part of the Orbit Project <https://www.orbit.cloud>.
See license in LICENSE.
*/

package orbit.server

data class OrbitConfig(
val port: Int = 50056
)
@@ -7,10 +7,27 @@
package orbit.server

import orbit.common.logging.logger
import orbit.server.net.GrpcEndpoint
import org.kodein.di.Kodein
import org.kodein.di.erased.bind
import org.kodein.di.erased.instance
import org.kodein.di.erased.singleton

class OrbitServer(private val config: OrbitConfig) {
private val logger by logger()

private val kodein = Kodein {
bind<OrbitConfig>() with singleton { config }
bind<GrpcEndpoint>() with singleton { GrpcEndpoint(instance()) }
}

class OrbitServer {
val logger by logger()
fun start() {
logger.info("Starting Orbit...")

val endpoint: GrpcEndpoint by kodein.instance()

endpoint.start()

logger.info("Orbit started.")
}
}
@@ -0,0 +1,21 @@
/*
Copyright (C) 2015 - 2019 Electronic Arts Inc. All rights reserved.
This file is part of the Orbit Project <https://www.orbit.cloud>.
See license in LICENSE.
*/

package orbit.server.demo

import orbit.shared.proto.GreeterGrpc
import orbit.shared.proto.GreeterOuterClass

class GreeterImpl : GreeterGrpc.GreeterImplBase() {
override fun sayHello(
request: GreeterOuterClass.HelloRequest,
responseObserver: io.grpc.stub.StreamObserver<GreeterOuterClass.HelloReply>
) {
val reply = GreeterOuterClass.HelloReply.newBuilder().setMessage("Hello ${request.name}").build()
responseObserver.onNext(reply)
responseObserver.onCompleted()
}
}
@@ -0,0 +1,33 @@
/*
Copyright (C) 2015 - 2019 Electronic Arts Inc. All rights reserved.
This file is part of the Orbit Project <https://www.orbit.cloud>.
See license in LICENSE.
*/

package orbit.server.net

import io.grpc.Server
import io.grpc.ServerBuilder
import orbit.common.logging.logger
import orbit.server.OrbitConfig
import orbit.server.demo.GreeterImpl

class GrpcEndpoint(private val config: OrbitConfig) {
private lateinit var server: Server

private val logger by logger()

fun start() {
logger.info("Starting gRPC Endpoint on port ${config.port}...")

server = ServerBuilder.forPort(config.port)
.addService(GreeterImpl())
.build()
.start()

logger.info("gRPC Endpoint started on port ${config.port}.")

// TODO: We need to handle threading correctly and not block here
server.awaitTermination()
}
}

0 comments on commit b414c32

Please sign in to comment.
You can’t perform that action at this time.