Search in sources :

Example 61 with EventService

use of com.hazelcast.spi.impl.eventservice.EventService 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 62 with EventService

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

Example 63 with EventService

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

the class PartitionEventManager method removeMigrationListenerAsync.

public CompletableFuture<Boolean> removeMigrationListenerAsync(@Nonnull UUID registrationId) {
    checkNotNull(registrationId, "registrationId can't be null");
    EventService eventService = nodeEngine.getEventService();
    return eventService.deregisterListenerAsync(SERVICE_NAME, MIGRATION_EVENT_TOPIC, registrationId);
}
Also used : EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 64 with EventService

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

the class PartitionEventManager method registerLocalListener.

private UUID registerLocalListener(PartitionEventListener<?> adapter, String topic) {
    EventService eventService = nodeEngine.getEventService();
    EventRegistration registration = eventService.registerLocalListener(SERVICE_NAME, topic, adapter);
    return registration.getId();
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 65 with EventService

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

the class PartitionEventManager method sendMigrationEvent.

private void sendMigrationEvent(ReplicaMigrationEvent event) {
    EventService eventService = nodeEngine.getEventService();
    // All migration events are sent in order.
    eventService.publishEvent(SERVICE_NAME, MIGRATION_EVENT_TOPIC, event, MIGRATION_EVENT_TOPIC.hashCode());
}
Also used : 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