1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.http2;
17
18 import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
19
20 import io.netty.buffer.ByteBuf;
21 import io.netty.buffer.DefaultByteBufHolder;
22 import io.netty.buffer.Unpooled;
23 import io.netty.util.internal.StringUtil;
24 import io.netty.util.internal.UnstableApi;
25
26
27
28
29 @UnstableApi
30 public final class DefaultHttp2GoAwayFrame extends DefaultByteBufHolder implements Http2GoAwayFrame {
31
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(errorCode, Unpooled.EMPTY_BUFFER);
52 }
53
54
55
56
57
58
59
60 public DefaultHttp2GoAwayFrame(Http2Error error, ByteBuf content) {
61 this(error.code(), content);
62 }
63
64
65
66
67
68
69
70 public DefaultHttp2GoAwayFrame(long errorCode, ByteBuf content) {
71 this(-1, errorCode, content);
72 }
73
74
75
76
77
78
79
80 DefaultHttp2GoAwayFrame(int lastStreamId, long errorCode, ByteBuf content) {
81 super(content);
82 this.errorCode = errorCode;
83 this.lastStreamId = lastStreamId;
84 }
85
86 @Override
87 public String name() {
88 return "GOAWAY";
89 }
90
91 @Override
92 public long errorCode() {
93 return errorCode;
94 }
95
96 @Override
97 public int extraStreamIds() {
98 return extraStreamIds;
99 }
100
101 @Override
102 public Http2GoAwayFrame setExtraStreamIds(int extraStreamIds) {
103 checkPositiveOrZero(extraStreamIds, "extraStreamIds");
104 this.extraStreamIds = extraStreamIds;
105 return this;
106 }
107
108 @Override
109 public int lastStreamId() {
110 return lastStreamId;
111 }
112
113 @Override
114 public Http2GoAwayFrame copy() {
115 return new DefaultHttp2GoAwayFrame(lastStreamId, errorCode, content().copy());
116 }
117
118 @Override
119 public Http2GoAwayFrame duplicate() {
120 return (Http2GoAwayFrame) super.duplicate();
121 }
122
123 @Override
124 public Http2GoAwayFrame retainedDuplicate() {
125 return (Http2GoAwayFrame) super.retainedDuplicate();
126 }
127
128 @Override
129 public Http2GoAwayFrame replace(ByteBuf content) {
130 return new DefaultHttp2GoAwayFrame(errorCode, content).setExtraStreamIds(extraStreamIds);
131 }
132
133 @Override
134 public Http2GoAwayFrame retain() {
135 super.retain();
136 return this;
137 }
138
139 @Override
140 public Http2GoAwayFrame retain(int increment) {
141 super.retain(increment);
142 return this;
143 }
144
145 @Override
146 public Http2GoAwayFrame touch() {
147 super.touch();
148 return this;
149 }
150
151 @Override
152 public Http2GoAwayFrame touch(Object hint) {
153 super.touch(hint);
154 return this;
155 }
156
157 @Override
158 public boolean equals(Object o) {
159 if (!(o instanceof DefaultHttp2GoAwayFrame)) {
160 return false;
161 }
162 DefaultHttp2GoAwayFrame other = (DefaultHttp2GoAwayFrame) o;
163 return errorCode == other.errorCode && extraStreamIds == other.extraStreamIds && super.equals(other);
164 }
165
166 @Override
167 public int hashCode() {
168 int hash = super.hashCode();
169 hash = hash * 31 + (int) (errorCode ^ errorCode >>> 32);
170 hash = hash * 31 + extraStreamIds;
171 return hash;
172 }
173
174 @Override
175 public String toString() {
176 return StringUtil.simpleClassName(this) + "(errorCode=" + errorCode + ", content=" + content()
177 + ", extraStreamIds=" + extraStreamIds + ", lastStreamId=" + lastStreamId + ')';
178 }
179 }