use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.
the class ClientExecutorServiceProxy method submitToTargetInternal.
private <T> void submitToTargetInternal(@Nonnull Data task, Member member, @Nullable ExecutionCallback<T> callback) {
checkNotNull(task, "task should not be null");
UUID uuid = getUUID();
ClientMessage request = ExecutorServiceSubmitToMemberCodec.encodeRequest(name, uuid, task, member.getUuid());
ClientInvocationFuture f = invokeOnTarget(request, member);
InternalCompletableFuture<T> delegatingFuture = (InternalCompletableFuture<T>) delegatingFuture(f, uuid, member, (T) null);
if (callback != null) {
delegatingFuture.whenCompleteAsync(new ExecutionCallbackAdapter<>(callback)).whenCompleteAsync((v, t) -> {
if (t instanceof RejectedExecutionException) {
callback.onFailure(t);
}
}, ConcurrencyUtil.getDefaultAsyncExecutor());
}
}
use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.
the class RaftService method removeCPMember.
public InternalCompletableFuture<Void> removeCPMember(UUID cpMemberUuid) {
ClusterService clusterService = nodeEngine.getClusterService();
InternalCompletableFuture<Void> future = newCompletableFuture();
BiConsumer<Void, Throwable> removeMemberCallback = (response, t) -> {
if (t == null) {
future.complete(null);
} else {
if (t instanceof CannotRemoveCPMemberException) {
t = new IllegalStateException(t.getMessage());
}
complete(future, t);
}
};
invocationManager.<Collection<CPMember>>invoke(getMetadataGroupId(), new GetActiveCPMembersOp()).whenCompleteAsync((cpMembers, t) -> {
if (t == null) {
CPMemberInfo cpMemberToRemove = null;
for (CPMember cpMember : cpMembers) {
if (cpMember.getUuid().equals(cpMemberUuid)) {
cpMemberToRemove = (CPMemberInfo) cpMember;
break;
}
}
if (cpMemberToRemove == null) {
complete(future, new IllegalArgumentException("No CPMember found with uuid: " + cpMemberUuid));
return;
} else {
Member member = clusterService.getMember(cpMemberToRemove.getAddress());
if (member != null) {
logger.warning("Only unreachable/crashed CP members should be removed. " + member + " is alive but " + cpMemberToRemove + " with the same address is being removed.");
}
}
invokeTriggerRemoveMember(cpMemberToRemove).whenCompleteAsync(removeMemberCallback);
} else {
complete(future, t);
}
});
return future;
}
use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.
the class RaftInvocationManager method completeExceptionallyIfCPSubsystemNotAvailable.
private <V> InternalCompletableFuture<V> completeExceptionallyIfCPSubsystemNotAvailable() {
if (!cpSubsystemEnabled) {
InternalCompletableFuture<V> future = new InternalCompletableFuture<>();
future.completeExceptionally(new HazelcastException("CP Subsystem is not enabled!"));
return future;
}
return null;
}
use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.
the class RaftService method resetLocalRaftState.
private void resetLocalRaftState() {
// node.forceSetTerminatedStatus() will trigger RaftNodeLifecycleAwareService.onRaftGroupDestroyed()
// which will attempt to acquire the read lock on nodeLock. In order to prevent it, we first
// add group ids into destroyedGroupIds to short-cut RaftNodeLifecycleAwareService.onRaftGroupDestroyed()
List<InternalCompletableFuture> futures = new ArrayList<>(nodes.size());
destroyedGroupIds.addAll(nodes.keySet());
for (RaftNode node : nodes.values()) {
InternalCompletableFuture f = node.forceSetTerminatedStatus();
futures.add(f);
}
for (InternalCompletableFuture future : futures) {
try {
future.get();
} catch (Exception e) {
logger.warning(e);
}
}
nodes.clear();
for (ServiceInfo serviceInfo : nodeEngine.getServiceInfos(RaftRemoteService.class)) {
if (serviceInfo.getService() instanceof RaftManagedService) {
((RaftManagedService) serviceInfo.getService()).onCPSubsystemRestart();
}
}
nodeMetrics.clear();
missingMembers.clear();
invocationManager.reset();
}
use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.
the class InvocationFuture_IsDoneTest method isDone_whenNoResponse.
@Test
public void isDone_whenNoResponse() {
DummyOperation op = new GetLostPartitionOperation();
InternalCompletableFuture future = operationService.invokeOnTarget(null, op, getAddress(local));
assertFalse(future.isDone());
}
Aggregations