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

org.infinispan.client.hotrod.impl.operations.GetAllOperation 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.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import net.jcip.annotations.Immutable;

import org.infinispan.client.hotrod.configuration.Configuration;
import org.infinispan.client.hotrod.impl.protocol.Codec;
import org.infinispan.client.hotrod.impl.protocol.HeaderParams;
import org.infinispan.client.hotrod.impl.transport.Transport;
import org.infinispan.client.hotrod.impl.transport.TransportFactory;

/**
 * Implements "getAll" as defined by  Hot Rod protocol specification.
 *
 * @author William Burns
 * @since 7.2
 */
@Immutable
public class GetAllOperation extends RetryOnFailureOperation> {

   public GetAllOperation(Codec codec, TransportFactory transportFactory,
                          Set keys, byte[] cacheName, AtomicInteger topologyId,
                          int flags, Configuration cfg) {
      super(codec, transportFactory, cacheName, topologyId, flags, cfg);
      this.keys = keys;
   }

   protected final Set keys;

   @Override
   protected Map executeOperation(Transport transport) {
      HeaderParams params = writeHeader(transport, GET_ALL_REQUEST);
      transport.writeVInt(keys.size());
      for (byte[] key : keys) {
         transport.writeArray(key);
      }
      transport.flush();

      short status = readHeaderAndValidate(transport, params);
      int size = transport.readVInt();
      Map result = new HashMap(size);
      for (int i = 0; i < size; ++i) {
         K key = codec.readUnmarshallByteArray(transport, status, cfg.serialWhitelist());
         V value = codec.readUnmarshallByteArray(transport, status, cfg.serialWhitelist());
         result.put(key, value);
      }
      return result;
   }

   @Override
   protected Transport getTransport(int retryCount, Set failedServers) {
      return transportFactory.getTransport(keys.iterator().next(), failedServers, cacheName);
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy