[ENT-4754] - Move subflow preparation logic in FlowStateMachine

This commit is contained in:
Dimos Raptis 2020-03-25 09:02:14 +00:00 committed by GitHub
parent c697b5850b
commit b73a498062
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 17 deletions

View File

@ -380,10 +380,8 @@ abstract class FlowLogic<out T> {
@Suspendable
@Throws(FlowException::class)
open fun <R> subFlow(subLogic: FlowLogic<R>): R {
subLogic.stateMachine = stateMachine
maybeWireUpProgressTracking(subLogic)
logger.debug { "Calling subflow: $subLogic" }
val result = stateMachine.subFlow(subLogic)
val result = stateMachine.subFlow(this, subLogic)
logger.debug { "Subflow finished with result ${result.toString().abbreviate(300)}" }
return result
}
@ -540,18 +538,6 @@ abstract class FlowLogic<out T> {
_stateMachine = value
}
private fun maybeWireUpProgressTracking(subLogic: FlowLogic<*>) {
val ours = progressTracker
val theirs = subLogic.progressTracker
if (ours != null && theirs != null && ours != theirs) {
if (ours.currentStep == ProgressTracker.UNSTARTED) {
logger.debug { "Initializing the progress tracker for flow: ${this::class.java.name}." }
ours.nextStep()
}
ours.setChildProgressTracker(ours.currentStep, theirs)
}
}
private fun enforceNoDuplicates(sessions: List<FlowSession>) {
require(sessions.size == sessions.toSet().size) { "A flow session can only appear once as argument." }
}

View File

@ -25,7 +25,7 @@ interface FlowStateMachine<FLOWRETURN> {
fun recordAuditEvent(eventType: String, comment: String, extraAuditData: Map<String, String>)
@Suspendable
fun <SUBFLOWRETURN> subFlow(subFlow: FlowLogic<SUBFLOWRETURN>): SUBFLOWRETURN
fun <SUBFLOWRETURN> subFlow(currentFlow: FlowLogic<*>, subFlow: FlowLogic<SUBFLOWRETURN>): SUBFLOWRETURN
@Suspendable
fun flowStackSnapshot(flowClass: Class<out FlowLogic<*>>): FlowStackSnapshot?

View File

@ -315,7 +315,10 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
}
@Suspendable
override fun <R> subFlow(subFlow: FlowLogic<R>): R {
override fun <R> subFlow(currentFlow: FlowLogic<*>, subFlow: FlowLogic<R>): R {
subFlow.stateMachine = this
maybeWireUpProgressTracking(currentFlow, subFlow)
checkpointIfSubflowIdempotent(subFlow.javaClass)
processEventImmediately(
Event.EnterSubFlow(subFlow.javaClass,
@ -338,6 +341,18 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
}
}
private fun maybeWireUpProgressTracking(currentFlow: FlowLogic<*>, subFlow: FlowLogic<*>) {
val currentFlowProgressTracker = currentFlow.progressTracker
val subflowProgressTracker = subFlow.progressTracker
if (currentFlowProgressTracker != null && subflowProgressTracker != null && currentFlowProgressTracker != subflowProgressTracker) {
if (currentFlowProgressTracker.currentStep == ProgressTracker.UNSTARTED) {
logger.debug { "Initializing the progress tracker for flow: ${this::class.java.name}." }
currentFlowProgressTracker.nextStep()
}
currentFlowProgressTracker.setChildProgressTracker(currentFlowProgressTracker.currentStep, subflowProgressTracker)
}
}
private fun Throwable.isUnrecoverable(): Boolean = this is VirtualMachineError && this !is StackOverflowError
/**