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 get the local dirs for the given executors. */
0033 public class GetLocalDirsForExecutors extends BlockTransferMessage {
0034   public final String appId;
0035   public final String[] execIds;
0036 
0037   public GetLocalDirsForExecutors(String appId, String[] execIds) {
0038     this.appId = appId;
0039     this.execIds = execIds;
0040   }
0041 
0042   @Override
0043   protected Type type() { return Type.GET_LOCAL_DIRS_FOR_EXECUTORS; }
0044 
0045   @Override
0046   public int hashCode() {
0047     return Objects.hashCode(appId) * 41 + Arrays.hashCode(execIds);
0048   }
0049 
0050   @Override
0051   public String toString() {
0052     return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
0053       .append("appId", appId)
0054       .append("execIds", Arrays.toString(execIds))
0055       .toString();
0056   }
0057 
0058   @Override
0059   public boolean equals(Object other) {
0060     if (other instanceof GetLocalDirsForExecutors) {
0061       GetLocalDirsForExecutors o = (GetLocalDirsForExecutors) other;
0062       return appId.equals(o.appId) && Arrays.equals(execIds, o.execIds);
0063     }
0064     return false;
0065   }
0066 
0067   @Override
0068   public int encodedLength() {
0069     return Encoders.Strings.encodedLength(appId) + Encoders.StringArrays.encodedLength(execIds);
0070   }
0071 
0072   @Override
0073   public void encode(ByteBuf buf) {
0074     Encoders.Strings.encode(buf, appId);
0075     Encoders.StringArrays.encode(buf, execIds);
0076   }
0077 
0078   public static GetLocalDirsForExecutors decode(ByteBuf buf) {
0079     String appId = Encoders.Strings.decode(buf);
0080     String[] execIds = Encoders.StringArrays.decode(buf);
0081     return new GetLocalDirsForExecutors(appId, execIds);
0082   }
0083 }