@@ -38,32 +38,32 @@ class ActionExecutor(
3838 private val eventHandler : StateMachine .StateMachineEventHandler ,
3939 private val coroutineScope : CoroutineScope ,
4040) {
41- fun execute (spec : Action , scope : Scope ): List <Action > =
42- when (spec ) {
43- is Invoke -> executeInvoke(spec , scope)
44- is Eval -> executeEval(spec , scope)
45- is Emit -> executeEmit(spec , scope)
46- is Timeout -> listOf (spec .triggers)
41+ fun execute (specification : Action , scope : Scope ): List <Action > =
42+ when (specification ) {
43+ is Invoke -> executeInvoke(specification , scope)
44+ is Eval -> executeEval(specification , scope)
45+ is Emit -> executeEmit(specification , scope)
46+ is Timeout -> listOf (specification .triggers)
4747 is Reset -> emptyList()
48- is Match -> executeMatch(spec , scope)
49- is Log -> executeLog(spec , scope)
50- is Instantiate -> executeInstantiate(spec , scope)
51- is Ctr -> executeCtr(spec , scope)
52- else -> error(" unknown action type '${spec ::class .simpleName} '" )
48+ is Match -> executeMatch(specification , scope)
49+ is Log -> executeLog(specification , scope)
50+ is Instantiate -> executeInstantiate(specification , scope)
51+ is Ctr -> executeCtr(specification , scope)
52+ else -> error(" unknown action type '${specification ::class .simpleName} '" )
5353 }
5454
55- private fun executeInvoke (spec : Invoke , scope : Scope ): List <Action > {
55+ private fun executeInvoke (specification : Invoke , scope : Scope ): List <Action > {
5656 val service =
57- selector.select(spec .type, spec .mode)
58- ? : error(" no service implementation found for type '${spec .type} '" )
57+ selector.select(specification .type, specification .mode)
58+ ? : error(" no service implementation found for type '${specification .type} '" )
5959
60- val input = spec .input.map { it.evaluate(scope.extent) }
60+ val input = specification .input.map { it.evaluate(scope.extent) }
6161
6262 coroutineScope.launch {
6363 val delta = measureTime {
6464 runCatching { service.invoke(input) }
6565 .onSuccess { output ->
66- spec .output.forEach { reference ->
66+ specification .output.forEach { reference ->
6767 output
6868 .firstOrNull { it.name == reference }
6969 ?.let {
@@ -79,7 +79,7 @@ class ActionExecutor(
7979 }
8080 }
8181
82- spec .emits.forEach { conditionalEvent ->
82+ specification .emits.forEach { conditionalEvent ->
8383 val shouldEmit = conditionalEvent.provided?.evaluate(scope.extent) ? : true
8484
8585 if (shouldEmit != false ) {
@@ -100,21 +100,22 @@ class ActionExecutor(
100100 return emptyList()
101101 }
102102
103- private fun executeEval (spec : Eval , scope : Scope ): List <Action > {
104- spec .expression.evaluate(scope.extent)
103+ private fun executeEval (specification : Eval , scope : Scope ): List <Action > {
104+ specification .expression.evaluate(scope.extent)
105105 return emptyList()
106106 }
107107
108- private fun executeEmit (spec : Emit , scope : Scope ): List <Action > {
108+ private fun executeEmit (specification : Emit , scope : Scope ): List <Action > {
109109 val emittedEvent =
110- spec .event.run {
110+ specification .event.run {
111111 val evaluatedData =
112112 data.map { item ->
113113 if (item is LazyContextVariable ) item.evaluate(scope.extent) else item
114114 }
115115
116116 copy(data = evaluatedData).let { eventWithData ->
117- val target = spec.target?.let { source -> source.evaluate(scope.extent) as ? String }
117+ val target =
118+ specification.target?.let { source -> source.evaluate(scope.extent) as ? String }
118119
119120 if (target != null ) eventWithData.copy(target = target) else eventWithData
120121 }
@@ -128,19 +129,19 @@ class ActionExecutor(
128129 return emptyList()
129130 }
130131
131- private fun executeMatch (spec : Match , scope : Scope ): List <Action > =
132- spec .cases.entries
132+ private fun executeMatch (specification : Match , scope : Scope ): List <Action > =
133+ specification .cases.entries
133134 .filter { (expression, _) -> expression.evaluate(scope.extent) == true }
134135 .flatMap { it.value }
135- .ifEmpty { listOfNotNull(spec .default) }
136+ .ifEmpty { listOfNotNull(specification .default) }
136137
137138 private fun executeLog (spec : Log , scope : Scope ): List <Action > {
138139 spec.message.evaluate(scope.extent).toString().also { logger.info(it) }
139140 return emptyList()
140141 }
141142
142- private fun executeInstantiate (spec : Instantiate , scope : Scope ): List <Action > {
143- val instances = spec .instances.map { it.evaluate(scope.extent).getOrThrow() }
143+ private fun executeInstantiate (specification : Instantiate , scope : Scope ): List <Action > {
144+ val instances = specification .instances.map { it.evaluate(scope.extent).getOrThrow() }
144145
145146 instances.forEach {
146147 val instanceData = it.data.map { (k, v) -> ContextVariable (k, v.evaluate(scope.extent)) }
@@ -151,20 +152,20 @@ class ActionExecutor(
151152 return emptyList()
152153 }
153154
154- private fun executeCtr (spec : Ctr , scope : Scope ): List <Action > {
155+ private fun executeCtr (specification : Ctr , scope : Scope ): List <Action > {
155156 val tags =
156- spec .tags?.entries?.joinToString(" ." ) { (key, value) ->
157+ specification .tags?.entries?.joinToString(" ." ) { (key, value) ->
157158 " $key =${value.evaluate(scope.extent)} "
158159 } ? : " "
159160
160161 val name =
161162 if (tags.isEmpty()) {
162- spec .counter
163+ specification .counter
163164 } else {
164- " ${spec .counter} .$tags "
165+ " ${specification .counter} .$tags "
165166 }
166167
167- metricRegistry.counter(name).inc(spec .by)
168+ metricRegistry.counter(name).inc(specification .by)
168169
169170 return emptyList()
170171 }
0 commit comments