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.mesos;
0019 
0020 import com.google.common.base.Objects;
0021 import io.netty.buffer.ByteBuf;
0022 
0023 import org.apache.spark.network.protocol.Encoders;
0024 import org.apache.spark.network.shuffle.protocol.BlockTransferMessage;
0025 
0026 // Needed by ScalaDoc. See SPARK-7726
0027 import static org.apache.spark.network.shuffle.protocol.BlockTransferMessage.Type;
0028 
0029 /**
0030  * A message sent from the driver to register with the MesosExternalShuffleService.
0031  */
0032 public class RegisterDriver extends BlockTransferMessage {
0033   private final String appId;
0034   private final long heartbeatTimeoutMs;
0035 
0036   public RegisterDriver(String appId, long heartbeatTimeoutMs) {
0037     this.appId = appId;
0038     this.heartbeatTimeoutMs = heartbeatTimeoutMs;
0039   }
0040 
0041   public String getAppId() { return appId; }
0042 
0043   public long getHeartbeatTimeoutMs() { return heartbeatTimeoutMs; }
0044 
0045   @Override
0046   protected Type type() { return Type.REGISTER_DRIVER; }
0047 
0048   @Override
0049   public int encodedLength() {
0050     return Encoders.Strings.encodedLength(appId) + Long.SIZE / Byte.SIZE;
0051   }
0052 
0053   @Override
0054   public void encode(ByteBuf buf) {
0055     Encoders.Strings.encode(buf, appId);
0056     buf.writeLong(heartbeatTimeoutMs);
0057   }
0058 
0059   @Override
0060   public int hashCode() {
0061     return Objects.hashCode(appId, heartbeatTimeoutMs);
0062   }
0063 
0064   @Override
0065   public boolean equals(Object o) {
0066     if (!(o instanceof RegisterDriver)) {
0067       return false;
0068     }
0069     return Objects.equal(appId, ((RegisterDriver) o).appId);
0070   }
0071 
0072   public static RegisterDriver decode(ByteBuf buf) {
0073     String appId = Encoders.Strings.decode(buf);
0074     long heartbeatTimeout = buf.readLong();
0075     return new RegisterDriver(appId, heartbeatTimeout);
0076   }
0077 }