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.Arrays;
0021 import java.util.Objects;
0022 
0023 import io.netty.buffer.ByteBuf;
0024 import org.apache.commons.lang3.builder.ToStringBuilder;
0025 import org.apache.commons.lang3.builder.ToStringStyle;
0026 
0027 import org.apache.spark.network.protocol.Encoders;
0028 
0029 // Needed by ScalaDoc. See SPARK-7726
0030 import static org.apache.spark.network.shuffle.protocol.BlockTransferMessage.Type;
0031 
0032 /** Request to read a set of blocks. Returns {@link StreamHandle}. */
0033 public class OpenBlocks extends BlockTransferMessage {
0034   public final String appId;
0035   public final String execId;
0036   public final String[] blockIds;
0037 
0038   public OpenBlocks(String appId, String execId, String[] blockIds) {
0039     this.appId = appId;
0040     this.execId = execId;
0041     this.blockIds = blockIds;
0042   }
0043 
0044   @Override
0045   protected Type type() { return Type.OPEN_BLOCKS; }
0046 
0047   @Override
0048   public int hashCode() {
0049     return Objects.hash(appId, execId) * 41 + Arrays.hashCode(blockIds);
0050   }
0051 
0052   @Override
0053   public String toString() {
0054     return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
0055       .append("appId", appId)
0056       .append("execId", execId)
0057       .append("blockIds", Arrays.toString(blockIds))
0058       .toString();
0059   }
0060 
0061   @Override
0062   public boolean equals(Object other) {
0063     if (other != null && other instanceof OpenBlocks) {
0064       OpenBlocks o = (OpenBlocks) other;
0065       return Objects.equals(appId, o.appId)
0066         && Objects.equals(execId, o.execId)
0067         && Arrays.equals(blockIds, o.blockIds);
0068     }
0069     return false;
0070   }
0071 
0072   @Override
0073   public int encodedLength() {
0074     return Encoders.Strings.encodedLength(appId)
0075       + Encoders.Strings.encodedLength(execId)
0076       + Encoders.StringArrays.encodedLength(blockIds);
0077   }
0078 
0079   @Override
0080   public void encode(ByteBuf buf) {
0081     Encoders.Strings.encode(buf, appId);
0082     Encoders.Strings.encode(buf, execId);
0083     Encoders.StringArrays.encode(buf, blockIds);
0084   }
0085 
0086   public static OpenBlocks decode(ByteBuf buf) {
0087     String appId = Encoders.Strings.decode(buf);
0088     String execId = Encoders.Strings.decode(buf);
0089     String[] blockIds = Encoders.StringArrays.decode(buf);
0090     return new OpenBlocks(appId, execId, blockIds);
0091   }
0092 }