Search in sources :

Example 1 with LifecycleServiceImpl

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);
    }
}
Also used : LifecycleState(com.hazelcast.core.LifecycleEvent.LifecycleState) LifecycleServiceImpl(com.hazelcast.instance.LifecycleServiceImpl)

Example 2 with LifecycleServiceImpl

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));
}
Also used : LifecycleServiceImpl(com.hazelcast.instance.LifecycleServiceImpl)

Example 3 with LifecycleServiceImpl

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));
            }
        });
    }
}
Also used : HashMap(java.util.HashMap) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) Data(com.hazelcast.nio.serialization.Data) LifecycleServiceImpl(com.hazelcast.instance.LifecycleServiceImpl) CacheLoaderException(javax.cache.integration.CacheLoaderException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with LifecycleServiceImpl

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();
            }
        }
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Node(com.hazelcast.instance.Node) LifecycleEvent(com.hazelcast.core.LifecycleEvent) LifecycleListener(com.hazelcast.core.LifecycleListener) LifecycleServiceImpl(com.hazelcast.instance.LifecycleServiceImpl)

Aggregations

LifecycleServiceImpl (com.hazelcast.instance.LifecycleServiceImpl)4 ClientConfig (com.hazelcast.client.config.ClientConfig)1 CacheConfig (com.hazelcast.config.CacheConfig)1 Config (com.hazelcast.config.Config)1 NearCacheConfig (com.hazelcast.config.NearCacheConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 LifecycleEvent (com.hazelcast.core.LifecycleEvent)1 LifecycleState (com.hazelcast.core.LifecycleEvent.LifecycleState)1 LifecycleListener (com.hazelcast.core.LifecycleListener)1 Node (com.hazelcast.instance.Node)1 Data (com.hazelcast.nio.serialization.Data)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 AssertTask (com.hazelcast.test.AssertTask)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CacheLoaderException (javax.cache.integration.CacheLoaderException)1