Search in sources :

Example 1 with LifecycleState

use of com.hazelcast.core.LifecycleEvent.LifecycleState in project hazelcast by hazelcast.

the class ClusterMergeTask method run.

public void run() {
    LifecycleServiceImpl lifecycleService = node.hazelcastInstance.getLifecycleService();
    lifecycleService.fireLifecycleEvent(MERGING);
    LifecycleState finalLifecycleState = MERGE_FAILED;
    try {
        resetState();
        Collection<Runnable> tasks = collectMergeTasks();
        resetServices();
        rejoin();
        finalLifecycleState = getFinalLifecycleState();
        if (finalLifecycleState == MERGED) {
            executeMergeTasks(tasks);
        }
    } finally {
        lifecycleService.fireLifecycleEvent(finalLifecycleState);
    }
}
Also used : LifecycleState(com.hazelcast.core.LifecycleEvent.LifecycleState) LifecycleServiceImpl(com.hazelcast.instance.LifecycleServiceImpl)

Example 2 with LifecycleState

use of com.hazelcast.core.LifecycleEvent.LifecycleState in project hazelcast by hazelcast.

the class ClientRegressionWithMockNetworkTest method testClientConnectionEvents.

@Test
public void testClientConnectionEvents() throws InterruptedException {
    final LinkedList<LifecycleState> list = new LinkedList<LifecycleState>();
    list.offer(LifecycleState.STARTING);
    list.offer(LifecycleState.STARTED);
    list.offer(LifecycleState.CLIENT_CONNECTED);
    list.offer(LifecycleState.CLIENT_DISCONNECTED);
    list.offer(LifecycleState.CLIENT_CONNECTED);
    list.offer(LifecycleState.CLIENT_DISCONNECTED);
    list.offer(LifecycleState.SHUTTING_DOWN);
    list.offer(LifecycleState.SHUTDOWN);
    hazelcastFactory.newHazelcastInstance();
    final CountDownLatch latch = new CountDownLatch(list.size());
    final CountDownLatch connectedLatch = new CountDownLatch(2);
    final CountDownLatch disconnectedLatch = new CountDownLatch(2);
    LifecycleListener listener = new LifecycleListener() {

        public void stateChanged(LifecycleEvent event) {
            Logger.getLogger(getClass()).info("stateChanged: " + event);
            final LifecycleState state = list.poll();
            LifecycleState eventState = event.getState();
            if (state != null && state.equals(eventState)) {
                latch.countDown();
            }
            if (LifecycleState.CLIENT_CONNECTED.equals(eventState)) {
                connectedLatch.countDown();
            }
            if (LifecycleState.CLIENT_DISCONNECTED.equals(eventState)) {
                disconnectedLatch.countDown();
            }
        }
    };
    final ListenerConfig listenerConfig = new ListenerConfig(listener);
    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.addListenerConfig(listenerConfig);
    clientConfig.getNetworkConfig().setConnectionAttemptLimit(100);
    HazelcastInstance hazelcastClient = hazelcastFactory.newHazelcastClient(clientConfig);
    hazelcastFactory.shutdownAllMembers();
    hazelcastFactory.newHazelcastInstance();
    assertOpenEventually("LifecycleState failed. Expected two CLIENT_CONNECTED events!", connectedLatch);
    hazelcastFactory.shutdownAllMembers();
    //wait for disconnect then call client.shutdown(). Otherwise shutdown could prevent firing DISCONNECTED event
    assertOpenEventually("LifecycleState failed. Expected two CLIENT_DISCONNECTED events!", disconnectedLatch);
    hazelcastClient.shutdown();
    assertOpenEventually("LifecycleState failed", latch);
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) LifecycleEvent(com.hazelcast.core.LifecycleEvent) LifecycleState(com.hazelcast.core.LifecycleEvent.LifecycleState) LifecycleListener(com.hazelcast.core.LifecycleListener) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConfig(com.hazelcast.client.config.ClientConfig) LinkedList(java.util.LinkedList) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

LifecycleState (com.hazelcast.core.LifecycleEvent.LifecycleState)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 ListenerConfig (com.hazelcast.config.ListenerConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 LifecycleEvent (com.hazelcast.core.LifecycleEvent)1 LifecycleListener (com.hazelcast.core.LifecycleListener)1 LifecycleServiceImpl (com.hazelcast.instance.LifecycleServiceImpl)1 NightlyTest (com.hazelcast.test.annotation.NightlyTest)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 LinkedList (java.util.LinkedList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1