All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.client.hotrod.impl.operations.PutAllBulkOperation Maven / Gradle / Ivy

There is a newer version: 9.3.1.Final
Show newest version
package org.infinispan.client.hotrod.impl.operations;

import java.net.SocketAddress;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletionStage;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.infinispan.client.hotrod.DataFormat;

public class PutAllBulkOperation extends HotRodBulkOperation, Void, HotRodOperation> {
   private final Map values;

   public PutAllBulkOperation(Map values, DataFormat dataFormat,
                              Function, HotRodOperation> setPutAllOperationFunction) {
      super(dataFormat, setPutAllOperationFunction);
      this.values = values;
   }

   @Override
   protected Map> gatherOperations(
         Function routingFunction) {
      Map> serializedKeys = new HashMap<>();
      for (Map.Entry entry : values.entrySet()) {
         Object key = entry.getKey();
         byte[] keyBytes = dataFormat.keyToBytes(key);
         SocketAddress socketAddress = getAddressForKey(key, keyBytes, routingFunction);
         Map mapBytes = serializedKeys.computeIfAbsent(socketAddress, ___ -> new HashMap<>());
         mapBytes.put(keyBytes, dataFormat.valueToBytes(entry.getValue()));
      }
      return serializedKeys.entrySet().stream()
            .collect(Collectors.toMap(Map.Entry::getKey, e ->
               opFunction.apply(e.getValue())));
   }

   @Override
   public CompletionStage reduce(CompletionStage> stage) {
      return stage
            .thenApply(___ -> null);
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy