Hazelcast EntryListener,如何避免竞争条件?
Hazelcast EntryListener, how to avoid race condition?
我正在尝试使用 Hazelcast 开发订阅服务。订阅将侦听添加到满足谓词的特定 Map 的条目。使用 EntryListener.
可以很容易地实现这一点
然而,当我添加 EntryListener
时,地图的本地缓存并不为空(并且地图不断接收更新)。如果将 EntryListener
添加到包含条目的地图,则不会为地图中任何预先存在的条目触发 EntryListener
。
我可以调用 map.values( <predicate> )
但总是可以在遍历 Map 之后但在添加 EntryListener
之前添加条目,因为调用 map.values(...)
和对 map.addEntryListener(...)
的调用是 不是 原子的。
在理想的解决方案中,事件的顺序是:
- 用谓词添加
EntryListener
- 接收缓存中与该谓词匹配的所有条目
- 然后在事件发生时接收 updates/removes/adds(匹配初始谓词)。
虽然是企业功能,
continuous-query-cache seems what you want. Please see pre-population part. Pre-population helps to fill your cache from underlying imap by getting a snapshot of it according to supplied predicate. You can also find some samples here.
我正在尝试使用 Hazelcast 开发订阅服务。订阅将侦听添加到满足谓词的特定 Map 的条目。使用 EntryListener.
可以很容易地实现这一点然而,当我添加 EntryListener
时,地图的本地缓存并不为空(并且地图不断接收更新)。如果将 EntryListener
添加到包含条目的地图,则不会为地图中任何预先存在的条目触发 EntryListener
。
我可以调用 map.values( <predicate> )
但总是可以在遍历 Map 之后但在添加 EntryListener
之前添加条目,因为调用 map.values(...)
和对 map.addEntryListener(...)
的调用是 不是 原子的。
在理想的解决方案中,事件的顺序是:
- 用谓词添加
EntryListener
- 接收缓存中与该谓词匹配的所有条目
- 然后在事件发生时接收 updates/removes/adds(匹配初始谓词)。
虽然是企业功能, continuous-query-cache seems what you want. Please see pre-population part. Pre-population helps to fill your cache from underlying imap by getting a snapshot of it according to supplied predicate. You can also find some samples here.