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();
}
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());
}
}
}
});
}
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();
}
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();
}
}
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);
}
Aggregations