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 /**
0027  * Response to {@link ChunkFetchRequest} when there is an error fetching the chunk.
0028  */
0029 public final class ChunkFetchFailure extends AbstractMessage implements ResponseMessage {
0030   public final StreamChunkId streamChunkId;
0031   public final String errorString;
0032 
0033   public ChunkFetchFailure(StreamChunkId streamChunkId, String errorString) {
0034     this.streamChunkId = streamChunkId;
0035     this.errorString = errorString;
0036   }
0037 
0038   @Override
0039   public Message.Type type() { return Type.ChunkFetchFailure; }
0040 
0041   @Override
0042   public int encodedLength() {
0043     return streamChunkId.encodedLength() + Encoders.Strings.encodedLength(errorString);
0044   }
0045 
0046   @Override
0047   public void encode(ByteBuf buf) {
0048     streamChunkId.encode(buf);
0049     Encoders.Strings.encode(buf, errorString);
0050   }
0051 
0052   public static ChunkFetchFailure decode(ByteBuf buf) {
0053     StreamChunkId streamChunkId = StreamChunkId.decode(buf);
0054     String errorString = Encoders.Strings.decode(buf);
0055     return new ChunkFetchFailure(streamChunkId, errorString);
0056   }
0057 
0058   @Override
0059   public int hashCode() {
0060     return Objects.hash(streamChunkId, errorString);
0061   }
0062 
0063   @Override
0064   public boolean equals(Object other) {
0065     if (other instanceof ChunkFetchFailure) {
0066       ChunkFetchFailure o = (ChunkFetchFailure) other;
0067       return streamChunkId.equals(o.streamChunkId) && errorString.equals(o.errorString);
0068     }
0069     return false;
0070   }
0071 
0072   @Override
0073   public String toString() {
0074     return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
0075       .append("streamChunkId", streamChunkId)
0076       .append("errorString", errorString)
0077       .toString();
0078   }
0079 }