我已经使用 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")
}