View Javadoc
1   /*
2    * Copyright 2016 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.StringUtil;
19  
20  import static io.netty.util.internal.ObjectUtil.checkNotNull;
21  
22  /**
23   * The default {@link Http2ResetFrame} implementation.
24   */
25  public final class DefaultHttp2ResetFrame extends AbstractHttp2StreamFrame implements Http2ResetFrame {
26  
27      private final long errorCode;
28  
29      /**
30       * Construct a reset message.
31       *
32       * @param error the non-{@code null} reason for reset
33       */
34      public DefaultHttp2ResetFrame(Http2Error error) {
35          errorCode = checkNotNull(error, "error").code();
36      }
37  
38      /**
39       * Construct a reset message.
40       *
41       * @param errorCode the reason for reset
42       */
43      public DefaultHttp2ResetFrame(long errorCode) {
44          this.errorCode = errorCode;
45      }
46  
47      @Override
48      public DefaultHttp2ResetFrame stream(Http2FrameStream stream) {
49          super.stream(stream);
50          return this;
51      }
52  
53      @Override
54      public String name() {
55          return "RST_STREAM";
56      }
57  
58      @Override
59      public long errorCode() {
60          return errorCode;
61      }
62  
63      @Override
64      public String toString() {
65          return StringUtil.simpleClassName(this) + "(stream=" + stream() + ", errorCode=" + errorCode + ')';
66      }
67  
68      @Override
69      public boolean equals(Object o) {
70          if (!(o instanceof DefaultHttp2ResetFrame)) {
71              return false;
72          }
73          DefaultHttp2ResetFrame other = (DefaultHttp2ResetFrame) o;
74          return super.equals(o) && errorCode == other.errorCode;
75      }
76  
77      @Override
78      public int hashCode() {
79          int hash = super.hashCode();
80          hash = hash * 31 + (int) (errorCode ^ errorCode >>> 32);
81          return hash;
82      }
83  }