Search code examples
javahazelcasthazelcast-imap

Modified Value of IMap After Serialization


I have defined an IMap as follows in a class called BookMap:

private final IMap<String, OrderBook> orderBooksBySymEx =
    FirmMatchingServer.getHazelcastInstance().getMap("BookMap");

OrderBook is a complex Class with many different member types. Some of those nested members themselves contain native HashMaps and other modifiable objects. All of the custom nested members have implemented Externalizable or Serializable.

There is a getter on BookMap which retrieves an OrderBook to the caller.

    public OrderBook getOrderBook(String _key)
    {
       log.info("get: " + toString());
       OrderBook obook = null;
       try
       {
          obook = orderBooksBySymEx.get(_key);
          if (obook == null) {
            obook = new OrderBook();
            orderBooksBySymEx.put(_key, obook);
          }
       }
       catch(Exception e)
       {
           log.error(e, e);
       }

       return obook;            
}

It seems Hazelcast serializes the OrderBook at the point of the put operation:

orderBooksBySymEx.put(_key, obook);

However, the caller which receives the OrderBook instance is free to modify it. I noticed that modifications to OrderBook are not reflected in the binary representation stored in the Hazelcast IMap so subsequent get()s on the IMap do not contain any updates that have occurred after the put().

Is there any way to tell Hazelcast to re-serialize it's object hierarchy so that the java reference semantics are not violated?


Solution

  • This is not possible in Hazelcast. The closest thing to what you are describing would be a User Defined Service which can proxy itself to the cluster on modification. But in that case the object state lives and is guarded by the cluster.