Search in sources :

Example 1 with MigrationListener

use of com.hazelcast.core.MigrationListener in project hazelcast by hazelcast.

the class PartitionMigrationListenerTest method testAddMigrationListener_whenListenerRegisteredTwice.

@Test
public void testAddMigrationListener_whenListenerRegisteredTwice() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance hz1 = factory.newHazelcastInstance();
    PartitionService partitionService = hz1.getPartitionService();
    MigrationListener listener = mock(MigrationListener.class);
    String id1 = partitionService.addMigrationListener(listener);
    String id2 = partitionService.addMigrationListener(listener);
    // first we check if the registration id's are different
    assertNotEquals(id1, id2);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PartitionService(com.hazelcast.core.PartitionService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) MigrationListener(com.hazelcast.core.MigrationListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with MigrationListener

use of com.hazelcast.core.MigrationListener in project hazelcast by hazelcast.

the class PartitionMigrationListenerTest method testRemoveMigrationListener.

@Test
public void testRemoveMigrationListener() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance hz1 = factory.newHazelcastInstance();
    PartitionService partitionService = hz1.getPartitionService();
    MigrationListener listener = mock(MigrationListener.class);
    String id = partitionService.addMigrationListener(listener);
    boolean removed = partitionService.removeMigrationListener(id);
    assertTrue(removed);
    // now we add a member
    HazelcastInstance hz2 = factory.newHazelcastInstance();
    warmUpPartitions(hz1, hz2);
    // and verify that the listener isn't called.
    verify(listener, never()).migrationStarted(any(MigrationEvent.class));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PartitionService(com.hazelcast.core.PartitionService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) MigrationListener(com.hazelcast.core.MigrationListener) MigrationEvent(com.hazelcast.core.MigrationEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with MigrationListener

use of com.hazelcast.core.MigrationListener in project hazelcast by hazelcast.

the class Node method initializeListeners.

@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" })
private void initializeListeners(Config config) {
    for (final ListenerConfig listenerCfg : config.getListenerConfigs()) {
        Object listener = listenerCfg.getImplementation();
        if (listener == null) {
            try {
                listener = ClassLoaderUtil.newInstance(configClassLoader, listenerCfg.getClassName());
            } catch (Exception e) {
                logger.severe(e);
            }
        }
        if (listener instanceof HazelcastInstanceAware) {
            ((HazelcastInstanceAware) listener).setHazelcastInstance(hazelcastInstance);
        }
        boolean known = false;
        if (listener instanceof DistributedObjectListener) {
            final ProxyServiceImpl proxyService = (ProxyServiceImpl) nodeEngine.getProxyService();
            proxyService.addProxyListener((DistributedObjectListener) listener);
            known = true;
        }
        if (listener instanceof MembershipListener) {
            clusterService.addMembershipListener((MembershipListener) listener);
            known = true;
        }
        if (listener instanceof MigrationListener) {
            partitionService.addMigrationListener((MigrationListener) listener);
            known = true;
        }
        if (listener instanceof PartitionLostListener) {
            partitionService.addPartitionLostListener((PartitionLostListener) listener);
            known = true;
        }
        if (listener instanceof LifecycleListener) {
            hazelcastInstance.lifecycleService.addLifecycleListener((LifecycleListener) listener);
            known = true;
        }
        if (listener instanceof ClientListener) {
            String serviceName = ClientEngineImpl.SERVICE_NAME;
            nodeEngine.getEventService().registerLocalListener(serviceName, serviceName, listener);
            known = true;
        }
        if (listener instanceof InternalMigrationListener) {
            final InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) nodeEngine.getPartitionService();
            partitionService.setInternalMigrationListener((InternalMigrationListener) listener);
            known = true;
        }
        if (nodeExtension.registerListener(listener)) {
            known = true;
        }
        if (listener != null && !known) {
            final String error = "Unknown listener type: " + listener.getClass();
            Throwable t = new IllegalArgumentException(error);
            logger.warning(error, t);
        }
    }
}
Also used : InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalMigrationListener(com.hazelcast.internal.partition.impl.InternalMigrationListener) LifecycleListener(com.hazelcast.core.LifecycleListener) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware) DistributedObjectListener(com.hazelcast.core.DistributedObjectListener) ProxyServiceImpl(com.hazelcast.spi.impl.proxyservice.impl.ProxyServiceImpl) ClientListener(com.hazelcast.core.ClientListener) ListenerConfig(com.hazelcast.config.ListenerConfig) PartitionLostListener(com.hazelcast.partition.PartitionLostListener) MembershipListener(com.hazelcast.core.MembershipListener) MigrationListener(com.hazelcast.core.MigrationListener) InternalMigrationListener(com.hazelcast.internal.partition.impl.InternalMigrationListener)

Aggregations

MigrationListener (com.hazelcast.core.MigrationListener)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 PartitionService (com.hazelcast.core.PartitionService)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2 ListenerConfig (com.hazelcast.config.ListenerConfig)1 ClientListener (com.hazelcast.core.ClientListener)1 DistributedObjectListener (com.hazelcast.core.DistributedObjectListener)1 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)1 LifecycleListener (com.hazelcast.core.LifecycleListener)1 MembershipListener (com.hazelcast.core.MembershipListener)1 MigrationEvent (com.hazelcast.core.MigrationEvent)1 InternalMigrationListener (com.hazelcast.internal.partition.impl.InternalMigrationListener)1 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)1 PartitionLostListener (com.hazelcast.partition.PartitionLostListener)1 ProxyServiceImpl (com.hazelcast.spi.impl.proxyservice.impl.ProxyServiceImpl)1