event.getOldValue() is null in entryUpdated

306 views
Skip to first unread message

nayr...@gmail.com

unread,
Jul 7, 2016, 1:29:29 PM7/7/16
to Hazelcast
When an entryUpdated event is triggered, the EntryEvent object that gets passed in returns null from getOldValue().

import com.hazelcast.map.listener.EntryUpdatedListener;

...

public class DataTable<E> implements EntryUpdatedListener<E, Entity> {

...

public
void entryUpdated(EntryEvent<E, Entity> event) {
       
       
Entity updatedEntity = event.getValue();
       
Entity originalEntity = event.getOldValue();

       
System.out.println(updatedEntity); // Service: dataServer LastUpdated: 2016-07-07 15:34:14.796
        System.out.println(originalEntity); // null
}

This was working as expected (getOldValue returns value prior to update) in version 2.6.10, but it does not work in 3.4 or 3.6.4.

Thank you

Vassilis Bekiaris

unread,
Jul 7, 2016, 2:20:06 PM7/7/16
to haze...@googlegroups.com

Hi,

how do you register your entry listener? The following listener works fine in Hazelcast 3.6.4, I can see both old and new value when updating an entry either via map.put or map.replace:

map.addEntryListener(new EntryUpdatedListener<Integer, String>() {
    @Override
    public void entryUpdated(EntryEvent<Integer, String> event) {
        System.out.println("old val: " + event.getOldValue() + ", new val: " + event.getValue());
    }
}, true);
Cheers!
Vassilis
--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at https://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/c3ebd3b0-abb2-447a-9ff0-48753580cdfd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

nayr...@gmail.com

unread,
Jul 8, 2016, 3:50:27 AM7/8/16
to Hazelcast
Thanks for replying,

This is from the DataTable class:
Config config = getHazelcast().getConfig();

MapConfig mapConfig = config.getMapConfig(name);
mapConfig
.setMaxIdleSeconds(0);
mapConfig
.setTimeToLiveSeconds(0);
mapConfig
.setEvictionPolicy(EvictionPolicy.NONE);
mapConfig
.setBackupCount(3);

hazelcast
.getMap(name).addEntryListener(this, true);


Thanks

ih...@hazelcast.com

unread,
Jul 8, 2016, 5:22:12 AM7/8/16
to Hazelcast, nayr...@gmail.com
Is it possible that there was no entry in the table and this would mean a null value when you performed IMap.put. In this case, it is OK to receive null as the old value. Can you verify this by doing a get before put?

Regards,
ihsan

nayr...@gmail.com

unread,
Jul 8, 2016, 3:56:58 PM7/8/16
to Hazelcast
Doh! Turns out that in our DataTable.put function we were using IMap.set instead of IMap.put, so as stated in the Javadoc:

Warning:

This method breaks the contract of EntryListener. When an entry is updated by set(), it fires an EntryEvent with a null oldValue.

Thanks for the help

nadimin...@gmail.com

unread,
Feb 2, 2018, 9:58:38 AM2/2/18
to Hazelcast

This saved my life..however, the maps were being set in a C++ client.

İhsan Demir

unread,
Feb 7, 2018, 3:34:11 AM2/7/18
to haze...@googlegroups.com
I understand that you are setting the map value from C++ client but just remember that for any key at the first put, you will always receive null for the oldValue since there was no old value prior to that put, right? So, it is a good practice to always do a null check.

Regards,
ihsan

--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+unsubscribe@googlegroups.com.

To post to this group, send email to haze...@googlegroups.com.
Visit this group at https://groups.google.com/group/hazelcast.

For more options, visit https://groups.google.com/d/optout.



--

Ihsan Demir
Software Engineer, Clients Team
Mahir İz Cad. No:35, Altunizade, İstanbul 
ih...@hazelcast.com
skype: idemir

Stodge

unread,
Sep 5, 2018, 8:56:18 AM9/5/18
to Hazelcast
Forgive my naive question, but why would you get an entryUpdated when you add an entry? Shouldn't it use the entryAdded callback?

I have the same problem.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.

Sertuğ Kaya

unread,
Sep 10, 2018, 10:03:50 AM9/10/18
to Hazelcast
If you're doing put/set for an entry which is already there, you will get an entryUpdated event instead of an entryAdded event.
Reply all
Reply to author
Forward
0 new messages