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 import org.apache.spark.network.protocol.Encoders;
0027 
0028 // Needed by ScalaDoc. See SPARK-7726
0029 import static org.apache.spark.network.shuffle.protocol.BlockTransferMessage.Type;
0030 
0031 /**
0032  * Initial registration message between an executor and its local shuffle server.
0033  * Returns nothing (empty byte array).
0034  */
0035 public class RegisterExecutor extends BlockTransferMessage {
0036   public final String appId;
0037   public final String execId;
0038   public final ExecutorShuffleInfo executorInfo;
0039 
0040   public RegisterExecutor(
0041       String appId,
0042       String execId,
0043       ExecutorShuffleInfo executorInfo) {
0044     this.appId = appId;
0045     this.execId = execId;
0046     this.executorInfo = executorInfo;
0047   }
0048 
0049   @Override
0050   protected Type type() { return Type.REGISTER_EXECUTOR; }
0051 
0052   @Override
0053   public int hashCode() {
0054     return Objects.hash(appId, execId, executorInfo);
0055   }
0056 
0057   @Override
0058   public String toString() {
0059     return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
0060       .append("appId", appId)
0061       .append("execId", execId)
0062       .append("executorInfo", executorInfo)
0063       .toString();
0064   }
0065 
0066   @Override
0067   public boolean equals(Object other) {
0068     if (other != null && other instanceof RegisterExecutor) {
0069       RegisterExecutor o = (RegisterExecutor) other;
0070       return Objects.equals(appId, o.appId)
0071         && Objects.equals(execId, o.execId)
0072         && Objects.equals(executorInfo, o.executorInfo);
0073     }
0074     return false;
0075   }
0076 
0077   @Override
0078   public int encodedLength() {
0079     return Encoders.Strings.encodedLength(appId)
0080       + Encoders.Strings.encodedLength(execId)
0081       + executorInfo.encodedLength();
0082   }
0083 
0084   @Override
0085   public void encode(ByteBuf buf) {
0086     Encoders.Strings.encode(buf, appId);
0087     Encoders.Strings.encode(buf, execId);
0088     executorInfo.encode(buf);
0089   }
0090 
0091   public static RegisterExecutor decode(ByteBuf buf) {
0092     String appId = Encoders.Strings.decode(buf);
0093     String execId = Encoders.Strings.decode(buf);
0094     ExecutorShuffleInfo executorShuffleInfo = ExecutorShuffleInfo.decode(buf);
0095     return new RegisterExecutor(appId, execId, executorShuffleInfo);
0096   }
0097 }