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

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

The 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