-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
StatisticsGatheringHttpClientStream.java
217 lines (184 loc) · 5.22 KB
/
StatisticsGatheringHttpClientStream.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
* Copyright (c) 2011-2023 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http:https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*/
package io.vertx.core.http.impl;
import io.netty.buffer.ByteBuf;
import io.vertx.codegen.annotations.Fluent;
import io.vertx.codegen.annotations.Nullable;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.MultiMap;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpFrame;
import io.vertx.core.http.HttpVersion;
import io.vertx.core.http.StreamPriority;
import io.vertx.core.impl.ContextInternal;
import io.vertx.core.net.endpoint.EndpointInteraction;
import io.vertx.core.streams.WriteStream;
/**
* Decorates an {@link HttpClientStream} that gathers usage statistics.
*
* @author <a href="mailto:[email protected]">Julien Viet</a>
*/
class StatisticsGatheringHttpClientStream implements HttpClientStream {
private final HttpClientStream delegate;
private final EndpointInteraction endpointRequest;
StatisticsGatheringHttpClientStream(HttpClientStream delegate, EndpointInteraction endpointRequest) {
this.delegate = delegate;
this.endpointRequest = endpointRequest;
}
@Override
public int id() {
return delegate.id();
}
@Override
public Object metric() {
return delegate.metric();
}
@Override
public Object trace() {
return delegate.trace();
}
@Override
public HttpVersion version() {
return delegate.version();
}
@Override
public HttpClientConnectionInternal connection() {
return delegate.connection();
}
@Override
public ContextInternal getContext() {
return delegate.getContext();
}
@Override
public Future<Void> writeHead(HttpRequestHead request, boolean chunked, ByteBuf buf, boolean end, StreamPriority priority, boolean connect) {
endpointRequest.reportRequestBegin();
if (end) {
endpointRequest.reportRequestEnd();
}
return delegate.writeHead(request, chunked, buf, end, priority, connect);
}
@Override
public Future<Void> writeBuffer(ByteBuf buf, boolean end) {
if (end) {
endpointRequest.reportRequestEnd();
}
return delegate.writeBuffer(buf, end);
}
@Override
public Future<Void> writeFrame(int type, int flags, ByteBuf payload) {
return delegate.writeFrame(type, flags, payload);
}
@Override
public void continueHandler(Handler<Void> handler) {
delegate.continueHandler(handler);
}
@Override
public void earlyHintsHandler(Handler<MultiMap> handler) {
delegate.earlyHintsHandler(handler);
}
@Override
public void pushHandler(Handler<HttpClientPush> handler) {
delegate.pushHandler(handler);
}
@Override
public void unknownFrameHandler(Handler<HttpFrame> handler) {
delegate.unknownFrameHandler(handler);
}
@Override
public void headHandler(Handler<HttpResponseHead> handler) {
if (handler != null) {
delegate.headHandler(multimap -> {
endpointRequest.reportResponseBegin();
handler.handle(multimap);
});
} else {
delegate.headHandler(null);
}
}
@Override
public void chunkHandler(Handler<Buffer> handler) {
delegate.chunkHandler(handler);
}
@Override
public void endHandler(Handler<MultiMap> handler) {
if (handler != null) {
delegate.endHandler(multimap -> {
endpointRequest.reportResponseEnd();
handler.handle(multimap);
});
} else {
delegate.endHandler(null);
}
}
@Override
public void priorityHandler(Handler<StreamPriority> handler) {
delegate.priorityHandler(handler);
}
@Override
public void closeHandler(Handler<Void> handler) {
delegate.closeHandler(handler);
}
@Override
public void doSetWriteQueueMaxSize(int size) {
delegate.doSetWriteQueueMaxSize(size);
}
@Override
public boolean isNotWritable() {
return delegate.isNotWritable();
}
@Override
public void doPause() {
delegate.doPause();
}
@Override
public void doFetch(long amount) {
delegate.doFetch(amount);
}
@Override
public void reset(Throwable cause) {
delegate.reset(cause);
}
@Override
public StreamPriority priority() {
return delegate.priority();
}
@Override
public void updatePriority(StreamPriority streamPriority) {
delegate.updatePriority(streamPriority);
}
@Override
public WriteStream<Buffer> exceptionHandler(@Nullable Handler<Throwable> handler) {
if (handler != null) {
delegate.exceptionHandler(err -> {
endpointRequest.reportFailure(err);
handler.handle(err);
});
} else {
delegate.exceptionHandler(null);
}
return this;
}
@Override
@Fluent
public WriteStream<Buffer> setWriteQueueMaxSize(int maxSize) {
return delegate.setWriteQueueMaxSize(maxSize);
}
@Override
public boolean writeQueueFull() {
return delegate.writeQueueFull();
}
@Override
@Fluent
public WriteStream<Buffer> drainHandler(@Nullable Handler<Void> handler) {
return delegate.drainHandler(handler);
}
}