blob: 6c36e83a21e0abdc0e6adfda74870aa6f05a2895 (
plain) (
blame)
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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.config;
import com.google.inject.Inject;
import com.yahoo.container.ConfigHack;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.container.jdisc.ThreadedHttpRequestHandler;
import com.yahoo.container.logging.AccessLog;
import com.yahoo.text.Utf8;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.concurrent.Executor;
/**
* Handler of statistics http requests. Temporary hack as a step towards a more
* general network interface.
*
* @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
* @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
*/
public class StatisticsRequestHandler extends ThreadedHttpRequestHandler {
@Inject
public StatisticsRequestHandler(Executor executor) {
super(executor);
}
@Override
public HttpResponse handle(HttpRequest request) {
return new StatisticsResponse(ConfigHack.instance.getStatisticsHandler().respond(request));
}
protected static class StatisticsResponse extends HttpResponse {
private final StringBuilder string;
private StatisticsResponse(StringBuilder stringBuilder) {
super(com.yahoo.jdisc.http.HttpResponse.Status.OK);
this.string = stringBuilder;
}
@Override
public void render(OutputStream stream) throws IOException {
Writer osWriter = new OutputStreamWriter(stream, Utf8.getCharset());
osWriter.write(string.toString());
osWriter.flush();
osWriter.close();
}
}
}
|