java - java.lang.IllegalArgumentException:无法在 Corda 中接收原始类型 [int]
问题描述
我试图使用 receiveAll() 函数在 PartyA(Initiator party) 中接收有效负载。但是遇到了一个错误:
java.lang.IllegalArgumentException:执行流程时无法接收原始类型 [int] 。
启动流程:
@InitiatingFlow
@StartableByRPC
class sendAllMapReceiveAll_IntExampleFlow(private val itemToBeSent : String,private val item2 : Int) : 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)
val sessionPayloadMap = mapOf(Pair(counterPartySession1,itemToBeSent), Pair(counterPartySession2,item2))
sendAllMap(sessionPayloadMap)
val receivedBack=receiveAll(Int::class.java, listOf(counterPartySession1,counterPartySession2)).map { it.unwrap { it } }
return receivedBack.toString()
}
}
响应流程:
@InitiatedBy(sendAllMapReceiveAll_AnyExampleFlow::class)
class SendAllMapReceiveAllAnyResponder(private val counterSession : FlowSession): FlowLogic<Unit>(){
@Suspendable
override fun call(){
val payloadItem = counterSession.receive<Any>().unwrap { it }
println("PayLoad Received at Responder = "+ payloadItem)
counterSession.send(12346)
}
}
后来为了解决这个错误。我发现这个链接很有帮助。通过在 receiveAll() 中将Int更改为Integer解决了该问题。但是int在单个接收函数中工作,如下所示:
val payloadItem = counterSession.receive<Int>().unwrap { it }
- 为什么原始 int 在 receiveAll() 中不起作用,但同时在单个接收(会话)中起作用?
- kotlin 中的其他原始类型在 receiveAll() 中的行为是否也相似?
编辑:再添加一个示例,该示例给了我相同的错误,以解决答案中的混乱。
val receivedBack2 =receiveAllMap(mapOf(Pair(counterPartySession1,String::class.java),
Pair(counterPartySession2,Int::class.java))).map { it.value.unwrap { it } }
解决方案
我认为您提供的代码片段不准确。
错误消息清楚地提到您尝试接收原语 int
(小写i
);在您的代码中,您编写类 Int
(大写I
)。
我认为最初您int
的代码中有错误,然后您将其更改为Int
发布问题时的错误。
send()
, receive()
,sendAndReceive()
仅适用于类(请参阅此处的文档);所以它将与Int
or一起使用Integer
;它不适用于int
.
推荐阅读
- django - ListView 调用 `get_template_names` 而不调用它
- ruby-on-rails - 使用 eval 运行 ruby 代码,它是 gems,rails
- git - 如何从分支获取所有提交并放入单个提交
- python - 如何将 Schedule 转换为 APScheduler 模块?
- java - 对我的对象数组列表进行选择排序不起作用 JAVA
- ionic-framework - IonicFramework - 在 iOS 上以全屏模式停止视频自动播放
- angular - 从另一个目录调用 angular build
- bash - 如何从 git 挂钩中可靠地找到根 git 目录?
- regex - 嵌套括号内的 grep
- javascript - XMLHttpRequest 的 readystatechange 事件在当前脚本结束前触发