use of com.hazelcast.instance.LifecycleServiceImpl 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.instance.LifecycleServiceImpl in project hazelcast by hazelcast.
the class ClusterServiceImpl method merge.
public void merge(Address newTargetAddress) {
node.getJoiner().setTargetAddress(newTargetAddress);
LifecycleServiceImpl lifecycleService = node.hazelcastInstance.getLifecycleService();
lifecycleService.runUnderLifecycleLock(new ClusterMergeTask(node));
}
use of com.hazelcast.instance.LifecycleServiceImpl in project hazelcast by hazelcast.
the class ClientNearCacheTestSupport method putToCacheAndGetInvalidationEventWhenNodeShutdown.
protected void putToCacheAndGetInvalidationEventWhenNodeShutdown(InMemoryFormat inMemoryFormat) {
Config config = createConfig();
config.setProperty(GroupProperty.CACHE_INVALIDATION_MESSAGE_BATCH_SIZE.getName(), String.valueOf(Integer.MAX_VALUE));
config.setProperty(CACHE_INVALIDATION_MESSAGE_BATCH_FREQUENCY_SECONDS.getName(), String.valueOf(Integer.MAX_VALUE));
HazelcastInstance instanceToShutdown = hazelcastFactory.newHazelcastInstance(config);
warmUpPartitions(serverInstance, instanceToShutdown);
waitAllForSafeState(serverInstance, instanceToShutdown);
NearCacheConfig nearCacheConfig = createNearCacheConfig(inMemoryFormat);
nearCacheConfig.setInvalidateOnChange(true);
nearCacheConfig.setLocalUpdatePolicy(LocalUpdatePolicy.CACHE_ON_UPDATE);
final NearCacheTestContext nearCacheTestContext1 = createNearCacheTest(DEFAULT_CACHE_NAME, nearCacheConfig);
final NearCacheTestContext nearCacheTestContext2 = createNearCacheTest(DEFAULT_CACHE_NAME, nearCacheConfig);
Map<String, String> keyAndValues = new HashMap<String, String>();
// put cache record from client-1 to instance which is going to be shutdown
for (int i = 0; i < DEFAULT_RECORD_COUNT; i++) {
String key = generateKeyOwnedBy(instanceToShutdown);
String value = generateValueFromKey(i);
nearCacheTestContext1.cache.put(key, value);
keyAndValues.put(key, value);
}
// verify that records are exist at Near Cache of client-1 because `local-update-policy` is `CACHE`
for (Map.Entry<String, String> entry : keyAndValues.entrySet()) {
String key = entry.getKey();
String exceptedValue = entry.getValue();
String actualValue = nearCacheTestContext1.nearCache.get(nearCacheTestContext1.serializationService.toData(key));
assertEquals(exceptedValue, actualValue);
}
// to send to client to invalidate its Near Cache
for (Map.Entry<String, String> entry : keyAndValues.entrySet()) {
nearCacheTestContext2.cache.remove(entry.getKey());
}
// we don't shutdown the instance because in case of shutdown even though events are published to event queue,
// they may not be processed in the event queue due to shutdown event queue executor or may not be sent
// to client endpoint due to IO handler shutdown
// for not to making test fragile, we just simulate shutting down by sending its event through `LifeCycleService`,
// so the node should flush invalidation events before shutdown
((LifecycleServiceImpl) instanceToShutdown.getLifecycleService()).fireLifecycleEvent(LifecycleEvent.LifecycleState.SHUTTING_DOWN);
// verify that records in the Near Cache of client-1 are invalidated eventually when instance shutdown
for (Map.Entry<String, String> entry : keyAndValues.entrySet()) {
final String key = entry.getKey();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
Data keyData = nearCacheTestContext1.serializationService.toData(key);
assertNull(nearCacheTestContext1.nearCache.get(keyData));
}
});
}
}
use of com.hazelcast.instance.LifecycleServiceImpl in project hazelcast by hazelcast.
the class NodeQueryCacheContext method flushPublishersOnNodeShutdown.
/**
* This is a best effort approach; there is no guarantee that events in publishers internal buffers will be fired,
* {@link com.hazelcast.spi.EventService} can drop them.
*/
private void flushPublishersOnNodeShutdown() {
Node node = ((NodeEngineImpl) this.nodeEngine).getNode();
LifecycleServiceImpl lifecycleService = node.hazelcastInstance.getLifecycleService();
lifecycleService.addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (SHUTTING_DOWN == event.getState()) {
publisherContext.flush();
}
}
});
}
Aggregations