Search in sources :

Example 56 with EventService

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

the class AddCPGroupAvailabilityListenerMessageTask method processInternal.

@Override
protected CompletableFuture<UUID> processInternal() {
    EventService eventService = clientEngine.getEventService();
    CPGroupAvailabilityListener listener = new ClientCPGroupAvailabilityListener(endpoint);
    boolean local = parameters;
    if (local) {
        UUID id = eventService.registerLocalListener(getServiceName(), TOPIC, listener).getId();
        return CompletableFuture.completedFuture(id);
    }
    return eventService.registerListenerAsync(getServiceName(), TOPIC, listener).thenApplyAsync(EventRegistration::getId, CALLER_RUNS);
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService) UUID(java.util.UUID) CPGroupAvailabilityListener(com.hazelcast.cp.event.CPGroupAvailabilityListener)

Example 57 with EventService

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

the class MetadataRaftGroupManager method sendMembershipEvents.

private void sendMembershipEvents(Collection<CPMemberInfo> currentMembers, Collection<CPMemberInfo> newMembers) {
    if (!isMetadataGroupLeader()) {
        return;
    }
    EventService eventService = nodeEngine.getEventService();
    Collection<CPMemberInfo> addedMembers = new LinkedHashSet<>(newMembers);
    addedMembers.removeAll(currentMembers);
    for (CPMemberInfo member : addedMembers) {
        CPMembershipEvent event = new CPMembershipEventImpl(member, EventType.ADDED);
        eventService.publishEvent(SERVICE_NAME, EVENT_TOPIC_MEMBERSHIP, event, EVENT_TOPIC_MEMBERSHIP.hashCode());
    }
    Collection<CPMemberInfo> removedMembers = new LinkedHashSet<>(currentMembers);
    removedMembers.removeAll(newMembers);
    for (CPMemberInfo member : removedMembers) {
        CPMembershipEvent event = new CPMembershipEventImpl(member, EventType.REMOVED);
        eventService.publishEvent(SERVICE_NAME, EVENT_TOPIC_MEMBERSHIP, event, EVENT_TOPIC_MEMBERSHIP.hashCode());
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) EventService(com.hazelcast.spi.impl.eventservice.EventService) CPMembershipEvent(com.hazelcast.cp.event.CPMembershipEvent) CPMembershipEventImpl(com.hazelcast.cp.event.impl.CPMembershipEventImpl)

Example 58 with EventService

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

the class AddCPMembershipListenerMessageTask method processInternal.

@Override
protected CompletableFuture<UUID> processInternal() {
    EventService eventService = clientEngine.getEventService();
    CPMembershipListener listener = new ClientCPMembershipListener(endpoint);
    boolean local = parameters;
    if (local) {
        UUID id = eventService.registerLocalListener(getServiceName(), TOPIC, listener).getId();
        return CompletableFuture.completedFuture(id);
    }
    return eventService.registerListenerAsync(getServiceName(), TOPIC, listener).thenApplyAsync(EventRegistration::getId, CALLER_RUNS);
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) CPMembershipListener(com.hazelcast.cp.event.CPMembershipListener) EventService(com.hazelcast.spi.impl.eventservice.EventService) UUID(java.util.UUID)

Example 59 with EventService

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

the class ClusterServiceImpl method removeMembershipListener.

public boolean removeMembershipListener(@Nonnull UUID registrationId) {
    checkNotNull(registrationId, "registrationId cannot be null");
    EventService eventService = nodeEngine.getEventService();
    return eventService.deregisterListener(SERVICE_NAME, SERVICE_NAME, registrationId);
}
Also used : EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 60 with EventService

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

the class ClusterServiceImpl method addMembershipListener.

@Nonnull
public UUID addMembershipListener(@Nonnull MembershipListener listener) {
    checkNotNull(listener, "listener cannot be null");
    EventService eventService = nodeEngine.getEventService();
    EventRegistration registration;
    if (listener instanceof InitialMembershipListener) {
        lock.lock();
        try {
            ((InitialMembershipListener) listener).init(new InitialMembershipEvent(this, getMembers()));
            registration = eventService.registerLocalListener(SERVICE_NAME, SERVICE_NAME, listener);
        } finally {
            lock.unlock();
        }
    } else {
        registration = eventService.registerLocalListener(SERVICE_NAME, SERVICE_NAME, listener);
    }
    return registration.getId();
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) InitialMembershipListener(com.hazelcast.cluster.InitialMembershipListener) EventService(com.hazelcast.spi.impl.eventservice.EventService) InitialMembershipEvent(com.hazelcast.cluster.InitialMembershipEvent) Nonnull(javax.annotation.Nonnull)

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