0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 package org.apache.spark.network.protocol;
0019
0020 import java.util.Objects;
0021
0022 import io.netty.buffer.ByteBuf;
0023 import org.apache.commons.lang3.builder.ToStringBuilder;
0024 import org.apache.commons.lang3.builder.ToStringStyle;
0025
0026
0027 public final class RpcFailure extends AbstractMessage implements ResponseMessage {
0028 public final long requestId;
0029 public final String errorString;
0030
0031 public RpcFailure(long requestId, String errorString) {
0032 this.requestId = requestId;
0033 this.errorString = errorString;
0034 }
0035
0036 @Override
0037 public Message.Type type() { return Type.RpcFailure; }
0038
0039 @Override
0040 public int encodedLength() {
0041 return 8 + Encoders.Strings.encodedLength(errorString);
0042 }
0043
0044 @Override
0045 public void encode(ByteBuf buf) {
0046 buf.writeLong(requestId);
0047 Encoders.Strings.encode(buf, errorString);
0048 }
0049
0050 public static RpcFailure decode(ByteBuf buf) {
0051 long requestId = buf.readLong();
0052 String errorString = Encoders.Strings.decode(buf);
0053 return new RpcFailure(requestId, errorString);
0054 }
0055
0056 @Override
0057 public int hashCode() {
0058 return Objects.hash(requestId, errorString);
0059 }
0060
0061 @Override
0062 public boolean equals(Object other) {
0063 if (other instanceof RpcFailure) {
0064 RpcFailure o = (RpcFailure) other;
0065 return requestId == o.requestId && errorString.equals(o.errorString);
0066 }
0067 return false;
0068 }
0069
0070 @Override
0071 public String toString() {
0072 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
0073 .append("requestId", requestId)
0074 .append("errorString", errorString)
0075 .toString();
0076 }
0077 }