You can add or remove event listeners to/from the related object using the Hazelcast API.
The downside of attaching listeners using this API is the possibility of missing events between the creation of an object and registering the listener. To overcome this race condition, Hazelcast allows you to register listeners in configuration. You can register listeners using declarative, programmatic, or Spring configuration.
<listeners>
<listener>com.hazelcast.examples.MembershipListener</listener>
</listeners>
config.addListenerConfig(
new ListenerConfig( "com.hazelcast.examples.MembershipListener" ) );
<hz:listeners>
<hz:listener class-name="com.hazelcast.spring.DummyMembershipListener"/>
<hz:listener implementation="dummyMembershipListener"/>
</hz:listeners>
<listeners>
<listener>com.hazelcast.examples.DistributedObjectListener</listener>
</listeners>
config.addListenerConfig(
new ListenerConfig( "com.hazelcast.examples.DistributedObjectListener" ) );
<hz:listeners>
<hz:listener class-name="com.hazelcast.spring.DummyDistributedObjectListener"/>
<hz:listener implementation="dummyDistributedObjectListener"/>
</hz:listeners>
<listeners>
<listener>com.hazelcast.examples.MigrationListener</listener>
</listeners>
config.addListenerConfig(
new ListenerConfig( "com.hazelcast.examples.MigrationListener" ) );
<hz:listeners>
<hz:listener class-name="com.hazelcast.spring.DummyMigrationListener"/>
<hz:listener implementation="dummyMigrationListener"/>
</hz:listeners>
<listeners>
<listener>com.hazelcast.examples.LifecycleListener</listener>
</listeners>
config.addListenerConfig(
new ListenerConfig( "com.hazelcast.examples.LifecycleListener" ) );
<hz:listeners>
<hz:listener class-name="com.hazelcast.spring.DummyLifecycleListener"/>
<hz:listener implementation="dummyLifecycleListener"/>
</hz:listeners>
<map name="default">
...
<entry-listeners>
<entry-listener include-value="true" local="false">
com.hazelcast.examples.EntryListener
</entry-listener>
</entry-listeners>
</map>
mapConfig.addEntryListenerConfig(
new EntryListenerConfig( "com.hazelcast.examples.EntryListener", false, false ) );
<hz:map name="default">
<hz:entry-listeners>
<hz:entry-listener include-value="true"
class-name="com.hazelcast.spring.DummyEntryListener"/>
<hz:entry-listener implementation="dummyEntryListener" local="true"/>
</hz:entry-listeners>
</hz:map>
<multimap name="default">
<value-collection-type>SET</value-collection-type>
<entry-listeners>
<entry-listener include-value="true" local="false">
com.hazelcast.examples.EntryListener
</entry-listener>
</entry-listeners>
</multimap>
multiMapConfig.addEntryListenerConfig(
new EntryListenerConfig( "com.hazelcast.examples.EntryListener", false, false ) );
<hz:multimap name="default" value-collection-type="LIST">
<hz:entry-listeners>
<hz:entry-listener include-value="true"
class-name="com.hazelcast.spring.DummyEntryListener"/>
<hz:entry-listener implementation="dummyEntryListener" local="true"/>
</hz:entry-listeners>
</hz:multimap>
<queue name="default">
...
<item-listeners>
<item-listener include-value="true">
com.hazelcast.examples.ItemListener
</item-listener>
</item-listeners>
</queue>
queueConfig.addItemListenerConfig(
new ItemListenerConfig( "com.hazelcast.examples.ItemListener", true ) );
<hz:queue name="default" >
<hz:item-listeners>
<hz:item-listener include-value="true"
class-name="com.hazelcast.spring.DummyItemListener"/>
</hz:item-listeners>
</hz:queue>
<topic name="default">
<message-listeners>
<message-listener>
com.hazelcast.examples.MessageListener
</message-listener>
</message-listeners>
</topic>
topicConfig.addMessageListenerConfig(
new ListenerConfig( "com.hazelcast.examples.MessageListener" ) );
<hz:topic name="default">
<hz:message-listeners>
<hz:message-listener
class-name="com.hazelcast.spring.DummyMessageListener"/>
</hz:message-listeners>
</hz:topic>
<listeners>
<listener>com.hazelcast.examples.ClientListener</listener>
</listeners>
topicConfig.addMessageListenerConfig(
new ListenerConfig( "com.hazelcast.examples.ClientListener" ) );
<hz:listeners>
<hz:listener class-name="com.hazelcast.spring.DummyClientListener"/>
<hz:listener implementation="dummyClientListener"/>
</hz:listeners>