Search in sources :

Example 1 with LifecycleService

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

the class BatchInvalidator method shutdown.

@Override
public void shutdown() {
    ExecutionService executionService = nodeEngine.getExecutionService();
    executionService.shutdownExecutor(invalidationExecutorName);
    HazelcastInstance node = nodeEngine.getHazelcastInstance();
    LifecycleService lifecycleService = node.getLifecycleService();
    lifecycleService.removeLifecycleListener(nodeShutdownListenerId);
    invalidationQueues.clear();
    super.shutdown();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) LifecycleService(com.hazelcast.core.LifecycleService) ExecutionService(com.hazelcast.spi.ExecutionService)

Example 2 with LifecycleService

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

the class BatchInvalidator method registerNodeShutdownListener.

/**
     * Sends remaining invalidation events in this invalidator's queues to the recipients.
     */
private String registerNodeShutdownListener() {
    HazelcastInstance node = nodeEngine.getHazelcastInstance();
    LifecycleService lifecycleService = node.getLifecycleService();
    return lifecycleService.addLifecycleListener(new LifecycleListener() {

        @Override
        public void stateChanged(LifecycleEvent event) {
            if (event.getState() == SHUTTING_DOWN) {
                Set<Map.Entry<String, InvalidationQueue>> entries = invalidationQueues.entrySet();
                for (Map.Entry<String, InvalidationQueue> entry : entries) {
                    pollAndSendInvalidations(entry.getKey(), entry.getValue());
                }
            }
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Set(java.util.Set) LifecycleEvent(com.hazelcast.core.LifecycleEvent) LifecycleService(com.hazelcast.core.LifecycleService) LifecycleListener(com.hazelcast.core.LifecycleListener) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 3 with LifecycleService

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

the class HazelcastOSGiInstanceTest method getLifecycleServiceCalledSuccessfullyOverOSGiInstance.

@Test
public void getLifecycleServiceCalledSuccessfullyOverOSGiInstance() {
    LifecycleService mockLifecycleService = mock(LifecycleService.class);
    HazelcastInstance mockHazelcastInstance = mock(HazelcastInstance.class);
    HazelcastOSGiInstance hazelcastOSGiInstance = HazelcastOSGiTestUtil.createHazelcastOSGiInstance(mockHazelcastInstance);
    when(mockHazelcastInstance.getLifecycleService()).thenReturn(mockLifecycleService);
    assertEquals(mockLifecycleService, hazelcastOSGiInstance.getLifecycleService());
    verify(mockHazelcastInstance).getLifecycleService();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) LifecycleService(com.hazelcast.core.LifecycleService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with LifecycleService

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

the class TestNodeRegistry method shutdown.

private void shutdown(boolean terminate) {
    Iterator<Node> iterator = nodes.values().iterator();
    while (iterator.hasNext()) {
        Node node = iterator.next();
        HazelcastInstance hz = node.hazelcastInstance;
        LifecycleService lifecycleService = hz.getLifecycleService();
        if (terminate) {
            lifecycleService.terminate();
        } else {
            lifecycleService.shutdown();
        }
        iterator.remove();
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.Node) LifecycleService(com.hazelcast.core.LifecycleService)

Example 5 with LifecycleService

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

the class ClientHeartbeatTest method testClientEndpointsDelaySeconds_whenHeartbeatResumed.

@Test
public void testClientEndpointsDelaySeconds_whenHeartbeatResumed() throws Exception {
    int delaySeconds = 2;
    Config config = new Config();
    config.setProperty(GroupProperty.CLIENT_ENDPOINT_REMOVE_DELAY_SECONDS.getName(), String.valueOf(delaySeconds));
    HazelcastInstance hazelcastInstance = hazelcastFactory.newHazelcastInstance(config);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setProperty(ClientProperty.HEARTBEAT_TIMEOUT.getName(), "4000");
    clientConfig.setProperty(ClientProperty.HEARTBEAT_INTERVAL.getName(), "1000");
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    final CountDownLatch disconnectedLatch = new CountDownLatch(1);
    LifecycleService lifecycleService = client.getLifecycleService();
    lifecycleService.addLifecycleListener(new LifecycleListener() {

        @Override
        public void stateChanged(LifecycleEvent event) {
            if (LifecycleEvent.LifecycleState.CLIENT_DISCONNECTED == event.getState()) {
                disconnectedLatch.countDown();
            }
        }
    });
    blockMessagesFromInstance(hazelcastInstance, client);
    //Wait for client to disconnect because of hearBeat problem.
    assertOpenEventually(disconnectedLatch);
    final CountDownLatch connectedLatch = new CountDownLatch(1);
    final AtomicLong stateChangeCount = new AtomicLong();
    lifecycleService.addLifecycleListener(new LifecycleListener() {

        @Override
        public void stateChanged(LifecycleEvent event) {
            stateChangeCount.incrementAndGet();
            Logger.getLogger(this.getClass()).info("state event : " + event);
            if (LifecycleEvent.LifecycleState.CLIENT_CONNECTED == event.getState()) {
                connectedLatch.countDown();
            }
        }
    });
    unblockMessagesFromInstance(hazelcastInstance, client);
    //Wait for client to connect back after heartbeat issue is resolved
    assertOpenEventually(connectedLatch);
    //After client connected, there should not be further change in client state
    //We are specifically testing for scheduled ClientDisconnectionOperation not to take action when run
    assertTrueAllTheTime(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(1, stateChangeCount.get());
        }
    }, delaySeconds * 2);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) LifecycleEvent(com.hazelcast.core.LifecycleEvent) AssertTask(com.hazelcast.test.AssertTask) LifecycleService(com.hazelcast.core.LifecycleService) LifecycleListener(com.hazelcast.core.LifecycleListener) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) ExpectedException(org.junit.rules.ExpectedException) ExecutionException(java.util.concurrent.ExecutionException) TargetDisconnectedException(com.hazelcast.spi.exception.TargetDisconnectedException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 LifecycleService (com.hazelcast.core.LifecycleService)5 LifecycleEvent (com.hazelcast.core.LifecycleEvent)2 LifecycleListener (com.hazelcast.core.LifecycleListener)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 Config (com.hazelcast.config.Config)1 Node (com.hazelcast.instance.Node)1 ExecutionService (com.hazelcast.spi.ExecutionService)1 TargetDisconnectedException (com.hazelcast.spi.exception.TargetDisconnectedException)1 AssertTask (com.hazelcast.test.AssertTask)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1