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.shuffle.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 // Needed by ScalaDoc. See SPARK-7726
0027 import static org.apache.spark.network.shuffle.protocol.BlockTransferMessage.Type;
0028 
0029 /** The reply to remove blocks giving back the number of removed blocks. */
0030 public class BlocksRemoved extends BlockTransferMessage {
0031   public final int numRemovedBlocks;
0032 
0033   public BlocksRemoved(int numRemovedBlocks) {
0034     this.numRemovedBlocks = numRemovedBlocks;
0035   }
0036 
0037   @Override
0038   protected Type type() { return Type.BLOCKS_REMOVED; }
0039 
0040   @Override
0041   public int hashCode() {
0042     return Objects.hashCode(numRemovedBlocks);
0043   }
0044 
0045   @Override
0046   public String toString() {
0047     return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
0048       .append("numRemovedBlocks", numRemovedBlocks)
0049       .toString();
0050   }
0051 
0052   @Override
0053   public boolean equals(Object other) {
0054     if (other != null && other instanceof BlocksRemoved) {
0055       BlocksRemoved o = (BlocksRemoved) other;
0056       return numRemovedBlocks == o.numRemovedBlocks;
0057     }
0058     return false;
0059   }
0060 
0061   @Override
0062   public int encodedLength() {
0063     return 4;
0064   }
0065 
0066   @Override
0067   public void encode(ByteBuf buf) {
0068     buf.writeInt(numRemovedBlocks);
0069   }
0070 
0071   public static BlocksRemoved decode(ByteBuf buf) {
0072     int numRemovedBlocks = buf.readInt();
0073     return new BlocksRemoved(numRemovedBlocks);
0074   }
0075 }