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