use of com.hazelcast.map.listener.MapPartitionLostListener in project hazelcast by hazelcast.
the class MapAddPartitionLostListenerMessageTask method call.
@Override
protected Object call() {
final ClientEndpoint endpoint = getEndpoint();
final MapService mapService = getService(MapService.SERVICE_NAME);
final MapPartitionLostListener listener = new MapPartitionLostListener() {
@Override
public void partitionLost(MapPartitionLostEvent event) {
if (endpoint.isAlive()) {
ClientMessage eventMessage = MapAddPartitionLostListenerCodec.encodeMapPartitionLostEvent(event.getPartitionId(), event.getMember().getUuid());
sendClientMessage(null, eventMessage);
}
}
};
MapServiceContext mapServiceContext = mapService.getMapServiceContext();
String registrationId;
if (parameters.localOnly) {
registrationId = mapServiceContext.addLocalPartitionLostListener(listener, parameters.name);
} else {
registrationId = mapServiceContext.addPartitionLostListener(listener, parameters.name);
}
endpoint.addListenerDestroyAction(MapService.SERVICE_NAME, parameters.name, registrationId);
return registrationId;
}
use of com.hazelcast.map.listener.MapPartitionLostListener in project hazelcast by hazelcast.
the class MapConfigTest method testMapPartitionLostListenerReadOnlyConfig_withImplementation.
@Test(expected = UnsupportedOperationException.class)
public void testMapPartitionLostListenerReadOnlyConfig_withImplementation() {
MapPartitionLostListener listener = mock(MapPartitionLostListener.class);
MapPartitionLostListenerConfig listenerConfig = new MapPartitionLostListenerConfig(listener);
MapPartitionLostListenerConfigReadOnly readOnly = listenerConfig.getAsReadOnly();
assertEquals(listener, readOnly.getImplementation());
readOnly.setImplementation(mock(MapPartitionLostListener.class));
}
use of com.hazelcast.map.listener.MapPartitionLostListener in project hazelcast by hazelcast.
the class ListenerTest method testMapPartitionLostListener_registeredViaImplementationInConfigObject.
@Test
public void testMapPartitionLostListener_registeredViaImplementationInConfigObject() {
final String name = randomString();
Config config = getConfig();
MapConfig mapConfig = config.getMapConfig(name);
MapPartitionLostListener listener = mock(MapPartitionLostListener.class);
mapConfig.addMapPartitionLostListenerConfig(new MapPartitionLostListenerConfig(listener));
mapConfig.setBackupCount(0);
HazelcastInstance instance = createHazelcastInstance(config);
instance.getMap(name);
final EventService eventService = getNode(instance).getNodeEngine().getEventService();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
final Collection<EventRegistration> registrations = eventService.getRegistrations(MapService.SERVICE_NAME, name);
assertFalse(registrations.isEmpty());
}
});
}
use of com.hazelcast.map.listener.MapPartitionLostListener in project hazelcast by hazelcast.
the class MapConfigTest method testMapPartitionLostListener_equalsWithImplementation.
@Test
public void testMapPartitionLostListener_equalsWithImplementation() {
MapPartitionLostListener listener = mock(MapPartitionLostListener.class);
MapPartitionLostListenerConfig config1 = new MapPartitionLostListenerConfig();
config1.setImplementation(listener);
MapPartitionLostListenerConfig config2 = new MapPartitionLostListenerConfig();
config2.setImplementation(listener);
MapPartitionLostListenerConfig config3 = new MapPartitionLostListenerConfig();
assertEquals(config1, config2);
assertNotEquals(config1, config3);
assertNotEquals(config2, config3);
}
use of com.hazelcast.map.listener.MapPartitionLostListener in project hazelcast by hazelcast.
the class MapConfigTest method testMapPartitionLostListenerConfig.
@Test
public void testMapPartitionLostListenerConfig() {
MapConfig mapConfig = new MapConfig();
MapPartitionLostListener listener = mock(MapPartitionLostListener.class);
mapConfig.addMapPartitionLostListenerConfig(new MapPartitionLostListenerConfig(listener));
MapPartitionLostListenerConfig listenerConfig = new MapPartitionLostListenerConfig();
listenerConfig.setImplementation(listener);
mapConfig.addMapPartitionLostListenerConfig(listenerConfig);
List<MapPartitionLostListenerConfig> listenerConfigs = mapConfig.getPartitionLostListenerConfigs();
assertEquals(2, listenerConfigs.size());
assertEquals(listener, listenerConfigs.get(0).getImplementation());
assertEquals(listener, listenerConfigs.get(1).getImplementation());
}
Aggregations