Search in sources :

Example 11 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class CacheCreateConfigMessageTask method processMessage.

@Override
protected void processMessage() {
    // parameters.cacheConfig is not nullable by protocol definition, hence no need for null check
    CacheConfig cacheConfig = parameters.cacheConfig.asCacheConfig(serializationService);
    CacheService cacheService = getService(CacheService.SERVICE_NAME);
    SplitBrainMergePolicyProvider mergePolicyProvider = nodeEngine.getSplitBrainMergePolicyProvider();
    checkCacheConfig(cacheConfig, mergePolicyProvider);
    InternalCompletableFuture future = cacheService.createCacheConfigOnAllMembersAsync(PreJoinCacheConfig.of(cacheConfig));
    future.whenCompleteAsync(this);
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) CacheConfig(com.hazelcast.config.CacheConfig) ConfigValidator.checkCacheConfig(com.hazelcast.internal.config.ConfigValidator.checkCacheConfig) PreJoinCacheConfig(com.hazelcast.cache.impl.PreJoinCacheConfig) SplitBrainMergePolicyProvider(com.hazelcast.spi.merge.SplitBrainMergePolicyProvider) CacheService(com.hazelcast.cache.impl.CacheService) ICacheService(com.hazelcast.cache.impl.ICacheService)

Example 12 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class TransferLeadershipOp method call.

@Override
public CallStatus call() throws Exception {
    RaftService service = getService();
    InternalCompletableFuture future = service.transferLeadership(groupId, (CPMemberInfo) destination);
    future.whenCompleteAsync(this);
    return CallStatus.VOID;
}
Also used : RaftService(com.hazelcast.cp.internal.RaftService) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture)

Example 13 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class RaftNodeImpl method query.

@Override
public InternalCompletableFuture query(Object operation, QueryPolicy queryPolicy) {
    InternalCompletableFuture resultFuture = raftIntegration.newCompletableFuture();
    raftIntegration.execute(new QueryTask(this, operation, queryPolicy, resultFuture));
    return resultFuture;
}
Also used : QueryTask(com.hazelcast.cp.internal.raft.impl.task.QueryTask) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture)

Example 14 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class RaftNodeImpl method invalidateFuturesFrom.

/**
 * Invalidates futures registered with indexes {@code >= entryIndex}. Note that {@code entryIndex} is inclusive.
 * {@link LeaderDemotedException} is set a result to futures.
 */
public void invalidateFuturesFrom(long entryIndex) {
    int count = 0;
    Iterator<Entry<Long, InternalCompletableFuture>> iterator = futures.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<Long, InternalCompletableFuture> entry = iterator.next();
        long index = entry.getKey();
        if (index >= entryIndex) {
            entry.getValue().completeExceptionally(new LeaderDemotedException(state.localEndpoint(), state.leader()));
            iterator.remove();
            count++;
        }
    }
    if (count > 0) {
        logger.warning("Invalidated " + count + " futures from log index: " + entryIndex);
    }
}
Also used : LeaderDemotedException(com.hazelcast.cp.exception.LeaderDemotedException) Entry(java.util.Map.Entry) LogEntry(com.hazelcast.cp.internal.raft.impl.log.LogEntry) SnapshotEntry(com.hazelcast.cp.internal.raft.impl.log.SnapshotEntry) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture)

Example 15 with InternalCompletableFuture

use of com.hazelcast.spi.impl.InternalCompletableFuture in project hazelcast by hazelcast.

the class RaftNodeImpl method replicate.

@Override
public InternalCompletableFuture replicate(Object operation) {
    InternalCompletableFuture resultFuture = raftIntegration.newCompletableFuture();
    execute(new ReplicateTask(this, operation, resultFuture));
    return resultFuture;
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ReplicateTask(com.hazelcast.cp.internal.raft.impl.task.ReplicateTask)

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