Search in sources :

Example 1 with EventService

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

the class QueueListenerTest method testItemListener_addedToQueueConfig_Issue366.

@Test
public void testItemListener_addedToQueueConfig_Issue366() throws Exception {
    String queueName = "Q";
    int totalQueuePut = 2000;
    CountdownItemListener countdownItemListener = new CountdownItemListener(totalQueuePut, 0);
    Config config = getConfig();
    ItemListenerConfig itemListenerConfig = new ItemListenerConfig().setImplementation(countdownItemListener).setIncludeValue(true);
    config.getQueueConfig(queueName).addItemListenerConfig(itemListenerConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance = factory.newHazelcastInstance(config);
    IQueue<VersionedObject<Integer>> queue = instance.getQueue(queueName);
    for (int i = 0; i < totalQueuePut / 2; i++) {
        queue.put(new VersionedObject<>(i));
    }
    HazelcastInstance second = factory.newHazelcastInstance(config);
    assertTrueEventually(() -> {
        EventService eventService1 = getNodeEngineImpl(instance).getEventService();
        EventService eventService2 = getNodeEngineImpl(second).getEventService();
        assertEquals(2, eventService1.getRegistrations(QueueService.SERVICE_NAME, queueName).size());
        assertEquals(2, eventService2.getRegistrations(QueueService.SERVICE_NAME, queueName).size());
    });
    for (int i = 0; i < totalQueuePut / 4; i++) {
        queue.put(new VersionedObject<>(i));
    }
    assertOpenEventually(countdownItemListener.added);
}
Also used : VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) HazelcastInstance(com.hazelcast.core.HazelcastInstance) QueueConfig(com.hazelcast.config.QueueConfig) Config(com.hazelcast.config.Config) ItemListenerConfig(com.hazelcast.config.ItemListenerConfig) ItemListenerConfig(com.hazelcast.config.ItemListenerConfig) EventService(com.hazelcast.spi.impl.eventservice.EventService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with EventService

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

the class AbstractCollectionProxyImpl method addItemListener.

@Nonnull
public UUID addItemListener(@Nonnull ItemListener<E> listener, boolean includeValue) {
    checkNotNull(listener, "Null listener is not allowed!");
    final EventService eventService = getNodeEngine().getEventService();
    final CollectionEventFilter filter = new CollectionEventFilter(includeValue);
    final EventRegistration registration = eventService.registerListener(getServiceName(), name, filter, listener);
    return registration.getId();
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService) Nonnull(javax.annotation.Nonnull)

Example 3 with EventService

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

the class RemoveCPMembershipListenerMessageTask method processInternal.

@Override
protected CompletableFuture<Boolean> processInternal() {
    UUID registrationId = this.parameters;
    endpoint.removeDestroyAction(registrationId);
    EventService eventService = clientEngine.getEventService();
    return eventService.deregisterListenerAsync(getServiceName(), EVENT_TOPIC_MEMBERSHIP, registrationId);
}
Also used : EventService(com.hazelcast.spi.impl.eventservice.EventService) UUID(java.util.UUID)

Example 4 with EventService

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

the class PartitionEventManager method addMigrationListenerAsync.

public CompletableFuture<UUID> addMigrationListenerAsync(@Nonnull MigrationListener listener) {
    checkNotNull(listener, "listener can't be null");
    final MigrationListenerAdapter adapter = new MigrationListenerAdapter(listener);
    EventService eventService = nodeEngine.getEventService();
    return eventService.registerListenerAsync(SERVICE_NAME, MIGRATION_EVENT_TOPIC, adapter).thenApplyAsync(EventRegistration::getId, CALLER_RUNS);
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 5 with EventService

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

the class PartitionEventManager method addMigrationListener.

public UUID addMigrationListener(@Nonnull MigrationListener listener) {
    checkNotNull(listener, "listener can't be null");
    final MigrationListenerAdapter adapter = new MigrationListenerAdapter(listener);
    EventService eventService = nodeEngine.getEventService();
    EventRegistration registration = eventService.registerListener(SERVICE_NAME, MIGRATION_EVENT_TOPIC, adapter);
    return registration.getId();
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

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