Search in sources :

Example 16 with InternalCompletableFuture

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

the class RaftNodeImpl method toFollower.

/**
 * Switches this node to follower role by clearing the known leader
 * endpoint and (pre) candidate states, and updating the term. If this Raft
 * node was leader before switching to the follower state, it may have some
 * queries waiting to be executed. Those queries are also failed with
 * {@link LeaderDemotedException}. After the state switch,
 * {@link RaftIntegration#onNodeStatusChange(RaftNodeStatus)} is called.
 *
 * @param term the new term to switch
 */
public void toFollower(int term) {
    LeaderState leaderState = state.leaderState();
    if (leaderState != null) {
        for (BiTuple<Object, InternalCompletableFuture> t : leaderState.queryState().operations()) {
            t.element2.completeExceptionally(new LeaderDemotedException(state.localEndpoint(), null));
        }
    }
    state.toFollower(term);
    printMemberState();
}
Also used : LeaderDemotedException(com.hazelcast.cp.exception.LeaderDemotedException) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) LeaderState(com.hazelcast.cp.internal.raft.impl.state.LeaderState)

Example 17 with InternalCompletableFuture

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

the class RaftNodeImpl method forceSetTerminatedStatus.

@Override
public InternalCompletableFuture forceSetTerminatedStatus() {
    InternalCompletableFuture resultFuture = raftIntegration.newCompletableFuture();
    if (isTerminatedOrSteppedDown()) {
        if (logger.isFineEnabled()) {
            logger.fine("Already stepped down or terminated, not setting `TERMINATED` status.");
        }
        resultFuture.complete(null);
        return resultFuture;
    }
    execute(() -> {
        Throwable failure = null;
        try {
            if (isTerminatedOrSteppedDown()) {
                return;
            } else if (status == INITIAL) {
                setStatus(TERMINATED);
                return;
            }
            invalidateFuturesFrom(state.commitIndex() + 1);
            LeaderState leaderState = state.leaderState();
            if (leaderState != null) {
                for (BiTuple<Object, InternalCompletableFuture> t : leaderState.queryState().operations()) {
                    t.element2.completeExceptionally(new LeaderDemotedException(state.localEndpoint(), null));
                }
            }
            state.completeLeadershipTransfer(new LeaderDemotedException(state.localEndpoint(), null));
            setStatus(TERMINATED);
        } catch (Throwable t) {
            failure = t;
            logger.severe("Failure during force-termination", t);
            if (status != TERMINATED && status != STEPPED_DOWN) {
                setStatus(TERMINATED);
            }
        } finally {
            if (failure == null) {
                resultFuture.complete(null);
            } else {
                resultFuture.completeExceptionally(failure);
            }
        }
    });
    return resultFuture;
}
Also used : LeaderDemotedException(com.hazelcast.cp.exception.LeaderDemotedException) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) LeaderState(com.hazelcast.cp.internal.raft.impl.state.LeaderState)

Example 18 with InternalCompletableFuture

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

the class ClientMapProxy method putAllInternal.

@SuppressWarnings("checkstyle:npathcomplexity")
private void putAllInternal(@Nonnull Map<? extends K, ? extends V> map, @Nullable InternalCompletableFuture<Void> future, boolean triggerMapLoader) {
    if (map.isEmpty()) {
        if (future != null) {
            future.complete(null);
        }
        return;
    }
    checkNotNull(map, "Null argument map is not allowed");
    ClientPartitionService partitionService = getContext().getPartitionService();
    int partitionCount = partitionService.getPartitionCount();
    Map<Integer, List<Map.Entry<Data, Data>>> entryMap = new HashMap<>(partitionCount);
    for (Entry<? extends K, ? extends V> entry : map.entrySet()) {
        checkNotNull(entry.getKey(), NULL_KEY_IS_NOT_ALLOWED);
        checkNotNull(entry.getValue(), NULL_VALUE_IS_NOT_ALLOWED);
        Data keyData = toData(entry.getKey());
        int partitionId = partitionService.getPartitionId(keyData);
        List<Map.Entry<Data, Data>> partition = entryMap.get(partitionId);
        if (partition == null) {
            partition = new ArrayList<>();
            entryMap.put(partitionId, partition);
        }
        partition.add(new AbstractMap.SimpleEntry<>(keyData, toData(entry.getValue())));
    }
    assert entryMap.size() > 0;
    AtomicInteger counter = new AtomicInteger(entryMap.size());
    InternalCompletableFuture<Void> resultFuture = future != null ? future : new InternalCompletableFuture<>();
    BiConsumer<ClientMessage, Throwable> callback = (response, t) -> {
        if (t != null) {
            resultFuture.completeExceptionally(t);
        }
        if (counter.decrementAndGet() == 0) {
            finalizePutAll(map, entryMap);
            if (!resultFuture.isDone()) {
                resultFuture.complete(null);
            }
        }
    };
    for (Entry<Integer, List<Map.Entry<Data, Data>>> entry : entryMap.entrySet()) {
        Integer partitionId = entry.getKey();
        // if there is only one entry, consider how we can use MapPutRequest
        // without having to get back the return value
        ClientMessage request = MapPutAllCodec.encodeRequest(name, entry.getValue(), triggerMapLoader);
        new ClientInvocation(getClient(), request, getName(), partitionId).invoke().whenCompleteAsync(callback);
    }
    // if executing in sync mode, block for the responses
    if (future == null) {
        try {
            resultFuture.get();
        } catch (Throwable e) {
            throw rethrow(e);
        }
    }
}
Also used : MapGetAllCodec(com.hazelcast.client.impl.protocol.codec.MapGetAllCodec) MapSetTtlCodec(com.hazelcast.client.impl.protocol.codec.MapSetTtlCodec) MapForceUnlockCodec(com.hazelcast.client.impl.protocol.codec.MapForceUnlockCodec) PartitionPredicate(com.hazelcast.query.PartitionPredicate) MapRemoveEntryListenerCodec(com.hazelcast.client.impl.protocol.codec.MapRemoveEntryListenerCodec) MapTryLockCodec(com.hazelcast.client.impl.protocol.codec.MapTryLockCodec) ReadResultSetImpl(com.hazelcast.ringbuffer.impl.ReadResultSetImpl) Thread.currentThread(java.lang.Thread.currentThread) ExceptionUtil.rethrow(com.hazelcast.internal.util.ExceptionUtil.rethrow) MapContainsValueCodec(com.hazelcast.client.impl.protocol.codec.MapContainsValueCodec) MapEntrySetCodec(com.hazelcast.client.impl.protocol.codec.MapEntrySetCodec) SerializationUtil(com.hazelcast.internal.serialization.impl.SerializationUtil) ListenerMessageCodec(com.hazelcast.client.impl.spi.impl.ListenerMessageCodec) Future(java.util.concurrent.Future) MapAddEntryListenerWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapAddEntryListenerWithPredicateCodec) MapLockCodec(com.hazelcast.client.impl.protocol.codec.MapLockCodec) MapPutTransientWithMaxIdleCodec(com.hazelcast.client.impl.protocol.codec.MapPutTransientWithMaxIdleCodec) SerializationService(com.hazelcast.internal.serialization.SerializationService) Map(java.util.Map) MapSizeCodec(com.hazelcast.client.impl.protocol.codec.MapSizeCodec) MapSetWithMaxIdleCodec(com.hazelcast.client.impl.protocol.codec.MapSetWithMaxIdleCodec) ClientMapQueryPartitionIterable(com.hazelcast.client.map.impl.iterator.ClientMapQueryPartitionIterable) MapValuesWithPagingPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapValuesWithPagingPredicateCodec) MapExecuteOnAllKeysCodec(com.hazelcast.client.impl.protocol.codec.MapExecuteOnAllKeysCodec) MapClearCodec(com.hazelcast.client.impl.protocol.codec.MapClearCodec) ClientPartitionService(com.hazelcast.client.impl.spi.ClientPartitionService) Set(java.util.Set) EntryView(com.hazelcast.core.EntryView) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) MapRemovePartitionLostListenerCodec(com.hazelcast.client.impl.protocol.codec.MapRemovePartitionLostListenerCodec) MapReplaceCodec(com.hazelcast.client.impl.protocol.codec.MapReplaceCodec) MapRemoveIfSameCodec(com.hazelcast.client.impl.protocol.codec.MapRemoveIfSameCodec) MapKeySetCodec(com.hazelcast.client.impl.protocol.codec.MapKeySetCodec) UnmodifiableLazyList(com.hazelcast.spi.impl.UnmodifiableLazyList) MapPutIfAbsentCodec(com.hazelcast.client.impl.protocol.codec.MapPutIfAbsentCodec) MapRemoveCodec(com.hazelcast.client.impl.protocol.codec.MapRemoveCodec) Preconditions.checkNotInstanceOf(com.hazelcast.internal.util.Preconditions.checkNotInstanceOf) Preconditions.checkPositive(com.hazelcast.internal.util.Preconditions.checkPositive) IterationType(com.hazelcast.internal.util.IterationType) MapAggregateCodec(com.hazelcast.client.impl.protocol.codec.MapAggregateCodec) ClientMapQueryPartitionIterator(com.hazelcast.client.map.impl.iterator.ClientMapQueryPartitionIterator) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) MapAddInterceptorCodec(com.hazelcast.client.impl.protocol.codec.MapAddInterceptorCodec) MapFlushCodec(com.hazelcast.client.impl.protocol.codec.MapFlushCodec) MapPutCodec(com.hazelcast.client.impl.protocol.codec.MapPutCodec) ClientMapQueryIterable(com.hazelcast.client.map.impl.iterator.ClientMapQueryIterable) ClientQueryCacheContext(com.hazelcast.client.map.impl.querycache.ClientQueryCacheContext) MapAddEntryListenerToKeyCodec(com.hazelcast.client.impl.protocol.codec.MapAddEntryListenerToKeyCodec) DataAwareEntryEvent(com.hazelcast.map.impl.DataAwareEntryEvent) IMapEvent(com.hazelcast.map.IMapEvent) UNSET(com.hazelcast.map.impl.record.Record.UNSET) MapProjectWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapProjectWithPredicateCodec) ArrayList(java.util.ArrayList) MapAddEntryListenerToKeyWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapAddEntryListenerToKeyWithPredicateCodec) MapLoadAllCodec(com.hazelcast.client.impl.protocol.codec.MapLoadAllCodec) ClientContext(com.hazelcast.client.impl.spi.ClientContext) BiConsumer(java.util.function.BiConsumer) PagingPredicateHolder(com.hazelcast.client.impl.protocol.codec.holder.PagingPredicateHolder) MapAddEntryListenerCodec(com.hazelcast.client.impl.protocol.codec.MapAddEntryListenerCodec) Nullable(javax.annotation.Nullable) LocalMapStats(com.hazelcast.map.LocalMapStats) MapEntriesWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapEntriesWithPredicateCodec) MapKeySetWithPagingPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapKeySetWithPagingPredicateCodec) ThreadUtil.getThreadId(com.hazelcast.internal.util.ThreadUtil.getThreadId) MapSubmitToKeyCodec(com.hazelcast.client.impl.protocol.codec.MapSubmitToKeyCodec) ClientMapIterator(com.hazelcast.client.map.impl.iterator.ClientMapIterator) QueryCacheEndToEndProvider(com.hazelcast.map.impl.querycache.subscriber.QueryCacheEndToEndProvider) MapGetCodec(com.hazelcast.client.impl.protocol.codec.MapGetCodec) MapDeleteCodec(com.hazelcast.client.impl.protocol.codec.MapDeleteCodec) TimeUtil.timeInMsOrTimeIfNullUnit(com.hazelcast.internal.util.TimeUtil.timeInMsOrTimeIfNullUnit) MapProjectCodec(com.hazelcast.client.impl.protocol.codec.MapProjectCodec) Preconditions.checkNotNull(com.hazelcast.internal.util.Preconditions.checkNotNull) LocalMapStatsImpl(com.hazelcast.internal.monitor.impl.LocalMapStatsImpl) ClientMapPartitionIterator(com.hazelcast.client.map.impl.iterator.ClientMapPartitionIterator) MapSetCodec(com.hazelcast.client.impl.protocol.codec.MapSetCodec) EntryProcessor(com.hazelcast.map.EntryProcessor) ReadOnly(com.hazelcast.core.ReadOnly) ClientMapIterable(com.hazelcast.client.map.impl.iterator.ClientMapIterable) ClientMapPartitionIterable(com.hazelcast.client.map.impl.iterator.ClientMapPartitionIterable) MapAddIndexCodec(com.hazelcast.client.impl.protocol.codec.MapAddIndexCodec) MapEvent(com.hazelcast.map.MapEvent) ListenerAdapter(com.hazelcast.map.impl.ListenerAdapter) MapExecuteOnKeyCodec(com.hazelcast.client.impl.protocol.codec.MapExecuteOnKeyCodec) MapLoadGivenKeysCodec(com.hazelcast.client.impl.protocol.codec.MapLoadGivenKeysCodec) Member(com.hazelcast.cluster.Member) BiFunction(java.util.function.BiFunction) ListenerAdapters.createListenerAdapter(com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter) MapPutIfAbsentWithMaxIdleCodec(com.hazelcast.client.impl.protocol.codec.MapPutIfAbsentWithMaxIdleCodec) CollectionUtil(com.hazelcast.internal.util.CollectionUtil) MapValuesWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapValuesWithPredicateCodec) EventHandler(com.hazelcast.client.impl.spi.EventHandler) MapContainsKeyCodec(com.hazelcast.client.impl.protocol.codec.MapContainsKeyCodec) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) MapAggregateWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapAggregateWithPredicateCodec) MapListener(com.hazelcast.map.listener.MapListener) MapAddPartitionLostListenerCodec(com.hazelcast.client.impl.protocol.codec.MapAddPartitionLostListenerCodec) PredicateUtils.unwrapPagingPredicate(com.hazelcast.query.impl.predicates.PredicateUtils.unwrapPagingPredicate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexUtils(com.hazelcast.query.impl.IndexUtils) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) Predicate(com.hazelcast.query.Predicate) ClientLockReferenceIdGenerator(com.hazelcast.client.impl.clientside.ClientLockReferenceIdGenerator) EntryEvent(com.hazelcast.core.EntryEvent) MapPutWithMaxIdleCodec(com.hazelcast.client.impl.protocol.codec.MapPutWithMaxIdleCodec) MapIsLockedCodec(com.hazelcast.client.impl.protocol.codec.MapIsLockedCodec) Collection(java.util.Collection) UUID(java.util.UUID) SubscriberContext(com.hazelcast.map.impl.querycache.subscriber.SubscriberContext) IndexConfig(com.hazelcast.config.IndexConfig) MapEvictCodec(com.hazelcast.client.impl.protocol.codec.MapEvictCodec) List(java.util.List) MapEntriesWithPagingPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapEntriesWithPagingPredicateCodec) MapGetEntryViewCodec(com.hazelcast.client.impl.protocol.codec.MapGetEntryViewCodec) EventJournalMapEvent(com.hazelcast.map.EventJournalMapEvent) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture) MapEventJournalSubscribeCodec(com.hazelcast.client.impl.protocol.codec.MapEventJournalSubscribeCodec) MapReplaceIfSameCodec(com.hazelcast.client.impl.protocol.codec.MapReplaceIfSameCodec) QueryCacheRequest(com.hazelcast.map.impl.querycache.subscriber.QueryCacheRequest) TimeUtil.timeInMsOrOneIfResultIsZero(com.hazelcast.internal.util.TimeUtil.timeInMsOrOneIfResultIsZero) MapPartitionLostEvent(com.hazelcast.map.MapPartitionLostEvent) Projection(com.hazelcast.projection.Projection) MapExecuteWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapExecuteWithPredicateCodec) MapEventJournalReadCodec(com.hazelcast.client.impl.protocol.codec.MapEventJournalReadCodec) QueryCacheRequest.newQueryCacheRequest(com.hazelcast.map.impl.querycache.subscriber.QueryCacheRequest.newQueryCacheRequest) MapKeySetWithPredicateCodec(com.hazelcast.client.impl.protocol.codec.MapKeySetWithPredicateCodec) MapRemoveInterceptorCodec(com.hazelcast.client.impl.protocol.codec.MapRemoveInterceptorCodec) ResponseParameters(com.hazelcast.client.impl.protocol.codec.MapEventJournalSubscribeCodec.ResponseParameters) CollectionUtil.objectToDataCollection(com.hazelcast.internal.util.CollectionUtil.objectToDataCollection) MapTryRemoveCodec(com.hazelcast.client.impl.protocol.codec.MapTryRemoveCodec) SimpleEntryView(com.hazelcast.map.impl.SimpleEntryView) HashMap(java.util.HashMap) Function(java.util.function.Function) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Aggregator(com.hazelcast.aggregation.Aggregator) MapIsEmptyCodec(com.hazelcast.client.impl.protocol.codec.MapIsEmptyCodec) PagingPredicate(com.hazelcast.query.PagingPredicate) MapValuesCodec(com.hazelcast.client.impl.protocol.codec.MapValuesCodec) MapRemoveAllCodec(com.hazelcast.client.impl.protocol.codec.MapRemoveAllCodec) MapUnlockCodec(com.hazelcast.client.impl.protocol.codec.MapUnlockCodec) Nonnull(javax.annotation.Nonnull) MapListenerFlagOperator.setAndGetListenerFlags(com.hazelcast.map.impl.MapListenerFlagOperator.setAndGetListenerFlags) MapPutTransientCodec(com.hazelcast.client.impl.protocol.codec.MapPutTransientCodec) Collections.emptyMap(java.util.Collections.emptyMap) Iterator(java.util.Iterator) EntryEventType(com.hazelcast.core.EntryEventType) EventJournalReader(com.hazelcast.internal.journal.EventJournalReader) MapInterceptor(com.hazelcast.map.MapInterceptor) UnmodifiableLazySet(com.hazelcast.spi.impl.UnmodifiableLazySet) Data(com.hazelcast.internal.serialization.Data) MapPutAllCodec(com.hazelcast.client.impl.protocol.codec.MapPutAllCodec) MapEvictAllCodec(com.hazelcast.client.impl.protocol.codec.MapEvictAllCodec) MapTryPutCodec(com.hazelcast.client.impl.protocol.codec.MapTryPutCodec) ClientProxy(com.hazelcast.client.impl.spi.ClientProxy) MapExecuteOnKeysCodec(com.hazelcast.client.impl.protocol.codec.MapExecuteOnKeysCodec) TimeUnit(java.util.concurrent.TimeUnit) AbstractMap(java.util.AbstractMap) PagingPredicateImpl(com.hazelcast.query.impl.predicates.PagingPredicateImpl) ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) QueryCache(com.hazelcast.map.QueryCache) MapPartitionLostListener(com.hazelcast.map.listener.MapPartitionLostListener) ReadResultSet(com.hazelcast.ringbuffer.ReadResultSet) EventJournalInitialSubscriberState(com.hazelcast.internal.journal.EventJournalInitialSubscriberState) Collections(java.util.Collections) MapReplaceAllCodec(com.hazelcast.client.impl.protocol.codec.MapReplaceAllCodec) IMap(com.hazelcast.map.IMap) HashMap(java.util.HashMap) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Data(com.hazelcast.internal.serialization.Data) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractMap(java.util.AbstractMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UnmodifiableLazyList(com.hazelcast.spi.impl.UnmodifiableLazyList) ArrayList(java.util.ArrayList) List(java.util.List) ClientPartitionService(com.hazelcast.client.impl.spi.ClientPartitionService) Map(java.util.Map) HashMap(java.util.HashMap) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Collections.emptyMap(java.util.Collections.emptyMap) AbstractMap(java.util.AbstractMap) IMap(com.hazelcast.map.IMap)

Example 19 with InternalCompletableFuture

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

the class ClientMultiMapProxy method putAllInternal.

@SuppressWarnings({ "checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity", "checkstyle:methodlength" })
private void putAllInternal(@Nonnull Map<Data, Collection<Data>> map, @Nonnull InternalCompletableFuture<Void> future) {
    if (map.isEmpty()) {
        future.complete(null);
        return;
    }
    ClientPartitionService partitionService = getContext().getPartitionService();
    int partitionCount = partitionService.getPartitionCount();
    Map<Integer, Collection<Map.Entry<Data, Collection<Data>>>> entryMap = new HashMap<>(partitionCount);
    for (Map.Entry<Data, Collection<Data>> entry : map.entrySet()) {
        checkNotNull(entry.getKey(), NULL_KEY_IS_NOT_ALLOWED);
        checkNotNull(entry.getValue(), NULL_VALUE_IS_NOT_ALLOWED);
        Data keyData = entry.getKey();
        int partitionId = partitionService.getPartitionId(keyData);
        Collection<Map.Entry<Data, Collection<Data>>> partition = entryMap.get(partitionId);
        if (partition == null) {
            partition = new ArrayList<>();
            entryMap.put(partitionId, partition);
        }
        partition.add(new AbstractMap.SimpleEntry<>(keyData, entry.getValue()));
    }
    assert entryMap.size() > 0;
    AtomicInteger counter = new AtomicInteger(entryMap.size());
    InternalCompletableFuture<Void> resultFuture = future;
    BiConsumer<ClientMessage, Throwable> callback = (response, t) -> {
        if (t != null) {
            resultFuture.completeExceptionally(t);
        }
        if (counter.decrementAndGet() == 0) {
            if (!resultFuture.isDone()) {
                resultFuture.complete(null);
            }
        }
    };
    for (Map.Entry<Integer, Collection<Map.Entry<Data, Collection<Data>>>> entry : entryMap.entrySet()) {
        Integer partitionId = entry.getKey();
        // if there is only one entry, consider how we can use MapPutRequest
        // without having to get back the return value
        ClientMessage request = MultiMapPutAllCodec.encodeRequest(name, entry.getValue());
        new ClientInvocation(getClient(), request, getName(), partitionId).invoke().whenCompleteAsync(callback);
    }
}
Also used : MultiMapPutCodec(com.hazelcast.client.impl.protocol.codec.MultiMapPutCodec) MultiMapContainsValueCodec(com.hazelcast.client.impl.protocol.codec.MultiMapContainsValueCodec) MultiMapAddEntryListenerCodec(com.hazelcast.client.impl.protocol.codec.MultiMapAddEntryListenerCodec) MultiMapForceUnlockCodec(com.hazelcast.client.impl.protocol.codec.MultiMapForceUnlockCodec) Member(com.hazelcast.cluster.Member) ListenerAdapters.createListenerAdapter(com.hazelcast.map.impl.ListenerAdapters.createListenerAdapter) MultiMapSizeCodec(com.hazelcast.client.impl.protocol.codec.MultiMapSizeCodec) Thread.currentThread(java.lang.Thread.currentThread) CollectionUtil(com.hazelcast.internal.util.CollectionUtil) EventHandler(com.hazelcast.client.impl.spi.EventHandler) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) MultiMapClearCodec(com.hazelcast.client.impl.protocol.codec.MultiMapClearCodec) ListenerMessageCodec(com.hazelcast.client.impl.spi.impl.ListenerMessageCodec) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MultiMapContainsEntryCodec(com.hazelcast.client.impl.protocol.codec.MultiMapContainsEntryCodec) Map(java.util.Map) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientLockReferenceIdGenerator(com.hazelcast.client.impl.clientside.ClientLockReferenceIdGenerator) MultiMapIsLockedCodec(com.hazelcast.client.impl.protocol.codec.MultiMapIsLockedCodec) MultiMapPutAllCodec(com.hazelcast.client.impl.protocol.codec.MultiMapPutAllCodec) EntryEvent(com.hazelcast.core.EntryEvent) MultiMapEntrySetCodec(com.hazelcast.client.impl.protocol.codec.MultiMapEntrySetCodec) LocalMultiMapStats(com.hazelcast.multimap.LocalMultiMapStats) ClientPartitionService(com.hazelcast.client.impl.spi.ClientPartitionService) MultiMapLockCodec(com.hazelcast.client.impl.protocol.codec.MultiMapLockCodec) Collection(java.util.Collection) Set(java.util.Set) EntryListener(com.hazelcast.core.EntryListener) UUID(java.util.UUID) MultiMapRemoveEntryCodec(com.hazelcast.client.impl.protocol.codec.MultiMapRemoveEntryCodec) MultiMapDeleteCodec(com.hazelcast.client.impl.protocol.codec.MultiMapDeleteCodec) UnmodifiableLazyList(com.hazelcast.spi.impl.UnmodifiableLazyList) CompletionStage(java.util.concurrent.CompletionStage) Preconditions.checkPositive(com.hazelcast.internal.util.Preconditions.checkPositive) MultiMapAddEntryListenerToKeyCodec(com.hazelcast.client.impl.protocol.codec.MultiMapAddEntryListenerToKeyCodec) MultiMapGetCodec(com.hazelcast.client.impl.protocol.codec.MultiMapGetCodec) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) MultiMapRemoveEntryListenerCodec(com.hazelcast.client.impl.protocol.codec.MultiMapRemoveEntryListenerCodec) MultiMapTryLockCodec(com.hazelcast.client.impl.protocol.codec.MultiMapTryLockCodec) DataAwareEntryEvent(com.hazelcast.map.impl.DataAwareEntryEvent) HashMap(java.util.HashMap) IMapEvent(com.hazelcast.map.IMapEvent) MultiMapUnlockCodec(com.hazelcast.client.impl.protocol.codec.MultiMapUnlockCodec) ArrayList(java.util.ArrayList) MultiMapValuesCodec(com.hazelcast.client.impl.protocol.codec.MultiMapValuesCodec) MultiMap(com.hazelcast.multimap.MultiMap) ClientContext(com.hazelcast.client.impl.spi.ClientContext) BiConsumer(java.util.function.BiConsumer) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) EntryEventType(com.hazelcast.core.EntryEventType) UnmodifiableLazySet(com.hazelcast.spi.impl.UnmodifiableLazySet) MultiMapRemoveCodec(com.hazelcast.client.impl.protocol.codec.MultiMapRemoveCodec) Data(com.hazelcast.internal.serialization.Data) MultiMapContainsKeyCodec(com.hazelcast.client.impl.protocol.codec.MultiMapContainsKeyCodec) MultiMapKeySetCodec(com.hazelcast.client.impl.protocol.codec.MultiMapKeySetCodec) Preconditions.checkNotNull(com.hazelcast.internal.util.Preconditions.checkNotNull) ClientProxy(com.hazelcast.client.impl.spi.ClientProxy) TimeUnit(java.util.concurrent.TimeUnit) AbstractMap(java.util.AbstractMap) MultiMapValueCountCodec(com.hazelcast.client.impl.protocol.codec.MultiMapValueCountCodec) MapEvent(com.hazelcast.map.MapEvent) ListenerAdapter(com.hazelcast.map.impl.ListenerAdapter) ThreadUtil(com.hazelcast.internal.util.ThreadUtil) HashMap(java.util.HashMap) Data(com.hazelcast.internal.serialization.Data) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractMap(java.util.AbstractMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Collection(java.util.Collection) ClientPartitionService(com.hazelcast.client.impl.spi.ClientPartitionService) Map(java.util.Map) HashMap(java.util.HashMap) MultiMap(com.hazelcast.multimap.MultiMap) AbstractMap(java.util.AbstractMap)

Example 20 with InternalCompletableFuture

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

the class ClientExecutorServiceProxy method submitToRandomWithCallbackInternal.

private <T> void submitToRandomWithCallbackInternal(Data task, ExecutionCallback<T> callback) {
    checkNotNull(task, "task should not be null");
    UUID uuid = getUUID();
    int partitionId = randomPartitionId();
    ClientMessage request = ExecutorServiceSubmitToPartitionCodec.encodeRequest(name, uuid, task);
    ClientInvocationFuture f = invokeOnPartitionOwner(request, partitionId);
    InternalCompletableFuture<T> delegatingFuture = (InternalCompletableFuture<T>) delegatingFuture(f, uuid, partitionId, (T) null);
    if (callback != null) {
        delegatingFuture.whenCompleteAsync(new ExecutionCallbackAdapter<>(callback)).whenCompleteAsync((v, t) -> {
            if (t instanceof RejectedExecutionException) {
                callback.onFailure(t);
            }
        }, ConcurrencyUtil.getDefaultAsyncExecutor());
    }
}
Also used : ExecutionCallbackAdapter(com.hazelcast.executor.impl.ExecutionCallbackAdapter) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) UUID(java.util.UUID) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ClientInvocationFuture(com.hazelcast.client.impl.spi.impl.ClientInvocationFuture)

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