mirror of
https://github.com/corda/corda.git
synced 2025-06-18 15:18:16 +00:00
CORDA-3506 - Implement session close operations (#6357)
This commit is contained in:
@ -25,6 +25,7 @@ import net.corda.core.node.NodeInfo
|
||||
import net.corda.core.node.ServiceHub
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
import net.corda.core.utilities.NonEmptySet
|
||||
import net.corda.core.utilities.ProgressTracker
|
||||
import net.corda.core.utilities.UntrustworthyData
|
||||
import net.corda.core.utilities.debug
|
||||
@ -378,6 +379,22 @@ abstract class FlowLogic<out T> {
|
||||
stateMachine.suspend(request, maySkipCheckpoint)
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the provided sessions and performs cleanup of any resources tied to these sessions.
|
||||
*
|
||||
* Note that sessions are closed automatically when the corresponding top-level flow terminates.
|
||||
* So, it's beneficial to eagerly close them in long-lived flows that might have many open sessions that are not needed anymore and consume resources (e.g. memory, disk etc.).
|
||||
* A closed session cannot be used anymore, e.g. to send or receive messages. So, you have to ensure you are calling this method only when the provided sessions are not going to be used anymore.
|
||||
* As a result, any operations on a closed session will fail with an [UnexpectedFlowEndException].
|
||||
* When a session is closed, the other side is informed and the session is closed there too eventually.
|
||||
* To prevent misuse of the API, if there is an attempt to close an uninitialised session the invocation will fail with an [IllegalStateException].
|
||||
*/
|
||||
@Suspendable
|
||||
fun close(sessions: NonEmptySet<FlowSession>) {
|
||||
val request = FlowIORequest.CloseSessions(sessions)
|
||||
stateMachine.suspend(request, false)
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes the given subflow. This function returns once the subflow completes successfully with the result
|
||||
* returned by that subflow's [call] method. If the subflow has a progress tracker, it is attached to the
|
||||
|
@ -191,6 +191,19 @@ abstract class FlowSession {
|
||||
*/
|
||||
@Suspendable
|
||||
abstract fun send(payload: Any)
|
||||
|
||||
/**
|
||||
* Closes this session and performs cleanup of any resources tied to this session.
|
||||
*
|
||||
* Note that sessions are closed automatically when the corresponding top-level flow terminates.
|
||||
* So, it's beneficial to eagerly close them in long-lived flows that might have many open sessions that are not needed anymore and consume resources (e.g. memory, disk etc.).
|
||||
* A closed session cannot be used anymore, e.g. to send or receive messages. So, you have to ensure you are calling this method only when the session is not going to be used anymore.
|
||||
* As a result, any operations on a closed session will fail with an [UnexpectedFlowEndException].
|
||||
* When a session is closed, the other side is informed and the session is closed there too eventually.
|
||||
* To prevent misuse of the API, if there is an attempt to close an uninitialised session the invocation will fail with an [IllegalStateException].
|
||||
*/
|
||||
@Suspendable
|
||||
abstract fun close()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,7 @@ import java.util.jar.JarInputStream
|
||||
|
||||
// *Internal* Corda-specific utilities.
|
||||
|
||||
const val PLATFORM_VERSION = 7
|
||||
const val PLATFORM_VERSION = 8
|
||||
|
||||
fun ServicesForResolution.ensureMinimumPlatformVersion(requiredMinPlatformVersion: Int, feature: String) {
|
||||
checkMinimumPlatformVersion(networkParameters.minimumPlatformVersion, requiredMinPlatformVersion, feature)
|
||||
|
@ -55,6 +55,13 @@ sealed class FlowIORequest<out R : Any> {
|
||||
}}, shouldRetrySend=$shouldRetrySend)"
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the specified sessions.
|
||||
*
|
||||
* @property sessions the sessions to be closed.
|
||||
*/
|
||||
data class CloseSessions(val sessions: NonEmptySet<FlowSession>): FlowIORequest<Unit>()
|
||||
|
||||
/**
|
||||
* Wait for a transaction to be committed to the database.
|
||||
*
|
||||
|
Reference in New Issue
Block a user