scala - 如何检查akka actor中的存储大小
问题描述
我已经使用 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")
}
解决方案
In akka, Stash is internally implemented as StashBuffer. A StashBuffer is a non thread safe mutable message buffer that can be used to buffer messages inside actors and then unstash them. The buffer can hold at most the given capacity number of messages.
The StashBuffer is a trait
trait StashBuffer[T] extends AnyRef
which contains the size method
abstract def size: Int
which denotes the number the number of elements in the message buffer. Please refer https://doc.akka.io/api/akka/current/akka/actor/typed/scaladsl/StashBuffer.html
推荐阅读
- javascript - 在 onClick="window.location.href" 上使用 jQuery 重定向到 asp 页面
- python - 下载到本地计算机后,如何在 Python 程序中使用 NNN.py 库?
- javascript - 更改地图功能中的背景颜色,反应 js 和 javascript 项目
- excel - 达到最大小时数限制时如何禁用下拉列表?
- postgresql - 为什么我的函数中的 postgres `lower()` 不是小写 È
- php - 第一次调用后通过重写自身来缓存其响应的 PHP 函数
- php - Apache 在大型 PHP 文件中出现 $_SESSION 变量的奇怪行为
- html - cucumber-html-reporter - 在带有预处理器的 cypress-cucumber 框架的失败步骤上添加屏幕截图
- firebase - 在 firebase 实时数据库的底部导航片段中填充 RecyclerView
- cmake - Raspberry Pi 4 Debian 10 上的安装问题