Giriş
Şu satırı dahil ederiz
import com.hazelcast.config.EntryListenerConfig;
Açıklaması şöyle
Registering Map Listeners
After you create your listener class, you can configure your cluster to include map listeners using the method addEntryListener
Yani şöyle yaparız
HazelcastInstance hz = Hazelcast.newHazelcastInstance(); IMap<String, String> map = hz.getMap( "somemap" ); map.addEntryListener( new MyEntryListener(), true );
Ancak bu yöntemde bazı listener mesajları kaçabilir
With the above approach, there is the possibility of missing events between the creation of the instance and registering the listener. To overcome this race condition, Hazelcast allows you to register listeners in configuration.
Bu yüzden şöyle yaparız
mapConfig.addEntryListenerConfig( new EntryListenerConfig( "com.yourpackage.MyEntryListener", false, false ) );
constructor - String className, boolean local, boolean includeValue
local değeri true ise sanırım IMap.addLocalEntryListener gibidir. Yani bu member'da sadece kendi sahibi olduğu key değerler için tetiklenir
Örnek
public class ExpiredListener implements EntryEvictedListener<String, Application>, EntryExpiredListener<String, Application> { private final ApplicationEventPublisher publisher; @Override public void entryEvicted(EntryEvent<String, Application> event) { publisher.publishEvent(new ApplicationCacheExpireEvent(this, event.getOldValue())); } @Override public void entryExpired(EntryEvent<String, Application> event) { publisher.publishEvent(new ApplicationCacheExpireEvent(this, event.getOldValue())); } } MapConfig applicationCache = ... .setMaxSizeConfig(new MaxSizeConfig() .setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.USED_HEAP_SIZE) .setSize(properties.getMaxMapHeapSize())) .setTimeToLiveSeconds(properties.getTtlBeforeSave()) .addEntryListenerConfig(new EntryListenerConfig(expiredListener, false, true));
Hiç yorum yok:
Yorum Gönder