com.alachisoft.ncache.client.internal.command.RaiseCustomEventCommand Maven / Gradle / Ivy
package com.alachisoft.ncache.client.internal.command;
import com.alachisoft.ncache.common.protobuf.CommandProtocol;
import com.alachisoft.ncache.common.protobuf.RaiseCustomEventCommandProtocol;
import com.alachisoft.ncache.runtime.exceptions.CommandException;
import com.google.protobuf.ByteString;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public final class RaiseCustomEventCommand extends com.alachisoft.ncache.client.internal.command.Command {
private java.lang.Object notifId;
private Object _notifData = null;
private int _methodOverload = 0;
protected com.alachisoft.ncache.common.protobuf.RaiseCustomEventCommandProtocol.RaiseCustomEventCommand _commandInstance;
public RaiseCustomEventCommand(java.lang.Object key,
java.lang.Object value, boolean async) {
name = "RAISECUSTOMNOTIF";
notifId = key;
this._notifData = value;
isAsync = async;
}
public void createCommand() throws CommandException {
if (notifId == null) {
throw new NullPointerException("notifId");
}
if (this._notifData == null) {
throw new NullPointerException("value");
}
// java.lang.String isAsync = !this.isAsync ? "N" : "Y";
// java.lang.String cmdString = (new StringBuilder()).append(name).append(
// " \"").append(getRequestId()).append("\"").toString();
RaiseCustomEventCommandProtocol.RaiseCustomEventCommand.Builder builder =
RaiseCustomEventCommandProtocol.RaiseCustomEventCommand.newBuilder();
builder = builder.setRequestId(this.getRequestId())
.setNotifIf(ByteString.copyFrom((byte[]) this.notifId))
.setData(ByteString.copyFrom((byte[]) this._notifData));
//
//
//
// // The final outputstream containing complete command array
// java.io.ByteArrayOutputStream memStream = new ByteArrayOutputStream();
//
// //
// java.io.ByteArrayOutputStream notifByteStream = new ByteArrayOutputStream();
// java.io.ObjectOutputStream notifObjectStream = null;
// try {
// notifObjectStream = new ObjectOutputStream(notifByteStream);
// } catch (java.io.IOException ex) {
// throw new CommandException(ex.getMessage());
// }
// byte objectLength[] = new byte[CommandOptions.DATA_SIZE];
// try {
// notifObjectStream.writeObject(this.notifId);
// } catch (java.io.IOException ex) {
// throw new CommandException(ex.getMessage());
// }
// byte serializedNotif[] = notifByteStream.toByteArray();
// byte lengthInUTFBytes[] = null;
// try {
// lengthInUTFBytes = com.alachisoft.ncache.util.HelperFxn.getUTF8Bytes(serializedNotif.length);
// } catch (java.io.UnsupportedEncodingException ex) {
// throw new CommandException(ex.getMessage());
// }
// java.lang.System.arraycopy(lengthInUTFBytes, 0, objectLength, 0,
// lengthInUTFBytes.length);
// memStream.write(objectLength, 0, objectLength.length);
// memStream.write(serializedNotif, 0, serializedNotif.length);
// //
//
// //
// java.io.ByteArrayOutputStream valueByteStream = new ByteArrayOutputStream();
// java.io.ObjectOutputStream valueObjectStream = null;
// try {
// valueObjectStream = new ObjectOutputStream(valueByteStream);
// } catch (java.io.IOException ex) {
// throw new CommandException(ex.getMessage());
// }
// byte dataLen[] = new byte[CommandOptions.DATA_SIZE];
// try {
// notifObjectStream.writeObject(this.value);
// } catch (java.io.IOException ex) {
// throw new CommandException(ex.getMessage());
// }
// byte value[] = notifByteStream.toByteArray();
// byte data[] = null;
// try {
// data = com.alachisoft.ncache.util.HelperFxn.getUTF8Bytes(value.length);
// } catch (java.io.UnsupportedEncodingException ex) {
// throw new CommandException(ex.getMessage());
// }
// java.lang.System.arraycopy(data, 0, dataLen, 0, data.length);
// memStream.write(dataLen, 0, CommandOptions.DATA_SIZE);
// memStream.write(value, 0, value.length);
// //
_commandInstance =builder
.setMethodOverload(_methodOverload).build();
}
public CommandType getCommandType() {
return CommandType.RAISE_CUSTOM_EVENT;
}
@Override
public RequestType getCommandRequestType() {
return RequestType.AtomicWrite;
}
@Override
protected void serializeCommandInternal(ByteArrayOutputStream stream) throws IOException
{
_commandInstance.writeTo(stream);
}
@Override
protected short getCommandHandle()
{
return (short)CommandProtocol.Command.Type.RAISE_CUSTOM_EVENT.getNumber();
}
}