Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kotlin ReceiveAll()在Corda中的应用是什么?如何实施?_Kotlin_Blockchain_Corda - Fatal编程技术网

Kotlin ReceiveAll()在Corda中的应用是什么?如何实施?

Kotlin ReceiveAll()在Corda中的应用是什么?如何实施?,kotlin,blockchain,corda,Kotlin,Blockchain,Corda,是否有实现sentAll()和receiveAll()的示例 receiveAll(receiveType:Class,sessions:List):列表 其中表示:从传入列表中指定的所有FlowSession对象接收。收到的类型必须相同 它是否用于响应器流内部?如果是,如何在receiveAll()中以列表的形式输入所需的会话 receiveAll()和sendAll()实际上是4.5中的性能升级 版本 这里举两个例子: 如果您想从a向B/C发送一条启动新会话的消息,您将对B和C使用init

是否有实现sentAll()和receiveAll()的示例

receiveAll(receiveType:Class,sessions:List):列表

其中表示:从传入列表中指定的所有FlowSession对象接收。收到的类型必须相同

它是否用于响应器流内部?如果是,如何在receiveAll()中以列表的形式输入所需的会话

receiveAll()和sendAll()实际上是4.5中的性能升级 版本

这里举两个例子:

  • 如果您想从a向B/C发送一条启动新会话的消息,您将对B和C使用initiateFlow,然后从a方执行sendAll()。在B和C的响应方,您将执行普通接收
  • 如果您希望从甲方的B&C接收并行消息(比如在建立会话后),您可以从B和C进行普通发送,并从A进行receiveAll()
启动器流:

@InitiatingFlow
@StartableByRPC
class sendAllReceiveAllExampleFlow(private val itemToBeSent : String) : FlowLogic<String>(){
    @Suspendable
    override fun call() : String {
        val counterParty1 = serviceHub.identityService.partiesFromName("PartyB",false).single()
        val counterParty2 = serviceHub.identityService.partiesFromName("PartyC",false).single()

        val counterPartySession1 = initiateFlow(counterParty1)
        val counterPartySession2 = initiateFlow(counterParty2)

        sendAll(itemToBeSent, setOf(counterPartySession1,counterPartySession2))

        val receivedBack= receiveAll(String::class.java,listOf(counterPartySession1,
counterPartySession2)).map { it.unwrap { it } }

  
       return "receivedBack :" + receivedBack.toString()
    }
}
class SendAllReceiveAllResponder(private val counterSessionList : FlowSession): FlowLogic<Unit>(){
    @Suspendable
    override fun call(){
        println("Inside Responder ")
        val receivedString = counterSessionList.receive<String>().unwrap { it }
        println("PayLoad Received at Responder = "+ receivedString)
        counterSessionList.send(receivedString + ourIdentity.name.organisation)
    }
}
@InitiatingFlow
@星表
类sendAllReceiveAllExampleFlow(private val itemtoPresent:String):FlowLogic(){
@暂停
重写有趣的调用():字符串{
val counterParty1=serviceHub.identityService.partiesFromName(“PartyB”,false).single()
val counterParty2=serviceHub.identityService.partiesFromName(“PartyC”,false).single()
val交易对手会话1=发起流动(交易对手1)
val交易对手会话2=发起流动(交易对手2)
发送所有(待发送项,集合(对方会话1、对方会话2))
val receivedBack=receiveAll(String::class.java,listOf(counterPartySession1,
对方会话2).映射{it.unwrap{it}
返回“receivedBack:+receivedBack.toString()
}
}
响应者流:

@InitiatingFlow
@StartableByRPC
class sendAllReceiveAllExampleFlow(private val itemToBeSent : String) : FlowLogic<String>(){
    @Suspendable
    override fun call() : String {
        val counterParty1 = serviceHub.identityService.partiesFromName("PartyB",false).single()
        val counterParty2 = serviceHub.identityService.partiesFromName("PartyC",false).single()

        val counterPartySession1 = initiateFlow(counterParty1)
        val counterPartySession2 = initiateFlow(counterParty2)

        sendAll(itemToBeSent, setOf(counterPartySession1,counterPartySession2))

        val receivedBack= receiveAll(String::class.java,listOf(counterPartySession1,
counterPartySession2)).map { it.unwrap { it } }

  
       return "receivedBack :" + receivedBack.toString()
    }
}
class SendAllReceiveAllResponder(private val counterSessionList : FlowSession): FlowLogic<Unit>(){
    @Suspendable
    override fun call(){
        println("Inside Responder ")
        val receivedString = counterSessionList.receive<String>().unwrap { it }
        println("PayLoad Received at Responder = "+ receivedString)
        counterSessionList.send(receivedString + ourIdentity.name.organisation)
    }
}
类SendAllReceiveAllResponder(私有val countersession列表:FlowSession):FlowLogic(){
@暂停
覆盖有趣的调用(){
println(“内部响应程序”)
val receivedString=counterSessionList.receive().unwrap{it}
println(“在响应程序接收的有效负载=“+receivedString”)
会务列表。发送(接收字符串+用户身份。名称。组织)
}
}

案例场景的来源:

您还可以查看这个单元测试——在github上的Corda存储库中

另外,要添加有关此API的内容,有两个API允许您同时向多个会话发送消息:

  • 使用
    SendAll()
    可以向所有会话发送相同的有效负载,如前面的注释所示
  • 使用
    SendAllMap()
    可以同时向不同的会话发送不同的有效负载。上面我提供的链接就是一个例子
。使用receiveAll()的示例测试文件