Binds together an HTTP request and the channel on which it was received. It makes it easier to provide a few utility methods to respond to the requests.
| 58 | * requests. |
| 59 | */ |
| 60 | final class HttpQuery extends AbstractHttpQuery { |
| 61 | |
| 62 | private static final Logger LOG = LoggerFactory.getLogger(HttpQuery.class); |
| 63 | |
| 64 | private static final String HTML_CONTENT_TYPE = "text/html; charset=UTF-8"; |
| 65 | |
| 66 | /** The maximum implemented API version, set when the user doesn't */ |
| 67 | private static final int MAX_API_VERSION = 1; |
| 68 | |
| 69 | /** |
| 70 | * Keep track of the latency of HTTP requests. |
| 71 | */ |
| 72 | private static final Histogram httplatency = |
| 73 | new Histogram(16000, (short) 2, 100); |
| 74 | |
| 75 | /** Maps Content-Type to a serializer */ |
| 76 | private static HashMap<String, Constructor<? extends HttpSerializer>> |
| 77 | serializer_map_content_type = null; |
| 78 | |
| 79 | /** Maps query string names to a serializer */ |
| 80 | private static HashMap<String, Constructor<? extends HttpSerializer>> |
| 81 | serializer_map_query_string = null; |
| 82 | |
| 83 | /** Caches serializer implementation information for user access */ |
| 84 | private static ArrayList<HashMap<String, Object>> serializer_status = null; |
| 85 | |
| 86 | /** API version parsed from the incoming request */ |
| 87 | private int api_version = 0; |
| 88 | |
| 89 | /** The serializer to use for parsing input and responding */ |
| 90 | private HttpSerializer serializer = null; |
| 91 | |
| 92 | /** Whether or not to show stack traces in the output */ |
| 93 | private final boolean show_stack_trace; |
| 94 | |
| 95 | /** |
| 96 | * Constructor. |
| 97 | * @param request The request in this HTTP query. |
| 98 | * @param chan The channel on which the request was received. |
| 99 | */ |
| 100 | public HttpQuery(final TSDB tsdb, final HttpRequest request, final Channel chan) { |
| 101 | super(tsdb, request, chan); |
| 102 | this.show_stack_trace = |
| 103 | tsdb.getConfig().getBoolean("tsd.http.show_stack_trace"); |
| 104 | this.serializer = new HttpJsonSerializer(this); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Collects the stats and metrics tracked by this instance. |
| 109 | * @param collector The collector to use. |
| 110 | */ |
| 111 | public static void collectStats(final StatsCollector collector) { |
| 112 | collector.record("http.latency", httplatency, "type=all"); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Returns the version for an API request. If the request was for a deprecated |
| 117 | * API call (such as /q, /suggest, /logs) this value will be 0. If the request |
nothing calls this directly
no test coverage detected
searching dependent graphs…