1

I need to update a persisted value. I mean:

////// Class InfoEquipoCache used as value of CM

class InfoEquipoCache implements BytesMarshallable {
    private EquipoCache equipoCache;
    public void actualiza() {
        .....
        equipoCache.actualiza()
        ......
    }
    .......

///// Principal Class has a CM of InfoEquipoCache

ChronicleMap<String, InfoEquipoCache> equipos;

..... //// In some part of principal class:

equipos.get(idEquipo).actualiza() //InfoEquipoCache contains actualiza method

But, equipos.get(idEquipo) has a reference of EquipoCache and inside InfoEquipoCache has a diferent reference of EquipoCache. As results actualiza method is usseless

Someone knows how to make changes of this value?

2 Answers2

1

When you store a value in Chronicle Map, it is serialised to off-heap memory; therefore when you call get() you will be retrieving a different (albeit value-equal) instance.

If you need to work with the same instance, then you should consider an in-memory solution (e.g. j.u.HashMap or j.u.c.ConcurrentHashMap).

Mark Price
  • 296
  • 1
  • 3
0

You could store and update EquipoCache value off-heap inside the Chronicle Map. Don't forget to write value back to CM at the end of manupulations.

try (ExternalMapQueryContext<String, InfoEquipoCache, ?> ctx = map.queryContext(idEquipo)) {
    ctx.updateLock().lock();
    try {
        MapEntry<String, InfoEquipoCache> entry = ctx.entry();
        if (entry != null) {
            InfoEquipoCache infoEquipoCache = entry.value().get();
            infoEquipoCache.actualiza();
            ctx.replaceValue(entry,ctx.wrapValueAsData(infoEquipoCache));
        }
    } finally {
        ctx.readLock().unlock();  //release all-type locks
    }
}

Also you can read this in a Chronicle Map tutorial

Serhio
  • 1
  • 1