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

org.infinispan.hotrod.impl.operations.PutAllParallelOperation Maven / Gradle / Ivy

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

import java.net.SocketAddress;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.infinispan.api.common.CacheWriteOptions;
import org.infinispan.hotrod.impl.DataFormat;

/**
 *
 */
public class PutAllParallelOperation extends ParallelHotRodOperation {

   protected final Map map;

   public PutAllParallelOperation(OperationContext operationContext, Map map, CacheWriteOptions options,
                                  DataFormat dataFormat) {
      super(operationContext, options, dataFormat);
      this.map = map;
   }

   @Override
   protected List mapOperations() {
      Map> splittedMaps = new HashMap<>();

      for (Map.Entry entry : map.entrySet()) {
         SocketAddress socketAddress = operationContext.getChannelFactory().getHashAwareServer(entry.getKey(), operationContext.getCacheNameBytes());
         Map keyValueMap = splittedMaps.computeIfAbsent(socketAddress, k -> new HashMap<>());
         keyValueMap.put(entry.getKey(), entry.getValue());
      }

      return splittedMaps.values().stream().map(
            mapSubset -> new PutAllOperation(operationContext, mapSubset, (CacheWriteOptions) options, dataFormat())).collect(Collectors.toList());
   }

   @Override
   protected Void createCollector() {
      return null;
   }

   @Override
   protected void combine(Void collector, Void result) {
      // Nothing to do
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy