mirror of
https://github.com/corda/corda.git
synced 2025-01-31 00:24:59 +00:00
[ENT-4754] - Move subflow preparation logic in FlowStateMachine
This commit is contained in:
parent
c697b5850b
commit
b73a498062
@ -380,10 +380,8 @@ abstract class FlowLogic<out T> {
|
|||||||
@Suspendable
|
@Suspendable
|
||||||
@Throws(FlowException::class)
|
@Throws(FlowException::class)
|
||||||
open fun <R> subFlow(subLogic: FlowLogic<R>): R {
|
open fun <R> subFlow(subLogic: FlowLogic<R>): R {
|
||||||
subLogic.stateMachine = stateMachine
|
|
||||||
maybeWireUpProgressTracking(subLogic)
|
|
||||||
logger.debug { "Calling subflow: $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)}" }
|
logger.debug { "Subflow finished with result ${result.toString().abbreviate(300)}" }
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -540,18 +538,6 @@ abstract class FlowLogic<out T> {
|
|||||||
_stateMachine = value
|
_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>) {
|
private fun enforceNoDuplicates(sessions: List<FlowSession>) {
|
||||||
require(sessions.size == sessions.toSet().size) { "A flow session can only appear once as argument." }
|
require(sessions.size == sessions.toSet().size) { "A flow session can only appear once as argument." }
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ interface FlowStateMachine<FLOWRETURN> {
|
|||||||
fun recordAuditEvent(eventType: String, comment: String, extraAuditData: Map<String, String>)
|
fun recordAuditEvent(eventType: String, comment: String, extraAuditData: Map<String, String>)
|
||||||
|
|
||||||
@Suspendable
|
@Suspendable
|
||||||
fun <SUBFLOWRETURN> subFlow(subFlow: FlowLogic<SUBFLOWRETURN>): SUBFLOWRETURN
|
fun <SUBFLOWRETURN> subFlow(currentFlow: FlowLogic<*>, subFlow: FlowLogic<SUBFLOWRETURN>): SUBFLOWRETURN
|
||||||
|
|
||||||
@Suspendable
|
@Suspendable
|
||||||
fun flowStackSnapshot(flowClass: Class<out FlowLogic<*>>): FlowStackSnapshot?
|
fun flowStackSnapshot(flowClass: Class<out FlowLogic<*>>): FlowStackSnapshot?
|
||||||
|
@ -315,7 +315,10 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Suspendable
|
@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)
|
checkpointIfSubflowIdempotent(subFlow.javaClass)
|
||||||
processEventImmediately(
|
processEventImmediately(
|
||||||
Event.EnterSubFlow(subFlow.javaClass,
|
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
|
private fun Throwable.isUnrecoverable(): Boolean = this is VirtualMachineError && this !is StackOverflowError
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user