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.netty5.handler.codec.http2;
17  
18  import io.netty5.util.internal.StringUtil;
19  import io.netty5.util.internal.UnstableApi;
20  
21  /**
22   * The default {@link Http2PingFrame} implementation.
23   */
24  @UnstableApi
25  public class DefaultHttp2PingFrame implements Http2PingFrame {
26  
27      private final long content;
28      private final boolean ack;
29  
30      public DefaultHttp2PingFrame(long content) {
31          this(content, false);
32      }
33  
34      public DefaultHttp2PingFrame(long content, boolean ack) {
35          this.content = content;
36          this.ack = ack;
37      }
38  
39      @Override
40      public boolean ack() {
41          return ack;
42      }
43  
44      @Override
45      public String name() {
46          return "PING";
47      }
48  
49      @Override
50      public long content() {
51          return content;
52      }
53  
54      @Override
55      public boolean equals(Object o) {
56          if (!(o instanceof Http2PingFrame)) {
57              return false;
58          }
59          Http2PingFrame other = (Http2PingFrame) o;
60          return ack == other.ack() &&  content == other.content();
61      }
62  
63      @Override
64      public int hashCode() {
65          int hash = super.hashCode();
66          hash = hash * 31 + (ack ? 1 : 0);
67          return hash;
68      }
69  
70      @Override
71      public String toString() {
72          return StringUtil.simpleClassName(this) + "(content=" + content + ", ack=" + ack + ')';
73      }
74  }