Skip to content

Commit

Permalink
Merge pull request #86 from cloudoptlab/3.x
Browse files Browse the repository at this point in the history
The version of the 3.1.0.0 release now,see the document for more details.
  • Loading branch information
T-baby authored Sep 21, 2022
2 parents abb891d + 5303985 commit 63df760
Show file tree
Hide file tree
Showing 118 changed files with 1,802 additions and 1,034 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![image.png](https://cdn.nlark.com/yuque/0/2020/png/85774/1596081097483-df48c14a-e8c6-4e49-98b7-88ec5334308c.png#align=left&display=inline&height=20&margin=%5Bobject%20Object%5D&name=image.png&originHeight=20&originWidth=98&size=2011&status=done&style=none&width=98) [![image.png](https://cdn.nlark.com/yuque/0/2020/png/85774/1596081503933-8696c94f-517e-4913-88f9-94cfb199f2f8.png#align=left&display=inline&height=20&margin=%5Bobject%20Object%5D&name=image.png&originHeight=20&originWidth=110&size=1557&status=done&style=none&width=110)](https://github.com/vert-x3/vertx-awesome) [![](https://cdn.nlark.com/yuque/0/2020/svg/85774/1596081628915-65fb4c2a-8aa6-432b-b13a-cf0f0193333e.svg#align=left&display=inline&height=20&margin=%5Bobject%20Object%5D&originHeight=20&originWidth=102&size=0&status=done&style=none&width=102)](https://github.com/KotlinBy/awesome-kotlin)

[Cloudopt Next](https://next.cloudopt.net/) is a very lightweight and modern, JVM-based, full stack kotlin framework
[Cloudopt Next](https://github.com/cloudoptlab/cloudopt-next/) is a very lightweight and modern, JVM-based, full stack kotlin framework
designed for building modular, easily testable JVM applications with support for Java, Kotlin language, crafted from the
best of breed Java libraries and standards.

Expand Down
7 changes: 2 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
plugins {
id "java"
id "org.jetbrains.kotlin.jvm" version "1.5.0"
id("org.jetbrains.dokka") version "1.4.30"
id "org.jetbrains.kotlin.jvm" version "1.6.0"
id "org.jetbrains.dokka" version "1.4.30"
}

allprojects {
group = "net.cloudopt.next"
version = property("project_version")
sourceCompatibility = property("java_version")
repositories {
maven { url "https://maven.aliyun.com/nexus/content/repositories/central/" }
maven { url "https://maven.aliyun.com/nexus/content/groups/public" }
mavenCentral()
}
}
Expand All @@ -19,7 +17,6 @@ subprojects {

buildscript {
repositories {
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' }
gradlePluginPortal()
}
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/
package net.cloudopt.next.core

import net.cloudopt.next.json.Jsoner.jsonToMutableMap
import com.fasterxml.jackson.databind.ObjectMapper
import io.vertx.core.json.JsonObject
import net.cloudopt.next.json.Jsoner.jsonToObject
import net.cloudopt.next.json.Jsoner.toJsonObject
import net.cloudopt.next.json.Jsoner.toJsonString
Expand All @@ -28,6 +29,7 @@ import java.nio.file.Files
import kotlin.io.path.Path
import kotlin.reflect.KClass


object Resourcer {

private var rootPath: String = ""
Expand Down Expand Up @@ -147,13 +149,7 @@ object Resourcer {
* @return MutableMap<String, Any>
*/
fun read(fileName: String, external: Boolean = false): MutableMap<String, Any> {
var jsonString = if (external) {
getExternalFileString(fileName)
} else {
inputStreamToString(getFileInputStream(fileName))
}
jsonString = cleanText(jsonString)
return jsonString.jsonToMutableMap()
return read(fileName, "", external)
}

/**
Expand All @@ -164,13 +160,13 @@ object Resourcer {
* @return MutableMap<String, Any>
*/
fun read(fileName: String, prefix: String, external: Boolean = false): MutableMap<String, Any> {
var jsonString = if (external) {
getExternalFileString(fileName)
val objMap = ObjectMapper()
var file = if (external) {
File(fileName)
} else {
inputStreamToString(getFileInputStream(fileName))
getFile(fileName)
}
jsonString = cleanText(jsonString)
var jsonObj = jsonString.toJsonObject()
var jsonObj = objMap.readTree(file).toJsonString().toJsonObject()
var list = prefix.split(".")
for (key in list) {
if (jsonObj.getJsonObject(key) != null) {
Expand All @@ -180,13 +176,4 @@ object Resourcer {
return jsonObj.map.toMutableMap()
}

/**
* Clear out the extra carriage return characters.
* @param jsonString String
* @return String
*/
private fun cleanText(jsonString: String): String {
return jsonString.replace("/n", "")
}

}
41 changes: 22 additions & 19 deletions cloudopt-next-core/src/main/kotlin/net/cloudopt/next/core/Worker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package net.cloudopt.next.core

import io.vertx.core.*
import io.vertx.kotlin.coroutines.await
import io.vertx.kotlin.coroutines.awaitBlocking
import io.vertx.kotlin.coroutines.dispatcher
import kotlinx.coroutines.*

Expand Down Expand Up @@ -73,21 +74,6 @@ object Worker {
}
}

/**
* Runs a new coroutine and blocks the current thread interruptibly until its completion. This function should not
* be used from a coroutine. It is designed to bridge regular blocking code to libraries that are written in
* suspending style, to be used in main functions and in tests.
* @param block [@kotlin.ExtensionFunctionType] SuspendFunction1<CoroutineScope, T>
* @return T
*/
fun <T> async(block: suspend CoroutineScope.() -> T): T {
return runBlocking(dispatcher()) {
return@runBlocking withContext(dispatcher()) {
return@withContext block.invoke(this)
}
}
}

/**
* Puts the handler on the event queue for the current context so it will be run asynchronously ASAP after all
* preceeding events have been handled.
Expand All @@ -98,20 +84,37 @@ object Worker {
vertx.runOnContext(block)
}

/**
* Awaits for completion of given deferred values without blocking a thread and resumes normally with the list of values
* when all deferred computations are complete or resumes with the first thrown exception if any of computations
* complete exceptionally including cancellation.
*/
suspend fun <T> gather(vararg blocks: suspend CoroutineScope.() -> T): List<T> {
val list = mutableListOf<Deferred<T>>()
coroutineScope {
blocks.forEach { block ->
list.add(async {
return@async block.invoke(this)
})
}
}
return list.awaitAll()
}

/**
* Automatic deployment in vertx.
*
* @param verticle Package name
* @param name Package name
* @param deploymentOptions Options for configuring a verticle deployment
*/
@JvmOverloads
fun deploy(
verticle: String,
name: String,
deploymentOptions: DeploymentOptions = ConfigManager.init("vertxDeployment")
.toObject(DeploymentOptions::class), workerPoolName: String = "net.cloudopt.next"
) {
deploymentOptions.workerPoolName = workerPoolName
vertx.deployVerticle(verticle, deploymentOptions)
vertx.deployVerticle(name, deploymentOptions)
}


Expand Down Expand Up @@ -167,7 +170,7 @@ object Worker {
}

/**
* Stop the the Vertx instance and release any resources held by it. The instance cannot be used after it has been
* Stop the Vertx instance and release any resources held by it. The instance cannot be used after it has been
* closed.
*/
fun close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package net.cloudopt.next.core.test

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import net.cloudopt.next.core.Worker
import net.cloudopt.next.core.Worker.async
import net.cloudopt.next.core.Worker.await
import net.cloudopt.next.core.Worker.cancelTimer
import net.cloudopt.next.core.Worker.gather
import net.cloudopt.next.core.Worker.global
import net.cloudopt.next.core.Worker.setTimer
import net.cloudopt.next.core.Worker.then
Expand Down Expand Up @@ -77,26 +78,48 @@ class TestWorker {
}
}

@Test
fun testAsync() {
val text = async {
return@async "success"
}
assert(text == "success")
}

@Test
fun testAsyncFunction() {
val text = asyncFunction()
assert(text == "success")
}

private fun asyncFunction(): String = async {
return@async await {
private fun asyncFunction(): String = runBlocking {
return@runBlocking await {
return@await "success"
}
}

suspend fun taskA(): Int {
delay(5000)
return 1
}

suspend fun taskB(): Int {
delay(5000)
return 2
}

@Test
fun testGather(): Unit = runBlocking {
assert(gather<Int>(
{
await {
return@await 1
}
},
{
await {
return@await 2
}
}
).sum() == 3)
val startTime = System.currentTimeMillis()
assert(gather({ taskA() }, { taskB() }).sum() == 3)
val endTime = System.currentTimeMillis()
assert((endTime - startTime) in 5000..6000)
}

@Test
fun testWorker() {
worker<String>({ promise ->
Expand Down Expand Up @@ -127,10 +150,11 @@ class TestWorker {
@Test
fun testTimer() {
assertDoesNotThrow {
val i = 0
var i = 0
var id: Long = -1
setTimer(100, true) { timerId ->
id = timerId
i = i + 1
if (i > 3) {
cancelTimer(id)
}
Expand Down
4 changes: 2 additions & 2 deletions cloudopt-next-logging/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies {
implementation "org.fusesource.jansi:jansi:1.18"
implementation "ch.qos.logback:logback-classic:1.2.3"
implementation 'org.fusesource.jansi:jansi:2.4.0'
implementation 'ch.qos.logback:logback-classic:1.2.11'
}

description = "Cloudopt Next Log"

This file was deleted.

Loading

0 comments on commit 63df760

Please sign in to comment.