Search in sources :

Example 61 with InternalCompletableFuture

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;
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) MembershipChangeTask(com.hazelcast.cp.internal.raft.impl.task.MembershipChangeTask)

Example 62 with InternalCompletableFuture

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;
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) InitLeadershipTransferTask(com.hazelcast.cp.internal.raft.impl.task.InitLeadershipTransferTask)

Example 63 with InternalCompletableFuture

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();
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId)

Example 64 with InternalCompletableFuture

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();
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) RaftGroupId(com.hazelcast.cp.internal.RaftGroupId) Entry(java.util.Map.Entry) ILogger(com.hazelcast.logging.ILogger)

Example 65 with InternalCompletableFuture

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);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Data(com.hazelcast.internal.serialization.Data) ShutdownOperation(com.hazelcast.executor.impl.operations.ShutdownOperation) CallableTaskOperation(com.hazelcast.executor.impl.operations.CallableTaskOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation) UuidUtil.newUnsecureUUID(com.hazelcast.internal.util.UuidUtil.newUnsecureUUID) UUID(java.util.UUID) CallableTaskOperation(com.hazelcast.executor.impl.operations.CallableTaskOperation) MemberCallableTaskOperation(com.hazelcast.executor.impl.operations.MemberCallableTaskOperation) Nonnull(javax.annotation.Nonnull)

Aggregations

InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)90 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)47 QuickTest (com.hazelcast.test.annotation.QuickTest)47 Test (org.junit.Test)47 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)19 HazelcastInstance (com.hazelcast.core.HazelcastInstance)17 Accessors.getOperationService (com.hazelcast.test.Accessors.getOperationService)15 Data (com.hazelcast.internal.serialization.Data)10 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 Operation (com.hazelcast.spi.impl.operationservice.Operation)9 UUID (java.util.UUID)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 Member (com.hazelcast.cluster.Member)7 ApplyRaftRunnable (com.hazelcast.cp.internal.raft.impl.dataservice.ApplyRaftRunnable)7 Future (java.util.concurrent.Future)7 Address (com.hazelcast.cluster.Address)6 List (java.util.List)6 BiConsumer (java.util.function.BiConsumer)6 Nonnull (javax.annotation.Nonnull)6