Search in sources :

Example 1 with MigrationListener

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

the class ClientMigrationListenerTest method testRemoveMigrationListener_whenExistingRegistrationId.

@Test
public void testRemoveMigrationListener_whenExistingRegistrationId() {
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    PartitionService clientPartitionService = client.getPartitionService();
    MigrationListener listener = mock(MigrationListener.class);
    UUID registrationId = clientPartitionService.addMigrationListener(listener);
    assertRegistrationsSizeEventually(instance, 1);
    boolean removed = clientPartitionService.removeMigrationListener(registrationId);
    assertRegistrationsSizeEventually(instance, 0);
    assertTrue(removed);
    HazelcastInstance hz2 = hazelcastFactory.newHazelcastInstance();
    warmUpPartitions(instance, hz2);
    verifyMigrationListenerNeverInvoked(listener);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PartitionService(com.hazelcast.partition.PartitionService) UUID(java.util.UUID) MigrationListener(com.hazelcast.partition.MigrationListener) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) PartitionMigrationListenerTest(com.hazelcast.partition.PartitionMigrationListenerTest)

Example 2 with MigrationListener

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

the class AddMigrationListenerMessageTask method processInternal.

@Override
protected CompletableFuture<UUID> processInternal() {
    IPartitionService partitionService = getService(getServiceName());
    MigrationListener listener = createMigrationListener();
    if (parameters) {
        return newCompletedFuture(partitionService.addLocalMigrationListener(listener));
    }
    return partitionService.addMigrationListenerAsync(listener);
}
Also used : IPartitionService(com.hazelcast.internal.partition.IPartitionService) MigrationListener(com.hazelcast.partition.MigrationListener)

Example 3 with MigrationListener

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

the class ClientMigrationListenerTest method testAddMigrationListener_whenListenerRegisteredTwice.

@Test
public void testAddMigrationListener_whenListenerRegisteredTwice() {
    hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    PartitionService partitionService = client.getPartitionService();
    MigrationListener listener = mock(MigrationListener.class);
    UUID id1 = partitionService.addMigrationListener(listener);
    UUID id2 = partitionService.addMigrationListener(listener);
    assertNotEquals(id1, id2);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PartitionService(com.hazelcast.partition.PartitionService) UUID(java.util.UUID) MigrationListener(com.hazelcast.partition.MigrationListener) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) PartitionMigrationListenerTest(com.hazelcast.partition.PartitionMigrationListenerTest)

Example 4 with MigrationListener

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

the class Node method initializeListeners.

@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity", "checkstyle:methodlength" })
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 MigrationInterceptor) {
            partitionService.setMigrationInterceptor((MigrationInterceptor) listener);
            known = true;
        }
        if (listener instanceof CPMembershipListener) {
            hazelcastInstance.cpSubsystem.addMembershipListener((CPMembershipListener) listener);
            known = true;
        }
        if (listener instanceof CPGroupAvailabilityListener) {
            hazelcastInstance.cpSubsystem.addGroupAvailabilityListener((CPGroupAvailabilityListener) 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 : 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.client.ClientListener) ListenerConfig(com.hazelcast.config.ListenerConfig) PartitionLostListener(com.hazelcast.partition.PartitionLostListener) CPMembershipListener(com.hazelcast.cp.event.CPMembershipListener) MigrationInterceptor(com.hazelcast.internal.partition.impl.MigrationInterceptor) CPMembershipListener(com.hazelcast.cp.event.CPMembershipListener) MembershipListener(com.hazelcast.cluster.MembershipListener) MigrationListener(com.hazelcast.partition.MigrationListener) CPGroupAvailabilityListener(com.hazelcast.cp.event.CPGroupAvailabilityListener)

Aggregations

MigrationListener (com.hazelcast.partition.MigrationListener)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 PartitionMigrationListenerTest (com.hazelcast.partition.PartitionMigrationListenerTest)2 PartitionService (com.hazelcast.partition.PartitionService)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 UUID (java.util.UUID)2 Test (org.junit.Test)2 ClientListener (com.hazelcast.client.ClientListener)1 MembershipListener (com.hazelcast.cluster.MembershipListener)1 ListenerConfig (com.hazelcast.config.ListenerConfig)1 DistributedObjectListener (com.hazelcast.core.DistributedObjectListener)1 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)1 LifecycleListener (com.hazelcast.core.LifecycleListener)1 CPGroupAvailabilityListener (com.hazelcast.cp.event.CPGroupAvailabilityListener)1 CPMembershipListener (com.hazelcast.cp.event.CPMembershipListener)1 IPartitionService (com.hazelcast.internal.partition.IPartitionService)1 MigrationInterceptor (com.hazelcast.internal.partition.impl.MigrationInterceptor)1 PartitionLostListener (com.hazelcast.partition.PartitionLostListener)1 ProxyServiceImpl (com.hazelcast.spi.impl.proxyservice.impl.ProxyServiceImpl)1