Search in sources :

Example 1 with HazelcastInstanceImpl

use of com.hazelcast.instance.HazelcastInstanceImpl in project hazelcast by hazelcast.

the class ClusterServiceImpl method shutdownNodes.

private void shutdownNodes() {
    final Operation op = new ShutdownNodeOperation();
    logger.info("Sending shutting down operations to all members...");
    Collection<Member> members = getMembers(NON_LOCAL_MEMBER_SELECTOR);
    final long timeout = node.getProperties().getNanos(GroupProperty.CLUSTER_SHUTDOWN_TIMEOUT_SECONDS);
    final long startTime = System.nanoTime();
    while ((System.nanoTime() - startTime) < timeout && !members.isEmpty()) {
        for (Member member : members) {
            nodeEngine.getOperationService().send(op, member.getAddress());
        }
        try {
            Thread.sleep(CLUSTER_SHUTDOWN_SLEEP_DURATION_IN_MILLIS);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            logger.warning("Shutdown sleep interrupted. ", e);
            break;
        }
        members = getMembers(NON_LOCAL_MEMBER_SELECTOR);
    }
    logger.info("Number of other nodes remaining: " + getSize(NON_LOCAL_MEMBER_SELECTOR) + ". Shutting down itself.");
    final HazelcastInstanceImpl hazelcastInstance = node.hazelcastInstance;
    hazelcastInstance.getLifecycleService().shutdown();
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.HazelcastInstanceImpl) ShutdownNodeOperation(com.hazelcast.internal.cluster.impl.operations.ShutdownNodeOperation) MemberInfoUpdateOperation(com.hazelcast.internal.cluster.impl.operations.MemberInfoUpdateOperation) Operation(com.hazelcast.spi.Operation) TriggerMemberListPublishOperation(com.hazelcast.internal.cluster.impl.operations.TriggerMemberListPublishOperation) MemberRemoveOperation(com.hazelcast.internal.cluster.impl.operations.MemberRemoveOperation) ShutdownNodeOperation(com.hazelcast.internal.cluster.impl.operations.ShutdownNodeOperation) Member(com.hazelcast.core.Member)

Example 2 with HazelcastInstanceImpl

use of com.hazelcast.instance.HazelcastInstanceImpl in project hazelcast by hazelcast.

the class AbstractCallableTaskOperation method getManagedContext.

private ManagedContext getManagedContext() {
    HazelcastInstanceImpl hazelcastInstance = (HazelcastInstanceImpl) getNodeEngine().getHazelcastInstance();
    SerializationService serializationService = hazelcastInstance.getSerializationService();
    return serializationService.getManagedContext();
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.HazelcastInstanceImpl) SerializationService(com.hazelcast.spi.serialization.SerializationService)

Example 3 with HazelcastInstanceImpl

use of com.hazelcast.instance.HazelcastInstanceImpl in project hazelcast by hazelcast.

the class ForceStartNodeRequest method writeResponse.

@Override
public void writeResponse(ManagementCenterService mcs, JsonObject out) throws Exception {
    String resultString;
    HazelcastInstanceImpl instance = mcs.getHazelcastInstance();
    try {
        resultString = instance.node.getNodeExtension().getInternalHotRestartService().triggerForceStart() ? SUCCESS_RESULT : FAILED_RESULT;
    } catch (Exception e) {
        ILogger logger = instance.node.getLogger(getClass());
        logger.warning("Problem on force start: ", e);
        resultString = e.getMessage();
    }
    JsonObject result = new JsonObject().add("result", resultString);
    out.add("result", result);
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.HazelcastInstanceImpl) JsonObject(com.eclipsesource.json.JsonObject) ILogger(com.hazelcast.logging.ILogger) JsonUtil.getString(com.hazelcast.util.JsonUtil.getString) IOException(java.io.IOException)

Example 4 with HazelcastInstanceImpl

use of com.hazelcast.instance.HazelcastInstanceImpl in project hazelcast by hazelcast.

the class CacheThroughHazelcastInstanceTest method getCache_whenOtherHazelcastExceptionIsThrown_thenFail.

@Test
public void getCache_whenOtherHazelcastExceptionIsThrown_thenFail() {
    // when one attempts to getCache but a HazelcastException other than ServiceNotFoundException is thrown
    HazelcastInstanceImpl hzInstanceImpl = mock(HazelcastInstanceImpl.class);
    when(hzInstanceImpl.getDistributedObject(anyString(), anyString())).thenThrow(new HazelcastException("mock hz exception"));
    // then the thrown HazelcastException is rethrown by getCache
    ICacheManager hzCacheManager = new HazelcastInstanceCacheManager(hzInstanceImpl);
    thrown.expect(HazelcastException.class);
    hzCacheManager.getCache("any-cache");
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.HazelcastInstanceImpl) HazelcastInstanceCacheManager(com.hazelcast.instance.HazelcastInstanceCacheManager) HazelcastException(com.hazelcast.core.HazelcastException) ICacheManager(com.hazelcast.core.ICacheManager) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with HazelcastInstanceImpl

use of com.hazelcast.instance.HazelcastInstanceImpl in project hazelcast by hazelcast.

the class MapRemoveFailingBackupTest method testMapRemoveFailingBackupShouldNotLeadToStaleDataWhenReadBackupIsEnabled.

@Test
public void testMapRemoveFailingBackupShouldNotLeadToStaleDataWhenReadBackupIsEnabled() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final String mapName = randomMapName();
    final String key = "2";
    final String value = "value2";
    Config config = getConfig();
    config.getSerializationConfig().addDataSerializableFactory(100, new Factory());
    config.setProperty(GroupProperty.PARTITION_BACKUP_SYNC_INTERVAL.getName(), "5");
    config.getMapConfig(mapName).setReadBackupData(true);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    HazelcastInstance hz2 = factory.newHazelcastInstance(config);
    final HazelcastInstanceImpl hz1Impl = TestUtil.getHazelcastInstanceImpl(hz1);
    final IMap<Object, Object> map1 = hz1.getMap(mapName);
    final IMap<Object, Object> map2 = hz2.getMap(mapName);
    MapProxyImpl<Object, Object> mock1 = (MapProxyImpl<Object, Object>) spy(map1);
    when(mock1.remove(anyString())).then(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            NodeEngineImpl nodeEngine = hz1Impl.node.nodeEngine;
            Object object = invocation.getArguments()[0];
            final Data key = nodeEngine.toData(object);
            RemoveOperation operation = new RemoveOperation(mapName, key);
            int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
            operation.setThreadId(ThreadUtil.getThreadId());
            OperationService operationService = nodeEngine.getOperationService();
            InternalCompletableFuture<Data> f = operationService.createInvocationBuilder(SERVICE_NAME, operation, partitionId).setResultDeserialized(false).invoke();
            Data result = f.get();
            return nodeEngine.toObject(result);
        }
    });
    mock1.put(key, value);
    mock1.remove(key);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertNull(map1.get(key));
            assertNull(map2.get(key));
        }
    }, 30);
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.HazelcastInstanceImpl) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Config(com.hazelcast.config.Config) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) DataSerializableFactory(com.hazelcast.nio.serialization.DataSerializableFactory) BaseRemoveOperation(com.hazelcast.map.impl.operation.BaseRemoveOperation) Data(com.hazelcast.nio.serialization.Data) Matchers.anyString(org.mockito.Matchers.anyString) HazelcastInstance(com.hazelcast.core.HazelcastInstance) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) AssertTask(com.hazelcast.test.AssertTask) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

HazelcastInstanceImpl (com.hazelcast.instance.HazelcastInstanceImpl)9 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)5 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 Field (java.lang.reflect.Field)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 HazelcastInstanceProxy (com.hazelcast.instance.HazelcastInstanceProxy)2 Address (com.hazelcast.nio.Address)2 Data (com.hazelcast.nio.serialization.Data)2 Operation (com.hazelcast.spi.Operation)2 OperationService (com.hazelcast.spi.OperationService)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 SerializationService (com.hazelcast.spi.serialization.SerializationService)2 JsonObject (com.eclipsesource.json.JsonObject)1 CachePartitionEventData (com.hazelcast.cache.impl.CachePartitionEventData)1 CachePartitionSegment (com.hazelcast.cache.impl.CachePartitionSegment)1 CacheService (com.hazelcast.cache.impl.CacheService)1 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)1 CacheReplicationOperation (com.hazelcast.cache.impl.operation.CacheReplicationOperation)1