开始看 Hazelcast ( 3.4.4)。最少的配置。测试:
case class Ticket(id:Int, name:String)
val ticketCount = 20
val tickets:List[Ticket] = for { n <- (0 until ticketCount).toList } yield Ticket(n, s"ticket$n")
val map: IMap[Long, Ticket] = hz1.getMap[Long,Ticket]("com.foo.testmap")
tickets foreach { t =>
println(s"submitting $t")
Thread.sleep(10) // some delay to submit one ticket
map.putIfAbsent(t.id, t)
}
Thread.sleep(2000) // two seconds to make sure all is set..
var value1 = map.get(19) // null
var value2 = map.containsKey(19) ) // false
val value3 = map.getAsync(19).get() // Ticket(19,ticket19)
为什么 null
,为什么false
,为什么只map.getAsync(19).get()
有效?
不过,这:
val iterator = map.entrySet().iterator() // will print all values
while(iterator.hasNext) {
val next = iterator.next()
println(next)
}
将打印所有条目。
更新:
在配置中:
<map name="com.foo.testmap">
<in-memory-format>OBJECT</in-memory-format>
</map>