All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.infinispan.client.hotrod.impl.operations.ReplaceIfUnmodifiedOperation Maven / Gradle / Ivy
package org.infinispan.client.hotrod.impl.operations;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
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.VersionedOperationResponse;
import org.infinispan.client.hotrod.impl.protocol.Codec;
import org.infinispan.client.hotrod.impl.protocol.HotRodConstants;
import org.infinispan.client.hotrod.impl.transport.netty.ByteBufUtil;
import org.infinispan.client.hotrod.impl.transport.netty.ChannelFactory;
import org.infinispan.client.hotrod.impl.transport.netty.HeaderDecoder;
import org.infinispan.client.hotrod.telemetry.impl.TelemetryService;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
/**
* Implement "replaceIfUnmodified" as defined by Hot Rod
* protocol specification .
*
* @author [email protected]
* @since 4.1
*/
public class ReplaceIfUnmodifiedOperation extends AbstractKeyValueOperation {
private final long version;
public ReplaceIfUnmodifiedOperation(Codec codec, ChannelFactory channelFactory, Object key, byte[] keyBytes, byte[] cacheName,
AtomicReference clientTopology, int flags, Configuration cfg, byte[] value,
long lifespan, TimeUnit lifespanTimeUnit, long maxIdle, TimeUnit maxIdleTimeUnit,
long version, DataFormat dataFormat, ClientStatistics clientStatistics,
TelemetryService telemetryService) {
super(REPLACE_IF_UNMODIFIED_REQUEST, REPLACE_IF_UNMODIFIED_RESPONSE, codec, channelFactory, key, keyBytes, cacheName,
clientTopology, flags, cfg, value, lifespan, lifespanTimeUnit, maxIdle, maxIdleTimeUnit, dataFormat, clientStatistics,
telemetryService);
this.version = version;
}
@Override
protected void executeOperation(Channel channel) {
scheduleRead(channel);
ByteBuf buf = channel.alloc().buffer(codec.estimateHeaderSize(header) + ByteBufUtil.estimateArraySize(keyBytes) +
codec.estimateExpirationSize(lifespan, lifespanTimeUnit, maxIdle, maxIdleTimeUnit) + 8 +
ByteBufUtil.estimateArraySize(value));
codec.writeHeader(buf, header);
ByteBufUtil.writeArray(buf, keyBytes);
codec.writeExpirationParams(buf, lifespan, lifespanTimeUnit, maxIdle, maxIdleTimeUnit);
buf.writeLong(version);
ByteBufUtil.writeArray(buf, value);
channel.writeAndFlush(buf);
}
@Override
public void acceptResponse(ByteBuf buf, short status, HeaderDecoder decoder) {
if (HotRodConstants.isSuccess(status)) {
statsDataStore();
}
complete(returnVersionedOperationResponse(buf, status));
}
}