Skip to content
Permalink
Browse files

gRPC code generation

  • Loading branch information...
JoeHegarty committed Aug 8, 2019
1 parent 95b2792 commit 5e33b639021fe927e1aa15f4c9a27289e09d8ea3
@@ -17,7 +17,11 @@ def publish = []
def localPublish = []

// Framework
configureProject(":src:orbit-commons", [withKotlin, withTests, publish])
configureProject(":src:orbit-server", [withKotlin, withTests, publish])
configureProject(":src:orbit-application", [withKotlin])
configureProject(":src:orbit-proto", [withJava])


buildscript {
ext.kotlinVersion = "1.3.41"
@@ -6,4 +6,7 @@

rootProject.name = "orbit"

include(":src:orbit-application")
include(":src:orbit-commons")
include(":src:orbit-server")
include(":src:orbit-application")
include(":src:orbit-proto")
@@ -7,3 +7,10 @@
apply plugin: "application"

mainClassName = "orbit.application.AppKt"

dependencies {
implementation(project(":src:orbit-server"))

// TODO: Probably want a better logger
implementation("org.slf4j:slf4j-simple:$slf4jVersion")
}
@@ -6,6 +6,9 @@

package orbit.application

fun main() {
import orbit.server.OrbitServer

fun main() {
val server = OrbitServer()
server.start()
}
@@ -0,0 +1,9 @@
/*
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.
*/

dependencies {
api("org.slf4j:slf4j-api:$slf4jVersion")
}
@@ -0,0 +1,127 @@
/*
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.common.logging

/**
* Logger API.
*/
interface Logger {
/**
* Determines whether TRACE level logging is enabled.
*/
val isTraceEnabled: Boolean

/**
* Determines whether DEBUG level logging is enabled.
*/
val isDebugEnabled: Boolean

/**
* Determines whether INFO level logging is enabled.
*/
val isInfoEnabled: Boolean

/**
* Determines whether WARN level logging is enabled.
*/
val isWarnEnabled: Boolean

/**
* Determines whether ERROR level logging is enabled.
*/
val isErrorEnabled: Boolean

/**
* Logs the specified message with the TRACE log level.
* @param msg The message.
* @param arg The arguments.
*/
fun trace(msg: String, vararg arg: Any?)

/**
* Logs the specified message with the DEBUG log level.
* @param msg The message.
* @param arg The arguments.
*/
fun debug(msg: String, vararg arg: Any?)

/**
* Logs the specified message with the INFO log level.
* @param msg The message.
* @param arg The arguments.
*/
fun info(msg: String, vararg arg: Any?)

/**
* Logs the specified message with the WARN log level.
* @param msg The message.
* @param arg The arguments.
*/
fun warn(msg: String, vararg arg: Any?)

/**
* Logs the specified message with the ERROR log level.
* @param msg The message.
* @param arg The arguments.
*/
fun error(msg: String, vararg arg: Any?)
}

/**
* Lazily logs the specified message with the TRACE log level.
* The message is only computed if the log level is enabled.
* @param msg The message.
*/
inline fun Logger.trace(msg: () -> String) {
if (isTraceEnabled) {
trace(msg())
}
}

/**
* Lazily logs the specified message with the DEBUG log level.
* The message is only computed if the log level is enabled.
* @param msg The message.
*/
inline fun Logger.debug(msg: () -> String) {
if (isDebugEnabled) {
debug(msg())
}
}

/**
* Lazily logs the specified message with the INFO log level.
* The message is only computed if the log level is enabled.
* @param msg The message.
*/
inline fun Logger.info(msg: () -> String) {
if (isInfoEnabled) {
info(msg())
}
}

/**
* Lazily logs the specified message with the WARN log level.
* The message is only computed if the log level is enabled.
* @param msg The message.
*/
inline fun Logger.warn(msg: () -> String) {
if (isWarnEnabled) {
warn(msg())
}
}

/**
* Lazily logs the specified message the ERROR log level.
* The message is only computed if the log level is enabled.
* @param msg The message.
*/
inline fun Logger.error(msg: () -> String) {
if (isErrorEnabled) {
error(msg())
}
}
@@ -0,0 +1,54 @@
/*
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.
*/

@file:JvmName("Logging")

package orbit.common.logging

import orbit.common.logging.impl.OrbitDefaultLogger
import kotlin.reflect.KClass
import org.slf4j.LoggerFactory as SLF4JLoggerFactory

/**
* Creates a [Logger] with the specified name.
* @param logName The name.
* @return The new [Logger].
*/
fun getLogger(logName: String): Logger =
OrbitDefaultLogger(SLF4JLoggerFactory.getLogger(logName))

/**
* Creates a [Logger] for the specified [Class].
* @param clazz The [Class].
* @return The new [Logger].
*/
fun getLogger(clazz: Class<*>): Logger =
OrbitDefaultLogger(SLF4JLoggerFactory.getLogger(clazz))

/**
* Creates a [Logger] for the specified [KClass].
* @param kClazz The [KClass].
* @return The new [Logger].
*/
fun getLogger(kClazz: KClass<*>): Logger = getLogger(kClazz.java)

/**
* Creates a [Logger] for the specified type.
* @param T The type.
* @return The new [Logger].
*/
inline fun <reified T> getLogger(): Logger = getLogger(T::class)

/**
* Creates a delegate [Logger] for the specified type.
* @param T The type.
* @return The new [Logger].
*/
inline fun <reified T> T.logger(): Lazy<Logger> {
return lazy {
getLogger<T>()
}
}
@@ -0,0 +1,66 @@
/*
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.common.logging

import org.slf4j.MDC

/**
* Provides structured logging features for Orbit when available in the
* underlying logging implementation.
*/
object LoggingContext {

/**
* Puts a context key with the specified value.
* @param key The key to set.
* @param value The value to set.
*/
@JvmStatic
fun put(key: String, value: String): Unit = MDC.put(key, value)


/**
* Puts a context key with the specified value.
* @param pair The key/value pair.
*/
@JvmStatic
fun put(pair: Pair<String, String>): Unit =
put(pair.first, pair.second)


/**
* Removes the specified context key.
* @param key The key to remove.
*/
@JvmStatic
fun remove(key: String): Unit = MDC.remove(key)

/**
* Clears all keys.
*/
@JvmStatic
fun clear(): Unit = MDC.clear()

/**
* Gets the specified context key.
* @param key The key to get.
* @return The key value.
*/
@JvmStatic
fun get(key: String): String? = MDC.get(key)

/**
* Gets all current keys.
* @return Map of the keys.
*/
@JvmStatic
fun getAll(): Map<String, String?> = MDC.getCopyOfContextMap()
}

inline fun loggingContext(body: LoggingContext.() -> Unit) {
body(LoggingContext)
}
@@ -0,0 +1,47 @@
/*
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.common.logging.impl

import orbit.common.logging.Logger
import org.slf4j.Logger as SLF4JLogger

internal class OrbitDefaultLogger(private val loggerWrapper: SLF4JLogger) : Logger {
override val isTraceEnabled: Boolean
get() = loggerWrapper.isTraceEnabled

override val isDebugEnabled: Boolean
get() = loggerWrapper.isDebugEnabled

override val isInfoEnabled: Boolean
get() = loggerWrapper.isInfoEnabled

override val isWarnEnabled: Boolean
get() = loggerWrapper.isWarnEnabled

override val isErrorEnabled: Boolean
get() = loggerWrapper.isErrorEnabled

override fun trace(msg: String, vararg arg: Any?) {
loggerWrapper.trace(msg, *arg)
}

override fun debug(msg: String, vararg arg: Any?) {
loggerWrapper.debug(msg, *arg)
}

override fun info(msg: String, vararg arg: Any?) {
loggerWrapper.info(msg, *arg)
}

override fun warn(msg: String, vararg arg: Any?) {
loggerWrapper.warn(msg, *arg)
}

override fun error(msg: String, vararg arg: Any?) {
loggerWrapper.error(msg, *arg)
}
}
@@ -0,0 +1,30 @@
/*
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.
*/

buildscript {
ext {
protobufVersion = "3.9.1"
protobufPluginVersion = "0.8.10"
}
repositories {
mavenCentral()
}
dependencies {
classpath("com.google.protobuf:protobuf-gradle-plugin:$protobufPluginVersion")
}
}

apply plugin: "com.google.protobuf"

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

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

0 comments on commit 5e33b63

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