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

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

The 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.atomic.AtomicReference;
import java.util.stream.Collectors;

import org.infinispan.client.hotrod.DataFormat;
import org.infinispan.client.hotrod.configuration.Configuration;
import org.infinispan.client.hotrod.impl.ClientStatistics;
import org.infinispan.client.hotrod.impl.ClientTopology;
import org.infinispan.client.hotrod.impl.protocol.Codec;
import org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory;

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

   private final Set keys;

   protected GetAllParallelOperation(Codec codec, ChannelFactory channelFactory, Set keys, byte[]
         cacheName, AtomicReference clientTopology, int flags, Configuration cfg, DataFormat dataFormat, ClientStatistics clientStatistics) {
      super(codec, channelFactory, cacheName, clientTopology, flags, cfg, dataFormat, clientStatistics);
      this.keys = keys;
   }

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

      for (byte[] key : keys) {
         SocketAddress socketAddress = channelFactory.getHashAwareServer(key, cacheName());
         Set keys = splittedKeys.computeIfAbsent(socketAddress, k -> new HashSet<>());
         keys.add(key);
      }

      return splittedKeys.values().stream().map(
            keysSubset -> new GetAllOperation(codec, channelFactory, keysSubset, cacheName(), header.getClientTopology(),
                  flags(), cfg, dataFormat(), clientStatistics)).collect(Collectors.toList());
   }

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy