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