-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat: Bind values to context in Orchestrator (#106)
* refactor: Orchestrate와 Rollback 인터페이스에 Function을 제거한다 * feat: Context binding in orchestrator * docs: Netx version 0.3.3 to 0.3.4
Showing
31 changed files
with
789 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.rooftop.netx.api | ||
|
||
import kotlin.reflect.KClass | ||
|
||
data class Context internal constructor( | ||
private val codec: Codec, | ||
internal val contexts: MutableMap<String, String>, | ||
) { | ||
|
||
fun <T : Any> set(key: String, value: T) { | ||
contexts[key] = codec.encode(value) | ||
} | ||
|
||
fun <T : Any> decodeContext(key: String, type: Class<T>): T = decodeContext(key, type.kotlin) | ||
|
||
fun <T : Any> decodeContext(key: String, type: KClass<T>): T = contexts[key]?.let { | ||
codec.decode(it, type) | ||
} ?: throw NullPointerException("Cannot find context by key \"$key\"") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.rooftop.netx.api | ||
|
||
fun interface ContextOrchestrate<T : Any, V : Any> { | ||
|
||
fun orchestrate(context: Context, request: T): V | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.rooftop.netx.api | ||
|
||
fun interface ContextRollback<T : Any, V : Any?> { | ||
|
||
fun rollback(context: Context, request: T): V | ||
} |
2 changes: 1 addition & 1 deletion
2
...g/rooftop/netx/api/OrchestrateFunction.kt → ...otlin/org/rooftop/netx/api/Orchestrate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package org.rooftop.netx.api | ||
|
||
fun interface OrchestrateFunction<T : Any, V : Any> { | ||
fun interface Orchestrate<T : Any, V : Any> { | ||
|
||
fun orchestrate(request: T): V | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../org/rooftop/netx/api/RollbackFunction.kt → ...n/kotlin/org/rooftop/netx/api/Rollback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package org.rooftop.netx.api | ||
|
||
fun interface RollbackFunction<T : Any, V : Any?> { | ||
fun interface Rollback<T : Any, V : Any?> { | ||
|
||
fun rollback(request: T): V | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.rooftop.netx.api | ||
|
||
import java.lang.reflect.ParameterizedType | ||
import java.lang.reflect.Type | ||
|
||
|
||
abstract class TypeReference<T : Any>() { | ||
val type: Type | ||
|
||
init { | ||
val superClass: Type = this.javaClass.genericSuperclass | ||
type = (superClass as ParameterizedType).actualTypeArguments[0] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
407 changes: 298 additions & 109 deletions
407
src/main/kotlin/org/rooftop/netx/engine/DefaultOrchestrateChain.kt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/org/rooftop/netx/engine/listen/CommandType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.rooftop.netx.engine.listen | ||
|
||
enum class CommandType { | ||
DEFAULT, | ||
CONTEXT, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/org/rooftop/netx/engine/listen/MonoOrchestrateCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.rooftop.netx.engine.listen | ||
|
||
import org.rooftop.netx.api.* | ||
import reactor.core.publisher.Mono | ||
|
||
class MonoOrchestrateCommand<T : Any, V : Any>( | ||
private val commandType: CommandType = CommandType.DEFAULT, | ||
private val codec: Codec, | ||
private val command: Any | ||
) { | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun command( | ||
request: T, | ||
contextData: String, | ||
): Mono<Pair<V, Context>> { | ||
val context = Context( | ||
codec, | ||
codec.decode(contextData, object : TypeReference<MutableMap<String, String>>() {}) | ||
) | ||
return when (commandType) { | ||
CommandType.DEFAULT -> (command as Orchestrate<T, Mono<V>>).orchestrate(request) | ||
|
||
CommandType.CONTEXT -> (command as ContextOrchestrate<T, Mono<V>>).orchestrate( | ||
context, | ||
request, | ||
) | ||
}.map { | ||
it to context | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/kotlin/org/rooftop/netx/engine/listen/MonoRollbackCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.rooftop.netx.engine.listen | ||
|
||
import org.rooftop.netx.api.* | ||
import reactor.core.publisher.Mono | ||
|
||
class MonoRollbackCommand<T : Any>( | ||
private val commandType: CommandType = CommandType.DEFAULT, | ||
private val codec: Codec, | ||
private val command: Any | ||
) { | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun command( | ||
request: T, | ||
contextData: String, | ||
): Mono<Pair<Any?, Context>> { | ||
val context = Context( | ||
codec, | ||
codec.decode(contextData, object : TypeReference<MutableMap<String, String>>() {}) | ||
) | ||
return when (commandType) { | ||
CommandType.DEFAULT -> (command as Rollback<T, Mono<Any?>>).rollback(request) | ||
|
||
CommandType.CONTEXT -> (command as ContextRollback<T, Mono<Any?>>).rollback( | ||
context, | ||
request, | ||
) | ||
}.map { it to context } | ||
.switchIfEmpty(Mono.just("ROLLBACK SUCCESS" to context)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/org/rooftop/netx/engine/listen/OrchestrateCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.rooftop.netx.engine.listen | ||
|
||
import org.rooftop.netx.api.* | ||
|
||
internal class OrchestrateCommand<T : Any, V : Any>( | ||
private val commandType: CommandType = CommandType.DEFAULT, | ||
private val codec: Codec, | ||
private val command: Any | ||
) { | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun command( | ||
request: T, | ||
contextData: String, | ||
): Pair<V, Context> { | ||
val context = Context( | ||
codec, | ||
codec.decode(contextData, object : TypeReference<MutableMap<String, String>>() {}) | ||
) | ||
return when (commandType) { | ||
CommandType.DEFAULT -> (command as Orchestrate<T, V>).orchestrate(request) | ||
|
||
CommandType.CONTEXT -> (command as ContextOrchestrate<T, V>).orchestrate( | ||
context, | ||
request, | ||
) | ||
} to context | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/org/rooftop/netx/engine/listen/RollbackCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.rooftop.netx.engine.listen | ||
|
||
import org.rooftop.netx.api.* | ||
|
||
class RollbackCommand<T : Any>( | ||
private val commandType: CommandType = CommandType.DEFAULT, | ||
private val codec: Codec, | ||
private val command: Any | ||
) { | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun command( | ||
request: T, | ||
contextData: String, | ||
): Pair<Any?, Context> { | ||
val context = Context( | ||
codec, | ||
codec.decode(contextData, object : TypeReference<MutableMap<String, String>>() {}) | ||
) | ||
return when (commandType) { | ||
CommandType.DEFAULT -> (command as Rollback<T, *>).rollback(request) | ||
|
||
CommandType.CONTEXT -> (command as ContextRollback<T, *>).rollback( | ||
context, | ||
request, | ||
) | ||
} to context | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters