org.infinispan.hotrod.impl.operations.PutAllParallelOperation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of infinispan-hotrod-jakarta Show documentation
Show all versions of infinispan-hotrod-jakarta Show documentation
Infinispan Hot Rod Client Jakarta EE
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
}
}