【发布时间】:2019-01-01 21:40:16
【问题描述】:
我已经使用 Akka actor 中的 stash 方法在 actor 中实现了 stash,但现在需要查看它的大小(即 stash 中没有消息)。有什么办法吗?
以下是方法及其文档 -
/**
* Adds the current message (the message that the actor received last) to the
* actor's stash.
*
* @throws StashOverflowException in case of a stash capacity violation
* @throws IllegalStateException if the same message is stashed more than once
*/
def stash(): Unit = {
val currMsg = actorCell.currentMessage
if (theStash.nonEmpty && (currMsg eq theStash.last))
throw new IllegalStateException(s"Can't stash the same message $currMsg more than once")
if (capacity <= 0 || theStash.size < capacity) theStash :+= currMsg
else throw new StashOverflowException(
s"Couldn't enqueue message ${currMsg.message.getClass.getName} from ${currMsg.sender} to stash of $self")
}
【问题讨论】:
-
我建议你阅读this。
-
你为什么不能只计算你调用
stash的次数并清除unstashAll的计数?
标签: scala akka actor akka-actor