Search in sources :

Example 26 with EventRegistration

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

the class ClientMapIssueTest method testListenerRegistrations.

@Test
public void testListenerRegistrations() {
    Config config = getConfig();
    ClientConfig clientConfig = getClientConfig();
    HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    final String mapName = randomMapName();
    IMap<Object, Object> map = client.getMap(mapName);
    map.addEntryListener(new EntryAdapter<>(), true);
    HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance(config);
    instance1.getLifecycleService().terminate();
    instance1 = hazelcastFactory.newHazelcastInstance(config);
    final EventService eventService1 = getNodeEngineImpl(instance1).getEventService();
    final EventService eventService2 = getNodeEngineImpl(instance2).getEventService();
    assertTrueEventually(() -> {
        Collection<EventRegistration> regs1 = eventService1.getRegistrations(MapService.SERVICE_NAME, mapName);
        Collection<EventRegistration> regs2 = eventService2.getRegistrations(MapService.SERVICE_NAME, mapName);
        assertEquals("there should be only one registration", 1, regs1.size());
        assertEquals("there should be only one registration", 1, regs2.size());
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) EventService(com.hazelcast.spi.impl.eventservice.EventService) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 27 with EventRegistration

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

the class ClientMapPartitionLostListenerTest method assertRegistrationEventually.

private static void assertRegistrationEventually(final HazelcastInstance instance, final String mapName, final boolean shouldBeRegistered) {
    final EventService eventService = getNode(instance).getNodeEngine().getEventService();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            boolean registered = false;
            for (EventRegistration registration : eventService.getRegistrations(SERVICE_NAME, mapName)) {
                if (registration.getFilter() instanceof MapPartitionLostEventFilter) {
                    registered = true;
                    break;
                }
            }
            if (shouldBeRegistered != registered) {
                fail("shouldBeRegistered: " + shouldBeRegistered + " registered: " + registered);
            }
        }
    });
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) MapPartitionLostEventFilter(com.hazelcast.map.impl.MapPartitionLostEventFilter) AssertTask(com.hazelcast.test.AssertTask) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 28 with EventRegistration

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

the class AbstractCacheRecordStore method closeListeners.

protected void closeListeners() {
    EventService eventService = cacheService.getNodeEngine().getEventService();
    Collection<EventRegistration> candidates = eventService.getRegistrations(ICacheService.SERVICE_NAME, name);
    for (EventRegistration eventRegistration : candidates) {
        eventService.close(eventRegistration);
    }
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 29 with EventRegistration

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

the class AbstractCacheService method registerListener.

@Override
public UUID registerListener(String cacheNameWithPrefix, CacheEventListener listener) {
    EventService eventService = getNodeEngine().getEventService();
    EventRegistration registration = eventService.registerListener(AbstractCacheService.SERVICE_NAME, cacheNameWithPrefix, listener);
    return updateRegisteredListeners(listener, registration);
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 30 with EventRegistration

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

the class AbstractCacheService method registerLocalListener.

@Override
public UUID registerLocalListener(String cacheNameWithPrefix, CacheEventListener listener, EventFilter eventFilter) {
    EventService eventService = getNodeEngine().getEventService();
    EventRegistration registration = eventService.registerLocalListener(AbstractCacheService.SERVICE_NAME, cacheNameWithPrefix, eventFilter, listener);
    if (registration == null) {
        return null;
    }
    return updateRegisteredListeners(listener, registration);
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Aggregations

EventRegistration (com.hazelcast.spi.impl.eventservice.EventRegistration)67 EventService (com.hazelcast.spi.impl.eventservice.EventService)45 Data (com.hazelcast.internal.serialization.Data)8 EventFilter (com.hazelcast.spi.impl.eventservice.EventFilter)7 UUID (java.util.UUID)7 Address (com.hazelcast.cluster.Address)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 ListenerAdapters.createListenerAdapter (com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter)4 QueryCacheListenerAdapter (com.hazelcast.map.impl.querycache.QueryCacheListenerAdapter)4 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)3 CollectionEventFilter (com.hazelcast.collection.impl.collection.CollectionEventFilter)3 MapPartitionLostEventFilter (com.hazelcast.map.impl.MapPartitionLostEventFilter)3 MapEventData (com.hazelcast.map.impl.event.MapEventData)3 Registration (com.hazelcast.spi.impl.eventservice.impl.Registration)3 InternalCachePartitionLostListenerAdapter (com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter)2 ItemListener (com.hazelcast.collection.ItemListener)2 EntryEventFilter (com.hazelcast.map.impl.EntryEventFilter)2 EntryEventData (com.hazelcast.map.impl.event.EntryEventData)2 AssertTask (com.hazelcast.test.AssertTask)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2