Search in sources :

Example 41 with EventService

use of com.hazelcast.spi.impl.eventservice.EventService in project hazelcast by hazelcast.

the class CachePartitionLostListenerConfigTest method testCachePartitionLostListener_registeredViaImplementationInConfigObject.

@Test
public void testCachePartitionLostListener_registeredViaImplementationInConfigObject() {
    final String cacheName = "myCache";
    Config config = new Config();
    CacheSimpleConfig cacheConfig = config.getCacheConfig(cacheName);
    CachePartitionLostListener listener = mock(CachePartitionLostListener.class);
    cacheConfig.addCachePartitionLostListenerConfig(new CachePartitionLostListenerConfig(listener));
    cacheConfig.setBackupCount(0);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance instance = factory.newHazelcastInstance(config);
    HazelcastServerCachingProvider cachingProvider = createServerCachingProvider(instance);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    cacheManager.getCache(cacheName);
    final EventService eventService = getNode(instance).getNodeEngine().getEventService();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Collection<EventRegistration> registrations = eventService.getRegistrations(CacheService.SERVICE_NAME, cacheName);
            assertFalse(registrations.isEmpty());
        }
    });
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) EventCollectingCachePartitionLostListener(com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener) CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) Config(com.hazelcast.config.Config) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) EventService(com.hazelcast.spi.impl.eventservice.EventService) IOException(java.io.IOException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 42 with EventService

use of com.hazelcast.spi.impl.eventservice.EventService in project hazelcast by hazelcast.

the class DestroyQueryCacheOperation method removeAllListeners.

private void removeAllListeners() {
    EventService eventService = getNodeEngine().getEventService();
    eventService.deregisterAllListeners(MapService.SERVICE_NAME, cacheId);
}
Also used : EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 43 with EventService

use of com.hazelcast.spi.impl.eventservice.EventService in project hazelcast by hazelcast.

the class MultiMapService method addListenerAsync.

public CompletableFuture<UUID> addListenerAsync(String name, @Nonnull EventListener listener, Data key, boolean includeValue) {
    EventService eventService = nodeEngine.getEventService();
    MultiMapEventFilter filter = new MultiMapEventFilter(includeValue, key);
    return eventService.registerListenerAsync(SERVICE_NAME, name, filter, listener).thenApplyAsync(EventRegistration::getId, CALLER_RUNS);
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 44 with EventService

use of com.hazelcast.spi.impl.eventservice.EventService in project hazelcast by hazelcast.

the class MultiMapService method addListener.

public UUID addListener(String name, @Nonnull EventListener listener, Data key, boolean includeValue) {
    EventService eventService = nodeEngine.getEventService();
    MultiMapEventFilter filter = new MultiMapEventFilter(includeValue, key);
    return eventService.registerListener(SERVICE_NAME, name, filter, listener).getId();
}
Also used : EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 45 with EventService

use of com.hazelcast.spi.impl.eventservice.EventService in project hazelcast by hazelcast.

the class MultiMapEventsPublisher method publishEntryEvent.

public final void publishEntryEvent(String multiMapName, EntryEventType eventType, Data key, Object newValue, Object oldValue) {
    EventService eventService = nodeEngine.getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(MultiMapService.SERVICE_NAME, multiMapName);
    for (EventRegistration registration : registrations) {
        MultiMapEventFilter filter = (MultiMapEventFilter) registration.getFilter();
        if (filter.getKey() == null || filter.getKey().equals(key)) {
            Data dataNewValue = filter.isIncludeValue() ? nodeEngine.toData(newValue) : null;
            Data dataOldValue = filter.isIncludeValue() ? nodeEngine.toData(oldValue) : null;
            Address caller = nodeEngine.getThisAddress();
            String source = caller.toString();
            EntryEventData event = new EntryEventData(source, multiMapName, caller, key, dataNewValue, dataOldValue, eventType.getType());
            eventService.publishEvent(MultiMapService.SERVICE_NAME, registration, event, multiMapName.hashCode());
        }
    }
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) Address(com.hazelcast.cluster.Address) EntryEventData(com.hazelcast.map.impl.event.EntryEventData) EventService(com.hazelcast.spi.impl.eventservice.EventService) MapEventData(com.hazelcast.map.impl.event.MapEventData) EntryEventData(com.hazelcast.map.impl.event.EntryEventData) Data(com.hazelcast.internal.serialization.Data)

Aggregations

EventService (com.hazelcast.spi.impl.eventservice.EventService)67 EventRegistration (com.hazelcast.spi.impl.eventservice.EventRegistration)45 UUID (java.util.UUID)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 Address (com.hazelcast.cluster.Address)4 Config (com.hazelcast.config.Config)4 Data (com.hazelcast.internal.serialization.Data)4 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)4 CollectionEventFilter (com.hazelcast.collection.impl.collection.CollectionEventFilter)3 MapEventData (com.hazelcast.map.impl.event.MapEventData)3 AssertTask (com.hazelcast.test.AssertTask)3 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)2 CachePartitionLostListener (com.hazelcast.cache.impl.event.CachePartitionLostListener)2 ItemListener (com.hazelcast.collection.ItemListener)2 DistributedObject (com.hazelcast.core.DistributedObject)2 Nonnull (javax.annotation.Nonnull)2 CacheEventType (com.hazelcast.cache.CacheEventType)1