mirror of
https://github.com/corda/corda.git
synced 2025-03-17 17:45:17 +00:00
ENT-1962: throw a clearer exception when starting RPC flow while SMM is stopped … (#912)
* ENT-1962: throw a clearer exception when starting RPC flow while SMM is stopped. * ENT-1962: update exception constructor
This commit is contained in:
parent
76644e0d00
commit
71d8586e61
@ -39,6 +39,17 @@ class LifeCycle<S : Enum<S>>(initial: S) {
|
||||
}
|
||||
fun requireState(requiredState: S) = requireState(requiredState) {}
|
||||
|
||||
fun <A> requireState(
|
||||
requiredState: S,
|
||||
throwable: Throwable,
|
||||
block: () -> A
|
||||
): A {
|
||||
return lock.readLock().withLock {
|
||||
if (requiredState != state) { throw throwable }
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
||||
/** Assert something about the current state atomically. */
|
||||
fun <A> requireState(
|
||||
errorMessage: (S) -> String,
|
||||
|
@ -50,6 +50,7 @@ import net.corda.core.node.services.vault.Sort
|
||||
import net.corda.core.serialization.serialize
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.node.internal.exceptions.StateMachineStoppedException
|
||||
import net.corda.node.services.api.FlowStarter
|
||||
import net.corda.node.services.api.ServiceHubInternal
|
||||
import net.corda.node.services.messaging.context
|
||||
@ -185,7 +186,11 @@ internal class CordaRPCOpsImpl(
|
||||
if (isFlowsDrainingModeEnabled()) {
|
||||
throw RejectedCommandException("Node is draining before shutdown. Cannot start new flows through RPC.")
|
||||
}
|
||||
return flowStarter.invokeFlowAsync(logicType, context(), *args).getOrThrow()
|
||||
try {
|
||||
return flowStarter.invokeFlowAsync(logicType, context(), *args).getOrThrow()
|
||||
} catch (e: StateMachineStoppedException) {
|
||||
throw RejectedCommandException("Node is shutting down. Cannot start new flows through RPC.")
|
||||
}
|
||||
}
|
||||
|
||||
override fun attachmentExists(id: SecureHash): Boolean {
|
||||
|
@ -0,0 +1,7 @@
|
||||
package net.corda.node.internal.exceptions
|
||||
|
||||
import net.corda.core.CordaRuntimeException
|
||||
|
||||
class StateMachineStoppedException(message: String, cause: Throwable?) : CordaRuntimeException(message, cause) {
|
||||
constructor(msg: String) : this(msg, null)
|
||||
}
|
@ -34,6 +34,7 @@ import net.corda.core.utilities.Try
|
||||
import net.corda.core.utilities.contextLogger
|
||||
import net.corda.core.utilities.debug
|
||||
import net.corda.node.internal.InitiatedFlowFactory
|
||||
import net.corda.node.internal.exceptions.StateMachineStoppedException
|
||||
import net.corda.node.services.api.CheckpointStorage
|
||||
import net.corda.node.services.api.ServiceHubInternal
|
||||
import net.corda.node.services.config.shouldCheckCheckpoints
|
||||
@ -196,7 +197,7 @@ class MultiThreadedStateMachineManager(
|
||||
ourIdentity: Party?,
|
||||
deduplicationHandler: DeduplicationHandler?
|
||||
): CordaFuture<FlowStateMachine<A>> {
|
||||
return lifeCycle.requireState(State.STARTED) {
|
||||
return lifeCycle.requireState(State.STARTED, StateMachineStoppedException("Flow cannot be started. State machine is stopped.")) {
|
||||
startFlowInternal(
|
||||
invocationContext = context,
|
||||
flowLogic = flowLogic,
|
||||
|
Loading…
x
Reference in New Issue
Block a user