From d8a7c5123a0bbb284989284341a674643ccdca48 Mon Sep 17 00:00:00 2001 From: devxb Date: Mon, 1 Apr 2024 10:40:30 +0900 Subject: [PATCH 1/2] feat: Get orchestratorFactory method to api.OrchestratorFactory --- .../rooftop/netx/api/OrchestratorFactory.kt | 5 +++ .../rooftop/netx/redis/RedisSagaConfigurer.kt | 2 +- .../javasupports/OrchestratorConfigurer.java | 6 +--- .../netx/client/OrchestratorConfigurer.kt | 6 ++-- .../netx/engine/OrchestratorConfigurer.kt | 33 +++++++++---------- 5 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/main/kotlin/org/rooftop/netx/api/OrchestratorFactory.kt b/src/main/kotlin/org/rooftop/netx/api/OrchestratorFactory.kt index fedb91a..c753e3a 100644 --- a/src/main/kotlin/org/rooftop/netx/api/OrchestratorFactory.kt +++ b/src/main/kotlin/org/rooftop/netx/api/OrchestratorFactory.kt @@ -6,4 +6,9 @@ interface OrchestratorFactory { fun create(orchestratorId: String): OrchestrateChain.Pre + companion object Instance { + internal lateinit var orchestratorFactory: OrchestratorFactory + + fun instance(): OrchestratorFactory = orchestratorFactory + } } diff --git a/src/main/kotlin/org/rooftop/netx/redis/RedisSagaConfigurer.kt b/src/main/kotlin/org/rooftop/netx/redis/RedisSagaConfigurer.kt index de90661..9fa72da 100644 --- a/src/main/kotlin/org/rooftop/netx/redis/RedisSagaConfigurer.kt +++ b/src/main/kotlin/org/rooftop/netx/redis/RedisSagaConfigurer.kt @@ -54,7 +54,7 @@ class RedisSagaConfigurer( codec = jsonCodec(), resultHolder = redisResultHolder(), requestHolder = redisRequestHolder(), - ) + ).apply { org.rooftop.netx.api.OrchestratorFactory.orchestratorFactory = this } @Bean @ConditionalOnProperty(prefix = "netx", name = ["mode"], havingValue = "redis") diff --git a/src/test/java/org/rooftop/netx/javasupports/OrchestratorConfigurer.java b/src/test/java/org/rooftop/netx/javasupports/OrchestratorConfigurer.java index c4726bd..55ede56 100644 --- a/src/test/java/org/rooftop/netx/javasupports/OrchestratorConfigurer.java +++ b/src/test/java/org/rooftop/netx/javasupports/OrchestratorConfigurer.java @@ -2,19 +2,15 @@ import org.rooftop.netx.api.Orchestrator; import org.rooftop.netx.api.OrchestratorFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class OrchestratorConfigurer { - @Autowired - private OrchestratorFactory orchestratorFactory; - @Bean public Orchestrator intOrchestrator() { - return orchestratorFactory.create("intOrchestrator") + return OrchestratorFactory.Instance.instance().create("intOrchestrator") .start( request -> request + 1, request -> request - 1 diff --git a/src/test/kotlin/org/rooftop/netx/client/OrchestratorConfigurer.kt b/src/test/kotlin/org/rooftop/netx/client/OrchestratorConfigurer.kt index 3db478b..da0cc2f 100644 --- a/src/test/kotlin/org/rooftop/netx/client/OrchestratorConfigurer.kt +++ b/src/test/kotlin/org/rooftop/netx/client/OrchestratorConfigurer.kt @@ -6,13 +6,11 @@ import org.rooftop.netx.api.OrchestratorFactory import org.springframework.context.annotation.Bean import reactor.core.publisher.Mono -internal class OrchestratorConfigurer( - private val orchestratorFactory: OrchestratorFactory, -) { +internal class OrchestratorConfigurer { @Bean fun sum3Orchestrator(): Orchestrator { - return orchestratorFactory.create("sum3Orchestrator") + return OrchestratorFactory.instance().create("sum3Orchestrator") .startReactive(MonoIntOrchestrator, rollback = { Mono.fromCallable { it - 1 } }) .joinReactive(MonoIntOrchestrator, rollback = { Mono.fromCallable { it - 1 } }) .commitReactiveWithContext({ _, request -> diff --git a/src/test/kotlin/org/rooftop/netx/engine/OrchestratorConfigurer.kt b/src/test/kotlin/org/rooftop/netx/engine/OrchestratorConfigurer.kt index 48ffbfc..d14eb48 100644 --- a/src/test/kotlin/org/rooftop/netx/engine/OrchestratorConfigurer.kt +++ b/src/test/kotlin/org/rooftop/netx/engine/OrchestratorConfigurer.kt @@ -1,9 +1,7 @@ package org.rooftop.netx.engine -import org.rooftop.netx.api.Orchestrate -import org.rooftop.netx.api.Orchestrator -import org.rooftop.netx.api.Rollback -import org.rooftop.netx.api.TypeReference +import org.rooftop.netx.api.* +import org.rooftop.netx.api.OrchestratorFactory import org.rooftop.netx.engine.OrchestratorTest.Companion.contextResult import org.rooftop.netx.engine.OrchestratorTest.Companion.monoRollbackResult import org.rooftop.netx.engine.OrchestratorTest.Companion.rollbackOrchestratorResult @@ -14,13 +12,11 @@ import reactor.core.publisher.Mono import java.time.Instant @Configuration -internal class OrchestratorConfigurer( - private val orchestratorFactory: OrchestratorFactory, -) { +internal class OrchestratorConfigurer { @Bean(name = ["numberOrchestrator"]) fun numberOrchestrator(): Orchestrator { - return orchestratorFactory.create("numberOrchestrator") + return OrchestratorFactory.instance().create("numberOrchestrator") .start(orchestrate = { it + 1 }) .join(orchestrate = { it + 1 }) .joinReactive(orchestrate = { Mono.just(it + 1) }) @@ -29,7 +25,7 @@ internal class OrchestratorConfigurer( @Bean(name = ["homeOrchestrator"]) fun homeOrchestrator(): Orchestrator { - return orchestratorFactory.create("homeOrchestrator") + return OrchestratorFactory.instance().create("homeOrchestrator") .startReactive({ home -> Mono.fromCallable { home.addPerson(OrchestratorTest.Person("Mother")) @@ -50,14 +46,15 @@ internal class OrchestratorConfigurer( @Bean(name = ["instantOrchestrator"]) fun instantOrchestrator(): Orchestrator { - return orchestratorFactory.create("instantOrchestrator") + return OrchestratorFactory.instance() + .create("instantOrchestrator") .start({ it }) .commit({ it }) } @Bean(name = ["manyTypeOrchestrator"]) fun manyTypeOrchestrator(): Orchestrator { - return orchestratorFactory.create("manyTypeOrchestrator") + return OrchestratorFactory.instance().create("manyTypeOrchestrator") .start({ "String" }) .join({ 1L }) .join({ 0.1 }) @@ -67,7 +64,7 @@ internal class OrchestratorConfigurer( @Bean(name = ["rollbackOrchestrator"]) fun rollbackOrchestrator(): Orchestrator { - return orchestratorFactory.create("rollbackOrchestrator") + return OrchestratorFactory.instance().create("rollbackOrchestrator") .start( orchestrate = { rollbackOrchestratorResult.add("1") @@ -100,7 +97,7 @@ internal class OrchestratorConfigurer( @Bean(name = ["upChainRollbackOrchestrator"]) fun upChainRollbackOrchestrator(): Orchestrator { - return orchestratorFactory.create("upChainRollbackOrchestrator") + return OrchestratorFactory.instance().create("upChainRollbackOrchestrator") .start({ upChainResult.add("1") }, { upChainResult.add("-1") }) .join({ upChainResult.add("2") }) .join({ upChainResult.add("3") }, { upChainResult.add("-3") }) @@ -112,7 +109,7 @@ internal class OrchestratorConfigurer( @Bean(name = ["monoRollbackOrchestrator"]) fun monoRollbackOrchestrator(): Orchestrator { - return orchestratorFactory.create("monoRollbackOrchestrator") + return OrchestratorFactory.instance().create("monoRollbackOrchestrator") .startReactive( { Mono.fromCallable { monoRollbackResult.add("1") } }, { Mono.fromCallable { monoRollbackResult.add("-1") } } @@ -132,7 +129,7 @@ internal class OrchestratorConfigurer( @Bean(name = ["contextOrchestrator"]) fun contextOrchestrator(): Orchestrator { - return orchestratorFactory.create("contextOrchestrator") + return OrchestratorFactory.instance().create("contextOrchestrator") .startWithContext( contextOrchestrate = { context, request -> context.set("start-1", request) @@ -180,7 +177,7 @@ internal class OrchestratorConfigurer( @Bean(name = ["pairOrchestrator"]) fun pairOrchestrator(): Orchestrator> { - return orchestratorFactory.create("pairOrchestrator") + return OrchestratorFactory.instance().create("pairOrchestrator") .start({ OrchestratorTest.Foo(it) to OrchestratorTest.Foo(it) }) .join(PairOrchestrate, PairRollback) .joinReactive(MonoPairOrchestrate, MonoPairRollback) @@ -199,7 +196,7 @@ internal class OrchestratorConfigurer( @Bean(name = ["startWithContextOrchestrator"]) fun startWithContextOrchestrator(): Orchestrator { - return orchestratorFactory.create("startWithContextOrchestrator") + return OrchestratorFactory.instance().create("startWithContextOrchestrator") .startWithContext({ context, _ -> context.decodeContext("key", String::class) }) @@ -210,7 +207,7 @@ internal class OrchestratorConfigurer( @Bean(name = ["fooContextOrchestrator"]) fun fooContextOrchestrator(): Orchestrator> { - return orchestratorFactory.create("fooContextOrchestrator") + return OrchestratorFactory.instance().create("fooContextOrchestrator") .startWithContext({ context, _ -> val before = context.decodeContext("0", OrchestratorTest.Foo::class) context.set("1", OrchestratorTest.Foo("startWithContext")) From aa7dc3e67358b893403d099cec51669529857269 Mon Sep 17 00:00:00 2001 From: devxb Date: Mon, 1 Apr 2024 10:43:09 +0900 Subject: [PATCH 2/2] docs: Autowired OrchestratorFactory to Instance OrchestratorFactory --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4ff315a..48ffb6b 100644 --- a/README.md +++ b/README.md @@ -78,9 +78,9 @@ class OrderService(private val orderOrchestrator: Orchestrator { //