Search in sources :

Example 11 with EventService

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

the class MultiMapService method addLocalListener.

public UUID addLocalListener(String name, @Nonnull EventListener listener, Data key, boolean includeValue) {
    EventService eventService = nodeEngine.getEventService();
    MultiMapEventFilter filter = new MultiMapEventFilter(includeValue, key);
    return eventService.registerLocalListener(SERVICE_NAME, name, filter, listener).getId();
}
Also used : EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 12 with EventService

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

the class ProxyRegistry method doCreateProxy.

private DistributedObjectFuture doCreateProxy(String name, UUID source, boolean initialize, DistributedObjectFuture proxyFuture, boolean local) {
    boolean publishEvent = !local;
    DistributedObject proxy;
    try {
        TenantControlServiceImpl tenantControlService = proxyService.nodeEngine.getTenantControlService();
        TenantControl tenantControl = tenantControlService.getTenantControl(serviceName, name);
        if (tenantControl == null) {
            if (initialize && service instanceof TenantContextAwareService) {
                try {
                    tenantControl = tenantControlService.initializeTenantControl(serviceName, name);
                } catch (Exception e) {
                    // log and throw exception to be handled in outer catch block
                    proxyService.logger.warning("Error while initializing tenant control for service '" + serviceName + "' and object '" + name + "'", e);
                    throw e;
                }
            } else {
                tenantControl = TenantControl.NOOP_TENANT_CONTROL;
            }
        }
        proxy = service.createDistributedObject(name, source, local);
        tenantControl.registerObject(proxy.getDestroyContextForTenant());
        if (initialize && proxy instanceof InitializingObject) {
            try {
                ((InitializingObject) proxy).initialize();
            } catch (Exception e) {
                // log and throw exception to be handled in outer catch block
                proxyService.logger.warning("Error while initializing proxy: " + proxy, e);
                throw e;
            }
        }
        proxyFuture.set(proxy, initialize);
        if (INTERNAL_OBJECTS_PREFIXES.stream().noneMatch(name::startsWith)) {
            createdCounter.inc();
        }
    } catch (Throwable e) {
        // proxy creation or initialization failed
        // deregister future to avoid infinite hang on future.get()
        proxyFuture.setError(e);
        proxies.remove(name);
        throw rethrow(e);
    }
    EventService eventService = proxyService.nodeEngine.getEventService();
    ProxyEventProcessor callback = new ProxyEventProcessor(proxyService.listeners.values(), CREATED, serviceName, name, proxy, source);
    eventService.executeEventCallback(callback);
    if (publishEvent) {
        publish(new DistributedObjectEventPacket(CREATED, serviceName, name, source));
    }
    return proxyFuture;
}
Also used : AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) DistributedObject(com.hazelcast.core.DistributedObject) InitializingObject(com.hazelcast.spi.impl.InitializingObject) TenantControlServiceImpl(com.hazelcast.spi.impl.tenantcontrol.impl.TenantControlServiceImpl) EventService(com.hazelcast.spi.impl.eventservice.EventService) TenantContextAwareService(com.hazelcast.internal.services.TenantContextAwareService) TenantControl(com.hazelcast.spi.tenantcontrol.TenantControl) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) DistributedObjectDestroyedException(com.hazelcast.spi.exception.DistributedObjectDestroyedException) HazelcastException(com.hazelcast.core.HazelcastException)

Example 13 with EventService

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

the class QueueService method addItemListenerAsync.

public CompletableFuture<UUID> addItemListenerAsync(String name, ItemListener listener, boolean includeValue) {
    EventService eventService = nodeEngine.getEventService();
    QueueEventFilter filter = new QueueEventFilter(includeValue);
    return eventService.registerListenerAsync(QueueService.SERVICE_NAME, name, filter, listener).thenApplyAsync(EventRegistration::getId, CALLER_RUNS);
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 14 with EventService

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

the class QueueService method addItemListener.

public UUID addItemListener(String name, ItemListener listener, boolean includeValue) {
    EventService eventService = nodeEngine.getEventService();
    QueueEventFilter filter = new QueueEventFilter(includeValue);
    return eventService.registerListener(QueueService.SERVICE_NAME, name, filter, listener).getId();
}
Also used : EventService(com.hazelcast.spi.impl.eventservice.EventService)

Example 15 with EventService

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

the class AbstractCacheService method publishCachePartitionLostEvent.

protected void publishCachePartitionLostEvent(String cacheName, int partitionId) {
    Collection<EventRegistration> registrations = new LinkedList<>();
    for (EventRegistration registration : getRegistrations(cacheName)) {
        if (registration.getFilter() instanceof CachePartitionLostEventFilter) {
            registrations.add(registration);
        }
    }
    if (registrations.isEmpty()) {
        return;
    }
    Member member = nodeEngine.getLocalMember();
    CacheEventData eventData = new CachePartitionEventData(cacheName, partitionId, member);
    EventService eventService = nodeEngine.getEventService();
    eventService.publishEvent(SERVICE_NAME, registrations, eventData, partitionId);
}
Also used : EventRegistration(com.hazelcast.spi.impl.eventservice.EventRegistration) EventService(com.hazelcast.spi.impl.eventservice.EventService) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) Member(com.hazelcast.cluster.Member) LinkedList(java.util.LinkedList)

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