use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.
the class RaftNodeImpl method replicateMembershipChange.
@Override
public InternalCompletableFuture replicateMembershipChange(RaftEndpoint member, MembershipChangeMode mode) {
InternalCompletableFuture resultFuture = raftIntegration.newCompletableFuture();
execute(new MembershipChangeTask(this, resultFuture, member, mode));
return resultFuture;
}
use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.
the class RaftNodeImpl method transferLeadership.
@Override
public InternalCompletableFuture transferLeadership(RaftEndpoint endpoint) {
InternalCompletableFuture resultFuture = raftIntegration.newCompletableFuture();
raftIntegration.execute(new InitLeadershipTransferTask(this, endpoint, resultFuture));
return resultFuture;
}
use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.
the class AbstractProxySessionManager method shutdown.
/**
* Invokes a shutdown call on server to close all existing sessions.
*/
public Map<RaftGroupId, InternalCompletableFuture<Object>> shutdown() {
lock.writeLock().lock();
try {
Map<RaftGroupId, InternalCompletableFuture<Object>> futures = new HashMap<>();
for (Entry<RaftGroupId, SessionState> e : sessions.entrySet()) {
RaftGroupId groupId = e.getKey();
long sessionId = e.getValue().id;
InternalCompletableFuture<Object> f = closeSession(groupId, sessionId);
futures.put(groupId, f);
}
sessions.clear();
running = false;
return futures;
} finally {
lock.writeLock().unlock();
}
}
use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.
the class ProxySessionManagerService method onShutdown.
@Override
public boolean onShutdown(long timeout, TimeUnit unit) {
ILogger logger = nodeEngine.getLogger(getClass());
Map<RaftGroupId, InternalCompletableFuture<Object>> futures = shutdown();
long remainingTimeNanos = unit.toNanos(timeout);
boolean successful = true;
while (remainingTimeNanos > 0 && futures.size() > 0) {
Iterator<Entry<RaftGroupId, InternalCompletableFuture<Object>>> it = futures.entrySet().iterator();
while (it.hasNext()) {
Entry<RaftGroupId, InternalCompletableFuture<Object>> entry = it.next();
RaftGroupId groupId = entry.getKey();
InternalCompletableFuture<Object> f = entry.getValue();
if (f.isDone()) {
it.remove();
try {
f.get();
logger.fine("Session closed for " + groupId);
} catch (Exception e) {
logger.warning("Close session failed for " + groupId, e);
successful = false;
}
}
}
try {
Thread.sleep(SHUTDOWN_TASK_PERIOD_IN_MILLIS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return false;
}
remainingTimeNanos -= MILLISECONDS.toNanos(SHUTDOWN_TASK_PERIOD_IN_MILLIS);
}
return successful && futures.isEmpty();
}
use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.
the class ExecutorServiceProxy method submitToPartitionOwner.
@Nonnull
private <T> Future<T> submitToPartitionOwner(@Nonnull Callable<T> task, int partitionId) {
checkNotNull(task, "task must not be null");
checkNotShutdown();
NodeEngine nodeEngine = getNodeEngine();
Data taskData = nodeEngine.toData(task);
UUID uuid = newUnsecureUUID();
Operation op = new CallableTaskOperation(name, uuid, taskData).setPartitionId(partitionId);
InternalCompletableFuture future = invokeOnPartition(op);
return new CancellableDelegatingFuture<>(future, nodeEngine, uuid, partitionId);
}
Aggregations