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
25
26
27
28 public final class DefaultHttp2GoAwayFrame extends DefaultByteBufHolder implements Http2GoAwayFrame {
29
30 private final long errorCode;
31 private final int lastStreamId;
32 private int extraStreamIds;
33
34
35
36
37
38
39 public DefaultHttp2GoAwayFrame(Http2Error error) {
40 this(error.code());
41 }
42
43
44
45
46
47
48 public DefaultHttp2GoAwayFrame(long errorCode) {
49 this(errorCode, Unpooled.EMPTY_BUFFER);
50 }
51
52
53
54
55
56
57
58 public DefaultHttp2GoAwayFrame(Http2Error error, ByteBuf content) {
59 this(error.code(), content);
60 }
61
62
63
64
65
66
67
68 public DefaultHttp2GoAwayFrame(long errorCode, ByteBuf content) {
69 this(-1, errorCode, content);
70 }
71
72
73
74
75
76
77
78 DefaultHttp2GoAwayFrame(int lastStreamId, long errorCode, ByteBuf content) {
79 super(content);
80 this.errorCode = errorCode;
81 this.lastStreamId = lastStreamId;
82 }
83
84 @Override
85 public String name() {
86 return "GOAWAY";
87 }
88
89 @Override
90 public long errorCode() {
91 return errorCode;
92 }
93
94 @Override
95 public int extraStreamIds() {
96 return extraStreamIds;
97 }
98
99 @Override
100 public Http2GoAwayFrame setExtraStreamIds(int extraStreamIds) {
101 checkPositiveOrZero(extraStreamIds, "extraStreamIds");
102 this.extraStreamIds = extraStreamIds;
103 return this;
104 }
105
106 @Override
107 public int lastStreamId() {
108 return lastStreamId;
109 }
110
111 @Override
112 public Http2GoAwayFrame copy() {
113 return new DefaultHttp2GoAwayFrame(lastStreamId, errorCode, content().copy());
114 }
115
116 @Override
117 public Http2GoAwayFrame duplicate() {
118 return (Http2GoAwayFrame) super.duplicate();
119 }
120
121 @Override
122 public Http2GoAwayFrame retainedDuplicate() {
123 return (Http2GoAwayFrame) super.retainedDuplicate();
124 }
125
126 @Override
127 public Http2GoAwayFrame replace(ByteBuf content) {
128 return new DefaultHttp2GoAwayFrame(errorCode, content).setExtraStreamIds(extraStreamIds);
129 }
130
131 @Override
132 public Http2GoAwayFrame retain() {
133 super.retain();
134 return this;
135 }
136
137 @Override
138 public Http2GoAwayFrame retain(int increment) {
139 super.retain(increment);
140 return this;
141 }
142
143 @Override
144 public Http2GoAwayFrame touch() {
145 super.touch();
146 return this;
147 }
148
149 @Override
150 public Http2GoAwayFrame touch(Object hint) {
151 super.touch(hint);
152 return this;
153 }
154
155 @Override
156 public boolean equals(Object o) {
157 if (!(o instanceof DefaultHttp2GoAwayFrame)) {
158 return false;
159 }
160 DefaultHttp2GoAwayFrame other = (DefaultHttp2GoAwayFrame) o;
161 return errorCode == other.errorCode && extraStreamIds == other.extraStreamIds && super.equals(other);
162 }
163
164 @Override
165 public int hashCode() {
166 int hash = super.hashCode();
167 hash = hash * 31 + (int) (errorCode ^ errorCode >>> 32);
168 hash = hash * 31 + extraStreamIds;
169 return hash;
170 }
171
172 @Override
173 public String toString() {
174 return StringUtil.simpleClassName(this) + "(errorCode=" + errorCode + ", content=" + content()
175 + ", extraStreamIds=" + extraStreamIds + ", lastStreamId=" + lastStreamId + ')';
176 }
177 }