Search in sources :

Example 1 with CachePartitionLostListener

use of com.hazelcast.cache.impl.event.CachePartitionLostListener 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 CachePartitionLostListener

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

the class CachePartitionLostListenerConfigTest method testCachePartitionLostListenerConfig_setImplementation.

@Test
public void testCachePartitionLostListenerConfig_setImplementation() {
    CachePartitionLostListener listener = mock(CachePartitionLostListener.class);
    CachePartitionLostListenerConfig listenerConfig = new CachePartitionLostListenerConfig();
    listenerConfig.setImplementation(listener);
    assertEquals(listener, listenerConfig.getImplementation());
}
Also used : EventCollectingCachePartitionLostListener(com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener) CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with CachePartitionLostListener

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

the class CachePartitionLostListenerConfigTest method testCachePartitionLostListenerReadOnlyConfig_withImplementation.

@Test(expected = UnsupportedOperationException.class)
public void testCachePartitionLostListenerReadOnlyConfig_withImplementation() {
    CachePartitionLostListener listener = mock(CachePartitionLostListener.class);
    CachePartitionLostListenerConfig listenerConfig = new CachePartitionLostListenerConfig(listener);
    CachePartitionLostListenerConfigReadOnly readOnly = listenerConfig.getAsReadOnly();
    assertEquals(listener, readOnly.getImplementation());
    readOnly.setImplementation(mock(CachePartitionLostListener.class));
}
Also used : EventCollectingCachePartitionLostListener(com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener) CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) CachePartitionLostListenerConfigReadOnly(com.hazelcast.config.CachePartitionLostListenerConfigReadOnly) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with CachePartitionLostListener

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

the class CachePartitionLostListenerConfigTest method testEqualsAndHashCode.

@Test
public void testEqualsAndHashCode() {
    CachePartitionLostListener listener = new EventCollectingCachePartitionLostListener(0);
    CachePartitionLostListenerConfig listenerConfig1 = new CachePartitionLostListenerConfig();
    CachePartitionLostListenerConfig listenerConfig2 = new CachePartitionLostListenerConfig();
    assertEquals(listenerConfig1, listenerConfig1);
    assertEquals(listenerConfig1, new CachePartitionLostListenerConfig());
    assertNotEquals(listenerConfig1, null);
    assertNotEquals(listenerConfig1, new Object());
    listenerConfig1.setImplementation(listener);
    assertNotEquals(listenerConfig1, listenerConfig2);
    assertNotEquals(listenerConfig1.hashCode(), listenerConfig2.hashCode());
    listenerConfig2.setImplementation(listener);
    assertEquals(listenerConfig1, listenerConfig2);
    assertEquals(listenerConfig1.hashCode(), listenerConfig2.hashCode());
    listenerConfig1.setClassName("EventCollectingCachePartitionLostListener");
    listenerConfig2.setClassName("CachePartitionLostListenerConfig");
    assertNotEquals(listenerConfig1, listenerConfig2);
    assertNotEquals(listenerConfig1.hashCode(), listenerConfig2.hashCode());
    listenerConfig2.setClassName("EventCollectingCachePartitionLostListener");
    assertEquals(listenerConfig1, listenerConfig2);
    assertEquals(listenerConfig1.hashCode(), listenerConfig2.hashCode());
}
Also used : EventCollectingCachePartitionLostListener(com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener) CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) EventCollectingCachePartitionLostListener(com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with CachePartitionLostListener

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

the class CachePartitionLostListenerConfigTest method testGetImplementation.

@Test
public void testGetImplementation() {
    CachePartitionLostListener listener = new EventCollectingCachePartitionLostListener(0);
    CachePartitionLostListenerConfig listenerConfig = new CachePartitionLostListenerConfig(listener);
    assertEquals(listener, listenerConfig.getImplementation());
}
Also used : EventCollectingCachePartitionLostListener(com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener) CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) EventCollectingCachePartitionLostListener(com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

CachePartitionLostListener (com.hazelcast.cache.impl.event.CachePartitionLostListener)7 ParallelTest (com.hazelcast.test.annotation.ParallelTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 EventCollectingCachePartitionLostListener (com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener)5 CachePartitionLostListenerConfig (com.hazelcast.config.CachePartitionLostListenerConfig)5 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)2 CachePartitionLostEvent (com.hazelcast.cache.impl.event.CachePartitionLostEvent)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 EventService (com.hazelcast.spi.EventService)2 CacheManager (javax.cache.CacheManager)2 ICache (com.hazelcast.cache.ICache)1 CacheService (com.hazelcast.cache.impl.CacheService)1 HazelcastServerCachingProvider.createCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider.createCachingProvider)1 ICacheService (com.hazelcast.cache.impl.ICacheService)1 CachePartitionLostEventFilter (com.hazelcast.cache.impl.event.CachePartitionLostEventFilter)1 InternalCachePartitionLostListenerAdapter (com.hazelcast.cache.impl.event.InternalCachePartitionLostListenerAdapter)1 ClientEndpoint (com.hazelcast.client.ClientEndpoint)1 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1