1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.handler.codec.http2;
17
18 import io.netty5.buffer.api.Buffer;
19 import io.netty5.buffer.api.BufferHolder;
20 import io.netty5.util.Send;
21 import io.netty5.util.internal.StringUtil;
22 import io.netty5.util.internal.UnstableApi;
23
24 import static io.netty5.buffer.api.DefaultBufferAllocators.onHeapAllocator;
25 import static io.netty5.util.internal.ObjectUtil.checkPositiveOrZero;
26
27
28
29
30 @UnstableApi
31 public final class DefaultHttp2GoAwayFrame extends BufferHolder<Http2GoAwayFrame> implements Http2GoAwayFrame {
32 private final long errorCode;
33 private final int lastStreamId;
34 private int extraStreamIds;
35
36
37
38
39
40
41 public DefaultHttp2GoAwayFrame(Http2Error error) {
42 this(error.code());
43 }
44
45
46
47
48
49
50 public DefaultHttp2GoAwayFrame(long errorCode) {
51 this(-1, errorCode, onHeapAllocator().allocate(0));
52 }
53
54
55
56
57
58
59
60 public DefaultHttp2GoAwayFrame(Http2Error error, Send<Buffer> content) {
61 this(error.code(), content);
62 }
63
64
65
66
67
68
69
70 public DefaultHttp2GoAwayFrame(long errorCode, Send<Buffer> content) {
71 this(-1, errorCode, content.receive());
72 }
73
74
75
76
77
78
79
80 DefaultHttp2GoAwayFrame(int lastStreamId, long errorCode, Send<Buffer> content) {
81 this(lastStreamId, errorCode, content.receive());
82 }
83
84 private DefaultHttp2GoAwayFrame(int lastStreamId, long errorCode, Buffer content) {
85 super(content);
86 this.errorCode = errorCode;
87 this.lastStreamId = lastStreamId;
88 }
89
90 @Override
91 public String name() {
92 return "GOAWAY";
93 }
94
95 @Override
96 public long errorCode() {
97 return errorCode;
98 }
99
100 @Override
101 public int extraStreamIds() {
102 return extraStreamIds;
103 }
104
105 @Override
106 public Http2GoAwayFrame setExtraStreamIds(int extraStreamIds) {
107 checkPositiveOrZero(extraStreamIds, "extraStreamIds");
108 this.extraStreamIds = extraStreamIds;
109 return this;
110 }
111
112 @Override
113 public int lastStreamId() {
114 return lastStreamId;
115 }
116
117 @Override
118 public Buffer content() {
119 return getBuffer();
120 }
121
122 @Override
123 public Http2GoAwayFrame copy() {
124 return new DefaultHttp2GoAwayFrame(lastStreamId, errorCode, content().copy());
125 }
126
127 @Override
128 protected Http2GoAwayFrame receive(Buffer buf) {
129 return new DefaultHttp2GoAwayFrame(lastStreamId, errorCode, buf);
130 }
131
132 @Override
133 public Http2GoAwayFrame touch(Object hint) {
134 super.touch(hint);
135 return this;
136 }
137
138 @Override
139 public boolean equals(Object o) {
140 if (!(o instanceof DefaultHttp2GoAwayFrame)) {
141 return false;
142 }
143 DefaultHttp2GoAwayFrame other = (DefaultHttp2GoAwayFrame) o;
144 return errorCode == other.errorCode && extraStreamIds == other.extraStreamIds && super.equals(other);
145 }
146
147 @Override
148 public int hashCode() {
149 int hash = super.hashCode();
150 hash = hash * 31 + (int) (errorCode ^ errorCode >>> 32);
151 hash = hash * 31 + extraStreamIds;
152 return hash;
153 }
154
155 @Override
156 public String toString() {
157 return StringUtil.simpleClassName(this) + "(errorCode=" + errorCode + ", content=" + content()
158 + ", extraStreamIds=" + extraStreamIds + ", lastStreamId=" + lastStreamId + ')';
159 }
160 }