The class responsible for writing histograms from Telnet calls or HTTP requests. @since 2.4
| 41 | * @since 2.4 |
| 42 | */ |
| 43 | public class HistogramDataPointRpc extends PutDataPointRpc |
| 44 | implements TelnetRpc, HttpRpc { |
| 45 | |
| 46 | /** Type ref for the histo pojo. */ |
| 47 | private static final TypeReference<ArrayList<HistogramPojo>> TYPE_REF = |
| 48 | new TypeReference<ArrayList<HistogramPojo>>() {}; |
| 49 | |
| 50 | /** Whether or not histograms are enabled. */ |
| 51 | private final boolean enabled; |
| 52 | |
| 53 | /** |
| 54 | * Default ctor. Checks the "tsd.core.histograms.config" value to see if |
| 55 | * histograms are enabled. If they are not, then exceptions are returned. |
| 56 | * @param config A non-null config to pull data from. |
| 57 | */ |
| 58 | public HistogramDataPointRpc(final Config config) { |
| 59 | super(config); |
| 60 | // drats, since we can't look at the manager we'll look at the settings. |
| 61 | final String histo_config = config.getString("tsd.core.histograms.config"); |
| 62 | if (Strings.isNullOrEmpty(histo_config)) { |
| 63 | enabled = false; |
| 64 | } else { |
| 65 | enabled = true; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public void execute(final TSDB tsdb, final HttpQuery query) throws IOException { |
| 71 | http_requests.incrementAndGet(); |
| 72 | |
| 73 | if (!enabled) { |
| 74 | throw new BadRequestException(HttpResponseStatus.SERVICE_UNAVAILABLE, |
| 75 | "Histogram storage has not been enabled. Check the " |
| 76 | + "'tsd.core.histograms.config' configuration."); |
| 77 | } |
| 78 | |
| 79 | // only accept POST |
| 80 | if (query.method() != HttpMethod.POST) { |
| 81 | throw new BadRequestException(HttpResponseStatus.METHOD_NOT_ALLOWED, |
| 82 | "Method not allowed", "The HTTP method [" + query.method().getName() + |
| 83 | "] is not permitted for this endpoint"); |
| 84 | } |
| 85 | |
| 86 | final List<HistogramPojo> dps = query.serializer() |
| 87 | .parsePutV1(HistogramPojo.class, TYPE_REF); |
| 88 | processDataPoint(tsdb, query, dps); |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | protected Deferred<Object> importDataPoint(final TSDB tsdb, |
| 93 | final String[] words) { |
| 94 | if (!enabled) { |
| 95 | throw new IllegalArgumentException( |
| 96 | "Histogram storage has not been enabled. Check the " |
| 97 | + "'tsd.core.histograms.config' configuration."); |
| 98 | } |
| 99 | |
| 100 | words[0] = null; // Ditch the "histogram". |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…