View Javadoc
1   /*
2    * Copyright 2020 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.handler.codec.http2;
17  
18  import io.netty.util.internal.UnstableApi;
19  
20  /**
21   * Default implementation of {@linkplain Http2PriorityFrame}
22   */
23  @UnstableApi
24  public final class DefaultHttp2PriorityFrame extends AbstractHttp2StreamFrame implements Http2PriorityFrame {
25  
26      private final int streamDependency;
27      private final short weight;
28      private final boolean exclusive;
29  
30      public DefaultHttp2PriorityFrame(int streamDependency, short weight, boolean exclusive) {
31          this.streamDependency = streamDependency;
32          this.weight = weight;
33          this.exclusive = exclusive;
34      }
35  
36      @Override
37      public int streamDependency() {
38          return streamDependency;
39      }
40  
41      @Override
42      public short weight() {
43          return weight;
44      }
45  
46      @Override
47      public boolean exclusive() {
48          return exclusive;
49      }
50  
51      @Override
52      public DefaultHttp2PriorityFrame stream(Http2FrameStream stream) {
53          super.stream(stream);
54          return this;
55      }
56  
57      @Override
58      public String name() {
59          return "PRIORITY_FRAME";
60      }
61  
62      @Override
63      public boolean equals(Object o) {
64          if (!(o instanceof DefaultHttp2PriorityFrame)) {
65              return false;
66          }
67          DefaultHttp2PriorityFrame other = (DefaultHttp2PriorityFrame) o;
68          boolean same = super.equals(other);
69          return same && streamDependency == other.streamDependency
70                  && weight == other.weight && exclusive == other.exclusive;
71      }
72  
73      @Override
74      public int hashCode() {
75          int hash = super.hashCode();
76          hash = hash * 31 + streamDependency;
77          hash = hash * 31 + weight;
78          hash = hash * 31 + (exclusive ? 1 : 0);
79          return hash;
80      }
81  
82      @Override
83      public String toString() {
84          return "DefaultHttp2PriorityFrame(" +
85                  "stream=" + stream() +
86                  ", streamDependency=" + streamDependency +
87                  ", weight=" + weight +
88                  ", exclusive=" + exclusive +
89                  ')';
90      }
91  }