Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Get orchestratorFactory method to OrchestratorFactory #124

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ class OrderService(private val orderOrchestrator: Orchestrator<Order, OrderRespo

// Register Orchestrator
@Configurer
class OrchestratorConfigurer(
private val orchestratorFactory: OrchestratorFactory
) {
class OrchestratorConfigurer {

private val orchestratorFactory = OrchestratorFactory.instance()

@Bean
fun orderOrchestartor(): Orchestrator<Order, OrderResponse> { // <First Request, Last Response>
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/org/rooftop/netx/api/OrchestratorFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ interface OrchestratorFactory {

fun <T : Any> create(orchestratorId: String): OrchestrateChain.Pre<T>

companion object Instance {
internal lateinit var orchestratorFactory: OrchestratorFactory

fun instance(): OrchestratorFactory = orchestratorFactory
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer, Integer> intOrchestrator() {
return orchestratorFactory.<Integer>create("intOrchestrator")
return OrchestratorFactory.Instance.instance().<Integer>create("intOrchestrator")
.start(
request -> request + 1,
request -> request - 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int, Int> {
return orchestratorFactory.create<Int>("sum3Orchestrator")
return OrchestratorFactory.instance().create<Int>("sum3Orchestrator")
.startReactive(MonoIntOrchestrator, rollback = { Mono.fromCallable { it - 1 } })
.joinReactive(MonoIntOrchestrator, rollback = { Mono.fromCallable { it - 1 } })
.commitReactiveWithContext({ _, request ->
Expand Down
33 changes: 15 additions & 18 deletions src/test/kotlin/org/rooftop/netx/engine/OrchestratorConfigurer.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<Int, Int> {
return orchestratorFactory.create<Int>("numberOrchestrator")
return OrchestratorFactory.instance().create<Int>("numberOrchestrator")
.start(orchestrate = { it + 1 })
.join(orchestrate = { it + 1 })
.joinReactive(orchestrate = { Mono.just(it + 1) })
Expand All @@ -29,7 +25,7 @@ internal class OrchestratorConfigurer(

@Bean(name = ["homeOrchestrator"])
fun homeOrchestrator(): Orchestrator<OrchestratorTest.Home, OrchestratorTest.Home> {
return orchestratorFactory.create<OrchestratorTest.Home>("homeOrchestrator")
return OrchestratorFactory.instance().create<OrchestratorTest.Home>("homeOrchestrator")
.startReactive({ home ->
Mono.fromCallable {
home.addPerson(OrchestratorTest.Person("Mother"))
Expand All @@ -50,14 +46,15 @@ internal class OrchestratorConfigurer(

@Bean(name = ["instantOrchestrator"])
fun instantOrchestrator(): Orchestrator<OrchestratorTest.InstantWrapper, OrchestratorTest.InstantWrapper> {
return orchestratorFactory.create<OrchestratorTest.InstantWrapper>("instantOrchestrator")
return OrchestratorFactory.instance()
.create<OrchestratorTest.InstantWrapper>("instantOrchestrator")
.start({ it })
.commit({ it })
}

@Bean(name = ["manyTypeOrchestrator"])
fun manyTypeOrchestrator(): Orchestrator<Int, OrchestratorTest.Home> {
return orchestratorFactory.create<Int>("manyTypeOrchestrator")
return OrchestratorFactory.instance().create<Int>("manyTypeOrchestrator")
.start({ "String" })
.join({ 1L })
.join({ 0.1 })
Expand All @@ -67,7 +64,7 @@ internal class OrchestratorConfigurer(

@Bean(name = ["rollbackOrchestrator"])
fun rollbackOrchestrator(): Orchestrator<String, String> {
return orchestratorFactory.create<String>("rollbackOrchestrator")
return OrchestratorFactory.instance().create<String>("rollbackOrchestrator")
.start(
orchestrate = {
rollbackOrchestratorResult.add("1")
Expand Down Expand Up @@ -100,7 +97,7 @@ internal class OrchestratorConfigurer(

@Bean(name = ["upChainRollbackOrchestrator"])
fun upChainRollbackOrchestrator(): Orchestrator<String, String> {
return orchestratorFactory.create<String>("upChainRollbackOrchestrator")
return OrchestratorFactory.instance().create<String>("upChainRollbackOrchestrator")
.start({ upChainResult.add("1") }, { upChainResult.add("-1") })
.join({ upChainResult.add("2") })
.join({ upChainResult.add("3") }, { upChainResult.add("-3") })
Expand All @@ -112,7 +109,7 @@ internal class OrchestratorConfigurer(

@Bean(name = ["monoRollbackOrchestrator"])
fun monoRollbackOrchestrator(): Orchestrator<String, String> {
return orchestratorFactory.create<String>("monoRollbackOrchestrator")
return OrchestratorFactory.instance().create<String>("monoRollbackOrchestrator")
.startReactive(
{ Mono.fromCallable { monoRollbackResult.add("1") } },
{ Mono.fromCallable { monoRollbackResult.add("-1") } }
Expand All @@ -132,7 +129,7 @@ internal class OrchestratorConfigurer(

@Bean(name = ["contextOrchestrator"])
fun contextOrchestrator(): Orchestrator<String, String> {
return orchestratorFactory.create<String>("contextOrchestrator")
return OrchestratorFactory.instance().create<String>("contextOrchestrator")
.startWithContext(
contextOrchestrate = { context, request ->
context.set("start-1", request)
Expand Down Expand Up @@ -180,7 +177,7 @@ internal class OrchestratorConfigurer(

@Bean(name = ["pairOrchestrator"])
fun pairOrchestrator(): Orchestrator<String, Pair<OrchestratorTest.Foo, OrchestratorTest.Foo>> {
return orchestratorFactory.create<String>("pairOrchestrator")
return OrchestratorFactory.instance().create<String>("pairOrchestrator")
.start({ OrchestratorTest.Foo(it) to OrchestratorTest.Foo(it) })
.join(PairOrchestrate, PairRollback)
.joinReactive(MonoPairOrchestrate, MonoPairRollback)
Expand All @@ -199,7 +196,7 @@ internal class OrchestratorConfigurer(

@Bean(name = ["startWithContextOrchestrator"])
fun startWithContextOrchestrator(): Orchestrator<String, String> {
return orchestratorFactory.create<String>("startWithContextOrchestrator")
return OrchestratorFactory.instance().create<String>("startWithContextOrchestrator")
.startWithContext({ context, _ ->
context.decodeContext("key", String::class)
})
Expand All @@ -210,7 +207,7 @@ internal class OrchestratorConfigurer(

@Bean(name = ["fooContextOrchestrator"])
fun fooContextOrchestrator(): Orchestrator<String, List<OrchestratorTest.Foo>> {
return orchestratorFactory.create<String>("fooContextOrchestrator")
return OrchestratorFactory.instance().create<String>("fooContextOrchestrator")
.startWithContext({ context, _ ->
val before = context.decodeContext("0", OrchestratorTest.Foo::class)
context.set("1", OrchestratorTest.Foo("startWithContext"))
Expand Down
Loading