mirror of
https://github.com/corda/corda.git
synced 2024-12-19 04:57:58 +00:00
CORDA-1043
This commit is contained in:
parent
ffd726d592
commit
66cbe8c56d
@ -232,7 +232,7 @@ abstract class FlowLogic<out T> {
|
||||
* @returns a [Map] containing the objects received, wrapped in an [UntrustworthyData], by the [FlowSession]s who sent them.
|
||||
*/
|
||||
@Suspendable
|
||||
open fun receiveAll(sessions: Map<FlowSession, Class<out Any>>): Map<FlowSession, UntrustworthyData<Any>> {
|
||||
open fun receiveAllMap(sessions: Map<FlowSession, Class<out Any>>): Map<FlowSession, UntrustworthyData<Any>> {
|
||||
return stateMachine.receiveAll(sessions, this)
|
||||
}
|
||||
|
||||
@ -250,7 +250,7 @@ abstract class FlowLogic<out T> {
|
||||
@Suspendable
|
||||
open fun <R : Any> receiveAll(receiveType: Class<R>, sessions: List<FlowSession>): List<UntrustworthyData<R>> {
|
||||
enforceNoDuplicates(sessions)
|
||||
return castMapValuesToKnownType(receiveAll(associateSessionsToReceiveType(receiveType, sessions)))
|
||||
return castMapValuesToKnownType(receiveAllMap(associateSessionsToReceiveType(receiveType, sessions)))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,7 +5,6 @@ import net.corda.core.utilities.UntrustworthyData
|
||||
import net.corda.core.utilities.unwrap
|
||||
import net.corda.node.internal.InitiatedFlowFactory
|
||||
import net.corda.node.internal.StartedNode
|
||||
import net.corda.testing.node.StartedMockNode
|
||||
import net.corda.testing.node.internal.InternalMockNetwork
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@ -81,7 +80,7 @@ infix fun <T : Any> KClass<T>.from(session: FlowSession): Pair<FlowSession, Clas
|
||||
fun FlowLogic<*>.receiveAll(session: Pair<FlowSession, Class<out Any>>, vararg sessions: Pair<FlowSession, Class<out Any>>): Map<FlowSession, UntrustworthyData<Any>> {
|
||||
val allSessions = arrayOf(session, *sessions)
|
||||
allSessions.enforceNoDuplicates()
|
||||
return receiveAll(mapOf(*allSessions))
|
||||
return receiveAllMap(mapOf(*allSessions))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -264,6 +264,13 @@ In order to create a communication session between your initiator flow and the r
|
||||
* ``sendAndReceive(receiveType: Class<R>, payload: Any): R``
|
||||
* Sends the ``payload`` object and receives an object of type ``receiveType`` back
|
||||
|
||||
In addition ``FlowLogic`` provides functions that batch receives:
|
||||
* ``receiveAllMap(sessions: Map<FlowSession, Class<out Any>>): Map<FlowSession, UntrustworthyData<Any>>``
|
||||
* Receives from all ``FlowSession``s specified in the passed in map. The received types may differ.
|
||||
* ``receiveAll(receiveType: Class<R>, sessions: List<FlowSession>): List<UntrustworthyData<R>>``
|
||||
* Receives from all ``FlowSession``s specified in the passed in list. The received types must be the same.
|
||||
|
||||
The batched functions are implemented more efficiently by the flow framework.
|
||||
|
||||
InitiateFlow
|
||||
~~~~~~~~~~~~
|
||||
|
@ -27,6 +27,7 @@ import net.corda.finance.contracts.asset.Cash
|
||||
import net.corda.testing.contracts.DummyContract
|
||||
import net.corda.testing.contracts.DummyState
|
||||
import java.security.PublicKey
|
||||
import java.security.Signature
|
||||
import java.time.Instant
|
||||
|
||||
// ``InitiatorFlow`` is our first flow, and will communicate with
|
||||
@ -205,6 +206,19 @@ class InitiatorFlow(val arg1: Boolean, val arg2: Int, private val counterparty:
|
||||
val packet3: UntrustworthyData<Any> = regulatorSession.receive<Any>()
|
||||
// DOCEND 06
|
||||
|
||||
// We may also batch receives in order to increase performance. This
|
||||
// ensures that only a single checkpoint is created for all received
|
||||
// messages.
|
||||
// Type-safe variant:
|
||||
val signatures: List<UntrustworthyData<Signature>> =
|
||||
receiveAll(Signature::class.java, listOf(counterpartySession, regulatorSession))
|
||||
// Dynamic variant:
|
||||
val messages: Map<FlowSession, UntrustworthyData<*>> =
|
||||
receiveAllMap(mapOf(
|
||||
counterpartySession to Boolean::class.java,
|
||||
regulatorSession to String::class.java
|
||||
))
|
||||
|
||||
/**-----------------------------------
|
||||
* EXTRACTING STATES FROM THE VAULT *
|
||||
-----------------------------------**/
|
||||
|
Loading…
Reference in New Issue
Block a user