com.alachisoft.ncache.client.internal.command.InitSecondarySocketCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ncache-professional-client Show documentation
Show all versions of ncache-professional-client Show documentation
NCache Professional client for java.
package com.alachisoft.ncache.client.internal.command;
import com.alachisoft.ncache.runtime.exceptions.CommandException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
public class InitSecondarySocketCommand extends InitialCommandBase {
private String clientId;
public InitSecondarySocketCommand(String clientID) {
super();
clientId = clientID;
}
@Override
public CommandType getCommandType() {
return CommandType.INIT_SECONDARY;
}
@Override
public RequestType getCommandRequestType() {
return RequestType.InternalCommand;
}
@Override
protected void createCommand() throws CommandException {
try {
constructCommand("InitSecondarySocketCommand \"" + super.getRequestId() + "\"" + clientId + "\"Y\"", new byte[0]);
} catch (UnsupportedEncodingException e) {
}
}
protected byte[] constructCommand(String cmdString, byte[] data) throws UnsupportedEncodingException
{
byte[] command = cmdString.getBytes(StandardCharsets.UTF_8);
byte[] buffer = new byte[2 * (CommandOptions.COMMAND_SIZE + CommandOptions.DATA_SIZE) + command.length + data.length];
byte[] commandSize = String.valueOf(command.length).getBytes(StandardCharsets.UTF_8);
byte[] dataSize = String.valueOf(data.length).getBytes(StandardCharsets.UTF_8);
System.arraycopy(commandSize, 0, buffer, 0, commandSize.length);
System.arraycopy(dataSize, 0, buffer, CommandOptions.COMMAND_SIZE,
dataSize.length);
// we copy the command size two times to avoid if an corruption occurs.
System.arraycopy(commandSize, 0, buffer, CommandOptions.TOTAL_SIZE,
commandSize.length);
System.arraycopy(dataSize, 0, buffer, CommandOptions.TOTAL_SIZE + CommandOptions.COMMAND_SIZE, dataSize.length);
System.arraycopy(command, 0, buffer, 2 * CommandOptions.TOTAL_SIZE,
command.length);
System.arraycopy(data, 0, buffer, (2 * CommandOptions.TOTAL_SIZE) + command.length, data.length);
return buffer;
}
}