Search in sources :

Example 61 with EventRegistration

use of com.hazelcast.spi.impl.eventservice.EventRegistration 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)

Example 62 with EventRegistration

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

the class MembershipManager method sendMembershipEventNotifications.

private void sendMembershipEventNotifications(MemberImpl member, Set<Member> members, final boolean added) {
    int eventType = added ? MembershipEvent.MEMBER_ADDED : MembershipEvent.MEMBER_REMOVED;
    node.getNodeExtension().getAuditlogService().eventBuilder(added ? AuditlogTypeIds.CLUSTER_MEMBER_ADDED : AuditlogTypeIds.CLUSTER_MEMBER_REMOVED).message("Membership changed").addParameter("memberAddress", member.getAddress()).log();
    MembershipEvent membershipEvent = new MembershipEvent(clusterService, member, eventType, members);
    Collection<MembershipAwareService> membershipAwareServices = nodeEngine.getServices(MembershipAwareService.class);
    if (membershipAwareServices != null && !membershipAwareServices.isEmpty()) {
        final MembershipServiceEvent event = new MembershipServiceEvent(membershipEvent);
        for (final MembershipAwareService service : membershipAwareServices) {
            nodeEngine.getExecutionService().execute(MEMBERSHIP_EVENT_EXECUTOR_NAME, () -> {
                if (added) {
                    service.memberAdded(event);
                } else {
                    service.memberRemoved(event);
                }
            });
        }
    }
    EventService eventService = nodeEngine.getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, SERVICE_NAME);
    for (EventRegistration reg : registrations) {
        eventService.publishEvent(SERVICE_NAME, reg, membershipEvent, reg.getId().hashCode());
    }
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) MembershipServiceEvent(com.hazelcast.internal.services.MembershipServiceEvent) MembershipEvent(com.hazelcast.cluster.MembershipEvent) MembershipAwareService(com.hazelcast.internal.services.MembershipAwareService) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 63 with EventRegistration

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

the class BatchInvalidator method sendInvalidations.

private void sendInvalidations(String dataStructureName, List<Invalidation> invalidations) {
    // There will always be at least one listener which listens invalidations. This is the reason behind eager creation
    // of BatchNearCacheInvalidation instance here. There is a causality between listener and invalidation. Only if we have
    // a listener, we can have an invalidation, otherwise invalidations are not generated.
    Invalidation invalidation = new BatchNearCacheInvalidation(dataStructureName, invalidations);
    Collection<EventRegistration> registrations = eventService.getRegistrations(serviceName, dataStructureName);
    for (EventRegistration registration : registrations) {
        if (eventFilter.apply(registration)) {
            // find worker queue of striped executor by using subscribers' address.
            // we want to send all batch invalidations belonging to same subscriber go into
            // the same workers queue.
            int orderKey = registration.getSubscriber().hashCode();
            eventService.publishEvent(serviceName, registration, invalidation, orderKey);
        }
    }
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration)

Example 64 with EventRegistration

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

the class Invalidator method sendImmediately.

protected final void sendImmediately(Invalidation invalidation, int orderKey) {
    String dataStructureName = invalidation.getName();
    Collection<EventRegistration> registrations = eventService.getRegistrations(serviceName, dataStructureName);
    for (EventRegistration registration : registrations) {
        if (eventFilter.apply(registration)) {
            eventService.publishEvent(serviceName, registration, invalidation, orderKey);
        }
    }
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration)

Example 65 with EventRegistration

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

the class PartitionEventManager method addPartitionLostListenerAsync.

public CompletableFuture<UUID> addPartitionLostListenerAsync(@Nonnull PartitionLostListener listener) {
    checkNotNull(listener, "listener can't be null");
    final PartitionLostListenerAdapter adapter = new PartitionLostListenerAdapter(listener);
    EventService eventService = nodeEngine.getEventService();
    return eventService.registerListenerAsync(SERVICE_NAME, PARTITION_LOST_EVENT_TOPIC, adapter).thenApplyAsync(EventRegistration::getId, CALLER_RUNS);
}
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