Search in sources :

Example 1 with MapPartitionLostListener

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;
}
Also used : MapPartitionLostListener(com.hazelcast.map.listener.MapPartitionLostListener) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientEndpoint(com.hazelcast.client.ClientEndpoint) MapService(com.hazelcast.map.impl.MapService) MapPartitionLostEvent(com.hazelcast.map.MapPartitionLostEvent) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 2 with MapPartitionLostListener

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));
}
Also used : MapPartitionLostListener(com.hazelcast.map.listener.MapPartitionLostListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with MapPartitionLostListener

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());
        }
    });
}
Also used : MapPartitionLostListener(com.hazelcast.map.listener.MapPartitionLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection) EventService(com.hazelcast.spi.EventService) MapConfig(com.hazelcast.config.MapConfig) IOException(java.io.IOException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with MapPartitionLostListener

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);
}
Also used : MapPartitionLostListener(com.hazelcast.map.listener.MapPartitionLostListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with MapPartitionLostListener

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());
}
Also used : MapPartitionLostListener(com.hazelcast.map.listener.MapPartitionLostListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MapPartitionLostListener (com.hazelcast.map.listener.MapPartitionLostListener)5 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 ClientEndpoint (com.hazelcast.client.ClientEndpoint)1 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 Config (com.hazelcast.config.Config)1 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)1 MapConfig (com.hazelcast.config.MapConfig)1 MapPartitionLostListenerConfig (com.hazelcast.config.MapPartitionLostListenerConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 MapPartitionLostEvent (com.hazelcast.map.MapPartitionLostEvent)1 MapService (com.hazelcast.map.impl.MapService)1 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)1 EventService (com.hazelcast.spi.EventService)1 AssertTask (com.hazelcast.test.AssertTask)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1