Search in sources :

Example 1 with InternalCachePartitionLostListenerAdapter

use of com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter in project hazelcast by hazelcast.

the class CacheAddPartitionLostListenerMessageTask method call.

@Override
protected Object call() {
    final ClientEndpoint endpoint = getEndpoint();
    CachePartitionLostListener listener = new CachePartitionLostListener() {

        @Override
        public void partitionLost(CachePartitionLostEvent event) {
            if (endpoint.isAlive()) {
                ClientMessage eventMessage = CacheAddPartitionLostListenerCodec.encodeCachePartitionLostEvent(event.getPartitionId(), event.getMember().getUuid());
                sendClientMessage(null, eventMessage);
            }
        }
    };
    InternalCachePartitionLostListenerAdapter listenerAdapter = new InternalCachePartitionLostListenerAdapter(listener);
    EventFilter filter = new CachePartitionLostEventFilter();
    CacheService service = getService(CacheService.SERVICE_NAME);
    EventService eventService = service.getNodeEngine().getEventService();
    EventRegistration registration;
    if (parameters.localOnly) {
        registration = eventService.registerLocalListener(ICacheService.SERVICE_NAME, parameters.name, filter, listenerAdapter);
    } else {
        registration = eventService.registerListener(ICacheService.SERVICE_NAME, parameters.name, filter, listenerAdapter);
    }
    String registrationId = registration.getId();
    endpoint.addListenerDestroyAction(CacheService.SERVICE_NAME, parameters.name, registrationId);
    return registrationId;
}
Also used : CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) EventRegistration(com.hazelcast.spi.EventRegistration) CachePartitionLostEvent(com.hazelcast.cache.impl.event.CachePartitionLostEvent) EventService(com.hazelcast.spi.EventService) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientEndpoint(com.hazelcast.client.ClientEndpoint) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) EventFilter(com.hazelcast.spi.EventFilter) InternalCachePartitionLostListenerAdapter(com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter) CacheService(com.hazelcast.cache.impl.CacheService) ICacheService(com.hazelcast.cache.impl.ICacheService)

Example 2 with InternalCachePartitionLostListenerAdapter

use of com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter in project hazelcast by hazelcast.

the class CacheProxy method addPartitionLostListener.

@Override
public String addPartitionLostListener(CachePartitionLostListener listener) {
    checkNotNull(listener, "CachePartitionLostListener can't be null");
    EventFilter filter = new CachePartitionLostEventFilter();
    InternalCachePartitionLostListenerAdapter listenerAdapter = new InternalCachePartitionLostListenerAdapter(listener);
    injectDependencies(listener);
    EventRegistration registration = getService().getNodeEngine().getEventService().registerListener(AbstractCacheService.SERVICE_NAME, name, filter, listenerAdapter);
    return registration.getId();
}
Also used : EventRegistration(com.hazelcast.spi.EventRegistration) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) CachePartitionLostEventFilter(com.hazelcast.cache.impl.event.CachePartitionLostEventFilter) EventFilter(com.hazelcast.spi.EventFilter) InternalCachePartitionLostListenerAdapter(com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter)

Aggregations

CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)2 InternalCachePartitionLostListenerAdapter (com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter)2 EventFilter (com.hazelcast.spi.EventFilter)2 EventRegistration (com.hazelcast.spi.EventRegistration)2 CacheService (com.hazelcast.cache.impl.CacheService)1 ICacheService (com.hazelcast.cache.impl.ICacheService)1 CachePartitionLostEvent (com.hazelcast.cache.impl.event.CachePartitionLostEvent)1 CachePartitionLostListener (com.hazelcast.cache.impl.event.CachePartitionLostListener)1 ClientEndpoint (com.hazelcast.client.ClientEndpoint)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 EventService (com.hazelcast.spi.EventService)1