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;
}
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());
}
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));
}
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());
}
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());
}
Aggregations