Search in sources :

Example 1 with NULL_KEY_IS_NOT_ALLOWED

use of com.hazelcast.multimap.impl.MultiMapProxyImpl.NULL_KEY_IS_NOT_ALLOWED in project hazelcast by hazelcast.

the class MultiMapProxySupport method putAllInternal.

// NB: this method is generally copied from MapProxySupport#putAllInternal
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:methodlength" })
protected void putAllInternal(Map<Data, Data> map, @Nullable InternalCompletableFuture<Void> future) {
    // get partition to entries mapping
    try {
        int mapSize = map.size();
        if (mapSize == 0) {
            if (future != null) {
                future.complete(null);
            }
            return;
        }
        int partitionCount = partitionService.getPartitionCount();
        int initialSize = getPutAllInitialSize(mapSize, partitionCount);
        // get node to partition mapping
        Map<Address, List<Integer>> memberPartitionsMap = partitionService.getMemberPartitionsMap();
        // fill entriesPerPartition
        MapEntries[] entriesPerPartition = new MapEntries[partitionCount];
        for (Map.Entry<Data, 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);
            MapEntries entries = entriesPerPartition[partitionId];
            if (entries == null) {
                entries = new MapEntries(initialSize);
                entriesPerPartition[partitionId] = entries;
            }
            entries.add(keyData, entry.getValue());
        }
        // invoke operations for entriesPerPartition
        AtomicInteger counter = new AtomicInteger(memberPartitionsMap.size());
        InternalCompletableFuture<Void> resultFuture = future != null ? future : new InternalCompletableFuture<>();
        BiConsumer<Void, Throwable> callback = (response, t) -> {
            if (t != null) {
                resultFuture.completeExceptionally(t);
            }
            if (counter.decrementAndGet() == 0) {
                if (!resultFuture.isDone()) {
                    resultFuture.complete(null);
                }
            }
        };
        for (Map.Entry<Address, List<Integer>> entry : memberPartitionsMap.entrySet()) {
            invokePutAllOperation(entry.getKey(), entry.getValue(), entriesPerPartition).whenCompleteAsync(callback);
        }
        // if executing in sync mode, block for the responses
        if (future == null) {
            resultFuture.get();
        }
    } catch (Throwable e) {
        throw rethrow(e);
    }
}
Also used : Address(com.hazelcast.cluster.Address) Arrays(java.util.Arrays) CompletableFuture(java.util.concurrent.CompletableFuture) ExceptionUtil.rethrow(com.hazelcast.internal.util.ExceptionUtil.rethrow) AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) HashSet(java.util.HashSet) Future(java.util.concurrent.Future) MultiMapConfig(com.hazelcast.config.MultiMapConfig) NULL_VALUE_IS_NOT_ALLOWED(com.hazelcast.multimap.impl.MultiMapProxyImpl.NULL_VALUE_IS_NOT_ALLOWED) MapEntries(com.hazelcast.map.impl.MapEntries) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PutOperation(com.hazelcast.multimap.impl.operations.PutOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) GetAllOperation(com.hazelcast.multimap.impl.operations.GetAllOperation) MultiMapOperationFactory(com.hazelcast.multimap.impl.operations.MultiMapOperationFactory) Collections.singletonMap(java.util.Collections.singletonMap) MapUtil.toIntSize(com.hazelcast.internal.util.MapUtil.toIntSize) MultiMapResponse(com.hazelcast.multimap.impl.operations.MultiMapResponse) OperationFactoryType(com.hazelcast.multimap.impl.operations.MultiMapOperationFactory.OperationFactoryType) LockSupportServiceImpl(com.hazelcast.internal.locksupport.LockSupportServiceImpl) Nullable(javax.annotation.Nullable) Timer(com.hazelcast.internal.util.Timer) CALLER_RUNS(com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS) RemoveOperation(com.hazelcast.multimap.impl.operations.RemoveOperation) InternalCompletableFuture.newCompletedFuture(com.hazelcast.spi.impl.InternalCompletableFuture.newCompletedFuture) NodeEngine(com.hazelcast.spi.impl.NodeEngine) EntryEventType(com.hazelcast.core.EntryEventType) IPartitionService(com.hazelcast.internal.partition.IPartitionService) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) CollectionUtil.asIntegerList(com.hazelcast.internal.util.CollectionUtil.asIntegerList) Data(com.hazelcast.internal.serialization.Data) ExceptionUtil(com.hazelcast.internal.util.ExceptionUtil) Set(java.util.Set) LocalMultiMapStatsImpl(com.hazelcast.internal.monitor.impl.LocalMultiMapStatsImpl) Preconditions.checkNotNull(com.hazelcast.internal.util.Preconditions.checkNotNull) DeleteOperation(com.hazelcast.multimap.impl.operations.DeleteOperation) MultiMapPutAllOperationFactory(com.hazelcast.multimap.impl.operations.MultiMapPutAllOperationFactory) RemoveAllOperation(com.hazelcast.multimap.impl.operations.RemoveAllOperation) List(java.util.List) LockProxySupport(com.hazelcast.internal.locksupport.LockProxySupport) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) NULL_KEY_IS_NOT_ALLOWED(com.hazelcast.multimap.impl.MultiMapProxyImpl.NULL_KEY_IS_NOT_ALLOWED) CountOperation(com.hazelcast.multimap.impl.operations.CountOperation) ThreadUtil(com.hazelcast.internal.util.ThreadUtil) Address(com.hazelcast.cluster.Address) Data(com.hazelcast.internal.serialization.Data) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapEntries(com.hazelcast.map.impl.MapEntries) CollectionUtil.asIntegerList(com.hazelcast.internal.util.CollectionUtil.asIntegerList) List(java.util.List) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap)

Aggregations

Address (com.hazelcast.cluster.Address)1 MultiMapConfig (com.hazelcast.config.MultiMapConfig)1 EntryEventType (com.hazelcast.core.EntryEventType)1 LockProxySupport (com.hazelcast.internal.locksupport.LockProxySupport)1 LockSupportServiceImpl (com.hazelcast.internal.locksupport.LockSupportServiceImpl)1 LocalMultiMapStatsImpl (com.hazelcast.internal.monitor.impl.LocalMultiMapStatsImpl)1 IPartitionService (com.hazelcast.internal.partition.IPartitionService)1 Data (com.hazelcast.internal.serialization.Data)1 DistributedObjectNamespace (com.hazelcast.internal.services.DistributedObjectNamespace)1 CollectionUtil.asIntegerList (com.hazelcast.internal.util.CollectionUtil.asIntegerList)1 CALLER_RUNS (com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS)1 ExceptionUtil (com.hazelcast.internal.util.ExceptionUtil)1 ExceptionUtil.rethrow (com.hazelcast.internal.util.ExceptionUtil.rethrow)1 MapUtil.toIntSize (com.hazelcast.internal.util.MapUtil.toIntSize)1 Preconditions.checkNotNull (com.hazelcast.internal.util.Preconditions.checkNotNull)1 ThreadUtil (com.hazelcast.internal.util.ThreadUtil)1 Timer (com.hazelcast.internal.util.Timer)1 MapEntries (com.hazelcast.map.impl.MapEntries)1 NULL_KEY_IS_NOT_ALLOWED (com.hazelcast.multimap.impl.MultiMapProxyImpl.NULL_KEY_IS_NOT_ALLOWED)1 NULL_VALUE_IS_NOT_ALLOWED (com.hazelcast.multimap.impl.MultiMapProxyImpl.NULL_VALUE_IS_NOT_ALLOWED)1