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

com.alachisoft.ncache.client.internal.command.ReadFromStreamCommand Maven / Gradle / Ivy

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.alachisoft.ncache.client.internal.command;

import com.alachisoft.ncache.common.protobuf.CommandProtocol;
import com.alachisoft.ncache.common.protobuf.ReadFromStreamCommandProtocol;
import com.alachisoft.ncache.runtime.exceptions.CommandException;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @author Administrator
 */
public class ReadFromStreamCommand extends Command {

    private ReadFromStreamCommandProtocol.ReadFromStreamCommand.Builder readFromStreamCommand;
    protected com.alachisoft.ncache.common.protobuf.ReadFromStreamCommandProtocol.ReadFromStreamCommand _commandInstance;



    public ReadFromStreamCommand(String key, String lockHandle, int streamOffset, int length) {
        readFromStreamCommand = ReadFromStreamCommandProtocol.ReadFromStreamCommand.newBuilder();

        if (key == null) {
            throw new IllegalArgumentException("Value cannot be null."+System.lineSeparator()+"Parameter name: key");
        }
        if (key.equals("")) {
            throw new IllegalArgumentException("Value cannot be empty.\nParameter name: key");
        }
        readFromStreamCommand.setKey(key);
        readFromStreamCommand.setLockHandle(lockHandle);
        readFromStreamCommand.setLength(length);
        readFromStreamCommand.setOffset(streamOffset);

    }

    public void createCommand() throws CommandException {
        _commandInstance =readFromStreamCommand.setRequestId(this.getRequestId()).build();
    }


    public CommandType getCommandType() {
        return CommandType.READ_FROM_STREAM;
    }

    @Override
    public RequestType getCommandRequestType() {
        return RequestType.AtomicRead;
    }

    @Override
    protected  void serializeCommandInternal(ByteArrayOutputStream stream) throws IOException
    {
        _commandInstance.writeTo(stream);
    }
    @Override
    protected short getCommandHandle()
    {
        return (short)CommandProtocol.Command.Type.READ_FROM_STREAM.getNumber();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy