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