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

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

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

import java.net.SocketAddress;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import org.infinispan.client.hotrod.configuration.ClientIntelligence;
import org.infinispan.client.hotrod.impl.protocol.Codec;
import org.infinispan.client.hotrod.impl.transport.TransportFactory;

/**
 * @author Guillaume Darmont / [email protected]
 */
public class GetAllParallelOperation extends ParallelHotRodOperation, GetAllOperation> {

   private final Set keys;

   protected GetAllParallelOperation(Codec codec, TransportFactory transportFactory, Set keys, byte[]
         cacheName, AtomicInteger topologyId, int flags, ClientIntelligence clientIntelligence, ExecutorService executorService) {
      super(codec, transportFactory, cacheName, topologyId, flags, clientIntelligence, executorService);
      this.keys = keys;
   }

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

      for (byte[] key : keys) {
         SocketAddress socketAddress = transportFactory.getSocketAddress(key, cacheName);
         Set keys = splittedKeys.get(socketAddress);
         if (keys == null) {
            keys = new HashSet<>();
            splittedKeys.put(socketAddress, keys);
         }
         keys.add(key);
      }

      return splittedKeys.values().stream().map(
            keysSubset -> new GetAllOperation(codec, transportFactory, keysSubset, cacheName, topologyId,
                  flags, clientIntelligence)).collect(Collectors.toList());
   }

   @Override
   protected Map createCollector() {
      return new HashMap<>();
   }

   @Override
   protected void combine(Map collector, Map result) {
      collector.putAll(result);
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy