Search in sources :

Example 36 with EventService

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

the class PartitionEventManager method addLocalPartitionLostListener.

public String addLocalPartitionLostListener(PartitionLostListener listener) {
    if (listener == null) {
        throw new NullPointerException("listener can't be null");
    }
    final PartitionLostListenerAdapter adapter = new PartitionLostListenerAdapter(listener);
    EventService eventService = nodeEngine.getEventService();
    EventRegistration registration = eventService.registerLocalListener(SERVICE_NAME, PARTITION_LOST_EVENT_TOPIC, adapter);
    return registration.getId();
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) EventService(com.hazelcast.spi.EventService)

Example 37 with EventService

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

the class PartitionEventManager method sendMigrationEvent.

void sendMigrationEvent(final MigrationInfo migrationInfo, final MigrationEvent.MigrationStatus status) {
    if (migrationInfo.getSourceCurrentReplicaIndex() != 0 && migrationInfo.getDestinationNewReplicaIndex() != 0) {
        // only fire events for 0th replica migrations
        return;
    }
    ClusterServiceImpl clusterService = node.getClusterService();
    MemberImpl current = clusterService.getMember(migrationInfo.getSource());
    MemberImpl newOwner = clusterService.getMember(migrationInfo.getDestination());
    MigrationEvent event = new MigrationEvent(migrationInfo.getPartitionId(), current, newOwner, status);
    EventService eventService = nodeEngine.getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, MIGRATION_EVENT_TOPIC);
    eventService.publishEvent(SERVICE_NAME, registrations, event, event.getPartitionId());
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) MemberImpl(com.hazelcast.instance.MemberImpl) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) EventService(com.hazelcast.spi.EventService) MigrationEvent(com.hazelcast.core.MigrationEvent)

Example 38 with EventService

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

the class MultiMapOperation method hasListener.

public final boolean hasListener() {
    EventService eventService = getNodeEngine().getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(getServiceName(), name);
    return registrations.size() > 0;
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) EventService(com.hazelcast.spi.EventService)

Example 39 with EventService

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

the class ClientEndpointImpl method addListenerDestroyAction.

@Override
public void addListenerDestroyAction(final String service, final String topic, final String id) {
    final EventService eventService = clientEngine.getEventService();
    addDestroyAction(id, new Callable<Boolean>() {

        @Override
        public Boolean call() {
            return eventService.deregisterListener(service, topic, id);
        }
    });
}
Also used : EventService(com.hazelcast.spi.EventService)

Example 40 with EventService

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

the class AbstractCacheService method deregisterAllListener.

@Override
public void deregisterAllListener(String name) {
    EventService eventService = getNodeEngine().getEventService();
    Collection<EventRegistration> registrations = eventService.getRegistrations(SERVICE_NAME, name);
    if (registrations != null) {
        for (EventRegistration registration : registrations) {
            Closeable listener = closeableListeners.remove(registration.getId());
            if (listener != null) {
                IOUtil.closeResource(listener);
            }
        }
    }
    eventService.deregisterAllListeners(AbstractCacheService.SERVICE_NAME, name);
    CacheContext cacheContext = cacheContexts.get(name);
    if (cacheContext != null) {
        cacheContext.resetCacheEntryListenerCount();
        cacheContext.resetInvalidationListenerCount();
    }
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) Closeable(java.io.Closeable) EventService(com.hazelcast.spi.EventService)

Aggregations

EventService (com.hazelcast.spi.EventService)49 EventRegistration (com.hazelcast.spi.EventRegistration)37 Address (com.hazelcast.nio.Address)5 NodeEngine (com.hazelcast.spi.NodeEngine)5 QueryCacheEventService (com.hazelcast.map.impl.querycache.QueryCacheEventService)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Collection (java.util.Collection)4 Test (org.junit.Test)4 ClientEndpoint (com.hazelcast.client.ClientEndpoint)3 CollectionEventFilter (com.hazelcast.collection.impl.collection.CollectionEventFilter)3 Config (com.hazelcast.config.Config)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 MapEventData (com.hazelcast.map.impl.event.MapEventData)3 Data (com.hazelcast.nio.serialization.Data)3 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)2 CachePartitionLostListener (com.hazelcast.cache.impl.event.CachePartitionLostListener)2 InitialMembershipEvent (com.hazelcast.core.InitialMembershipEvent)2 ItemListener (com.hazelcast.core.ItemListener)2 Member (com.hazelcast.core.Member)2