Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *    http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
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 /** Response to {@link RpcRequest} for a failed RPC. */
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 }