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.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 /**
0027  * Request to stream data from the remote end.
0028  * <p>
0029  * The stream ID is an arbitrary string that needs to be negotiated between the two endpoints before
0030  * the data can be streamed.
0031  */
0032 public final class StreamRequest extends AbstractMessage implements RequestMessage {
0033    public final String streamId;
0034 
0035    public StreamRequest(String streamId) {
0036      this.streamId = streamId;
0037    }
0038 
0039   @Override
0040   public Message.Type type() { return Type.StreamRequest; }
0041 
0042   @Override
0043   public int encodedLength() {
0044     return Encoders.Strings.encodedLength(streamId);
0045   }
0046 
0047   @Override
0048   public void encode(ByteBuf buf) {
0049     Encoders.Strings.encode(buf, streamId);
0050   }
0051 
0052   public static StreamRequest decode(ByteBuf buf) {
0053     String streamId = Encoders.Strings.decode(buf);
0054     return new StreamRequest(streamId);
0055   }
0056 
0057   @Override
0058   public int hashCode() {
0059     return Objects.hashCode(streamId);
0060   }
0061 
0062   @Override
0063   public boolean equals(Object other) {
0064     if (other instanceof StreamRequest) {
0065       StreamRequest o = (StreamRequest) other;
0066       return streamId.equals(o.streamId);
0067     }
0068     return false;
0069   }
0070 
0071   @Override
0072   public String toString() {
0073     return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
0074       .append("streamId", streamId)
0075       .toString();
0076   }
0077 
0078 }