Skip to content

Commit 58995b7

Browse files
committed
v2.0.0-RC0
1 parent cec06c1 commit 58995b7

File tree

16 files changed

+266
-77
lines changed

16 files changed

+266
-77
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=2.0.0-ALPHA
1+
version=2.0.0-RC0
22
group=io.github.numichi
33
developerId=numichi
44
developerName=Donát Csongor
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.github.numichi.reactive.logger
2+
3+
import io.github.numichi.reactive.logger.coroutine.readMDCResult
4+
import io.github.numichi.reactive.logger.exception.ContextNotExistException
5+
import io.github.numichi.reactive.logger.exception.InvalidContextDataException
6+
import io.github.numichi.reactive.logger.reactor.MDCSnapshot
7+
import reactor.core.scheduler.Scheduler
8+
import reactor.util.context.ContextView
9+
import java.util.*
10+
11+
interface ICore {
12+
val isEnableError: Boolean
13+
val mdcContextKey: String
14+
val scheduler: Scheduler
15+
val name: String
16+
17+
fun readMDC(context: ContextView): Optional<Map<String, String>> {
18+
return Optional.ofNullable(readMDCResult(context, mdcContextKey).getOrNull())
19+
}
20+
21+
@Throws(ContextNotExistException::class, InvalidContextDataException::class)
22+
fun takeMDCSnapshot(context: ContextView): MDCSnapshot {
23+
val result = readMDCResult(context, mdcContextKey)
24+
25+
return when {
26+
result.isSuccess -> MDCSnapshot.of(result.getOrNull())
27+
result.isFailure && !isEnableError -> MDCSnapshot.empty()
28+
else -> throw result.exceptionOrNull()!!
29+
}
30+
}
31+
}

src/main/java/io/github/numichi/reactive/logger/abstracts/ICore.kt

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/main/java/io/github/numichi/reactive/logger/abstracts/ACoroutine.kt renamed to src/main/java/io/github/numichi/reactive/logger/coroutine/ACoroutine.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
package io.github.numichi.reactive.logger.abstracts
1+
package io.github.numichi.reactive.logger.coroutine
22

3-
import io.github.numichi.reactive.logger.coroutine.CCElement
4-
import io.github.numichi.reactive.logger.coroutine.CCKey
5-
import io.github.numichi.reactive.logger.coroutine.CCResolveFn
6-
import io.github.numichi.reactive.logger.coroutine.ICoroutineCore
73
import io.github.numichi.reactive.logger.reactor.IReactorLogger
84
import org.slf4j.Logger
95
import reactor.core.scheduler.Scheduler

src/main/java/io/github/numichi/reactive/logger/coroutine/CoroutineKLogger.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.github.numichi.reactive.logger.coroutine
22

33
import io.github.numichi.reactive.logger.DefaultValues
4-
import io.github.numichi.reactive.logger.abstracts.ACoroutine
54
import io.github.numichi.reactive.logger.reactor.IReactorKLogger
65
import io.github.numichi.reactive.logger.reactor.ReactiveKLogger
76
import io.github.numichi.reactive.logger.reactor.ReactiveLogger

src/main/java/io/github/numichi/reactive/logger/coroutine/CoroutineLogger.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.github.numichi.reactive.logger.coroutine
22

33
import io.github.numichi.reactive.logger.DefaultValues
4-
import io.github.numichi.reactive.logger.abstracts.ACoroutine
54
import io.github.numichi.reactive.logger.reactor.IReactorLogger
65
import io.github.numichi.reactive.logger.reactor.ReactiveLogger
76
import kotlinx.coroutines.reactor.ReactorContext

src/main/java/io/github/numichi/reactive/logger/coroutine/ICoroutineCore.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package io.github.numichi.reactive.logger.coroutine
22

33
import io.github.numichi.reactive.logger.MDC
4-
import io.github.numichi.reactive.logger.abstracts.ICore
4+
import io.github.numichi.reactive.logger.ICore
5+
import io.github.numichi.reactive.logger.exception.ContextNotExistException
6+
import io.github.numichi.reactive.logger.exception.InvalidContextDataException
57
import io.github.numichi.reactive.logger.reactor.IReactorLogger
68
import kotlinx.coroutines.reactor.ReactorContext
79
import kotlinx.coroutines.reactor.awaitSingle
810
import kotlinx.coroutines.reactor.awaitSingleOrNull
911
import reactor.core.publisher.Mono
1012
import reactor.util.context.Context
13+
import reactor.util.context.ContextView
1114
import kotlin.coroutines.coroutineContext
1215

1316
interface ICoroutineCore<T : IReactorLogger> : ICore {
@@ -18,7 +21,8 @@ interface ICoroutineCore<T : IReactorLogger> : ICore {
1821
override val name: String
1922
get() = reactorLogger.name
2023

21-
suspend fun snapshot(context: Context? = null): MDC? {
24+
@Throws(ContextNotExistException::class, InvalidContextDataException::class)
25+
suspend fun snapshot(context: ContextView? = null): MDC? {
2226
val ctx = context ?: coroutineContext[ReactorContext]?.context
2327
return ctx?.let { reactorLogger.snapshot(it).awaitSingleOrNull() }
2428
}

src/main/java/io/github/numichi/reactive/logger/coroutine/readMDC.kt

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,59 @@ package io.github.numichi.reactive.logger.coroutine
22

33
import io.github.numichi.reactive.logger.DefaultValues
44
import io.github.numichi.reactive.logger.MDC
5+
import io.github.numichi.reactive.logger.exception.ContextNotExistException
56
import io.github.numichi.reactive.logger.exception.InvalidContextDataException
67
import reactor.util.context.ContextView
78

8-
suspend fun readMDC(): MDC {
9-
return readMDC(DefaultValues.getInstance().defaultReactorContextMdcKey)
9+
@Throws(ContextNotExistException::class, InvalidContextDataException::class)
10+
suspend fun readMdc(): MDC {
11+
return readMdc(DefaultValues.getInstance().defaultReactorContextMdcKey)
1012
}
1113

12-
suspend fun readMDC(mdcContextKey: String): MDC {
13-
return readMDC(rectorContext(), mdcContextKey)
14+
@Throws(ContextNotExistException::class, InvalidContextDataException::class)
15+
suspend fun readMdc(mdcContextKey: String): MDC {
16+
return readMdc(rectorContext(), mdcContextKey)
1417
}
1518

16-
fun readMDC(contextView: ContextView?): MDC {
17-
return readMDC(contextView, DefaultValues.getInstance().defaultReactorContextMdcKey)
19+
@Throws(ContextNotExistException::class, InvalidContextDataException::class)
20+
fun readMdc(contextView: ContextView?): MDC {
21+
return readMdc(contextView, DefaultValues.getInstance().defaultReactorContextMdcKey)
1822
}
1923

20-
fun readMDC(contextView: ContextView?, mdcContextKey: String): MDC {
24+
@Throws(ContextNotExistException::class, InvalidContextDataException::class)
25+
fun readMdc(contextView: ContextView?, mdcContextKey: String): MDC {
2126
requireNotNull(contextView) { "contentView must not be null" }
2227

2328
val mdc = MDC(mdcContextKey)
2429

2530
try {
2631
val map: Map<String, String> = contextView.get(mdcContextKey)
2732
mdc.putAll(map)
33+
} catch (noSuchException: NoSuchElementException) {
34+
throw ContextNotExistException("\"$mdcContextKey\" context not found", noSuchException)
2835
} catch (exception: Exception) {
2936
throw InvalidContextDataException(exception)
3037
}
3138

3239
return mdc
40+
}
41+
42+
suspend fun readMdcOrNull(): MDC? {
43+
return readMdcOrNull(DefaultValues.getInstance().defaultReactorContextMdcKey)
44+
}
45+
46+
suspend fun readMdcOrNull(mdcContextKey: String): MDC? {
47+
return readMdcOrNull(rectorContext(), mdcContextKey)
48+
}
49+
50+
fun readMdcOrNull(contextView: ContextView?): MDC? {
51+
return readMdcOrNull(contextView, DefaultValues.getInstance().defaultReactorContextMdcKey)
52+
}
53+
54+
fun readMdcOrNull(contextView: ContextView?, mdcContextKey: String): MDC? {
55+
return readMDCResult(contextView, mdcContextKey).getOrNull()
56+
}
57+
58+
fun readMDCResult(contextView: ContextView?, mdcContextKey: String): Result<MDC> {
59+
return runCatching { readMdc(contextView, mdcContextKey) }
3360
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package io.github.numichi.reactive.logger.exception;
22

3-
class ContextNotExistException(message: String) : RuntimeException(message)
3+
class ContextNotExistException(message: String, throwable: Throwable) : RuntimeException(message, throwable)

src/main/java/io/github/numichi/reactive/logger/abstracts/AReactive.kt renamed to src/main/java/io/github/numichi/reactive/logger/reactor/AReactive.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package io.github.numichi.reactive.logger.abstracts
1+
package io.github.numichi.reactive.logger.reactor
22

3-
import io.github.numichi.reactive.logger.reactor.IReactorCore
43
import org.slf4j.Logger
54
import reactor.core.scheduler.Scheduler
65

0 commit comments

Comments
 (0)