@Test public void testReportSnappy() { LookoutConfig config = new LookoutConfig(); AddressService addressService = new DefaultAddressService(); Registry registry = new DefaultRegistry(); HttpObserver observer = new HttpObserver(config, addressService, registry, new TestHttpRequestProcessor()); observer.reportSnappy2Agent(new Address("localhost"), "hellohello", null); Assert.assertEquals(12, httpPost.getEntity().getContentLength()); }
void reportSnappy2Agent(Address agentAddress, String msg, Map<String, String> metadata) { HttpPost httpPost = new HttpPost(buildRealAgentServerURL(agentAddress)); httpPost.setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_OCTET_STREAM); httpPost.setHeader(HttpHeaders.CONTENT_ENCODING, SNAPPY); byte[] compressed = new byte[0]; try { compressed = Snappy.compress(msg, Charset.forName(UTF_8)); } catch (IOException e) { logger.info(">>WARNING: snappy compress report msg err:{}", e.getMessage()); return; } httpPost.setEntity(new ByteArrayEntity(compressed)); sendHttpDataSilently(httpPost, metadata); }
HttpObserver implements MetricObserver<LookoutMeasurement> { void reportSnappy2Agent(Address agentAddress, String msg, Map<String, String> metadata) { HttpPost httpPost = new HttpPost(buildRealAgentServerURL(agentAddress)); httpPost.setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_OCTET_STREAM); httpPost.setHeader(HttpHeaders.CONTENT_ENCODING, SNAPPY); byte[] compressed = new byte[0]; try { compressed = Snappy.compress(msg, Charset.forName(UTF_8)); } catch (IOException e) { logger.info(">>WARNING: snappy compress report msg err:{}", e.getMessage()); return; } httpPost.setEntity(new ByteArrayEntity(compressed)); sendHttpDataSilently(httpPost, metadata); } }
HttpObserver implements MetricObserver<LookoutMeasurement> { void reportSnappy2Agent(Address agentAddress, String msg, Map<String, String> metadata) { HttpPost httpPost = new HttpPost(buildRealAgentServerURL(agentAddress)); httpPost.setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_OCTET_STREAM); httpPost.setHeader(HttpHeaders.CONTENT_ENCODING, SNAPPY); byte[] compressed = new byte[0]; try { compressed = Snappy.compress(msg, Charset.forName(UTF_8)); } catch (IOException e) { logger.info(">>WARNING: snappy compress report msg err:{}", e.getMessage()); return; } httpPost.setEntity(new ByteArrayEntity(compressed)); sendHttpDataSilently(httpPost, metadata); } HttpObserver(LookoutConfig lookoutConfig, AddressService addrService);  HttpObserver(LookoutConfig lookoutConfig, AddressService addrService, Registry registry);  HttpObserver(LookoutConfig lookoutConfig, AddressService addrService, Registry registry,
                        HttpRequestProcessor requestProcessor); }
HttpObserver implements MetricObserver<LookoutMeasurement> { void reportSnappy2Agent(Address agentAddress, String msg, Map<String, String> metadata) { HttpPost httpPost = new HttpPost(buildRealAgentServerURL(agentAddress)); httpPost.setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_OCTET_STREAM); httpPost.setHeader(HttpHeaders.CONTENT_ENCODING, SNAPPY); byte[] compressed = new byte[0]; try { compressed = Snappy.compress(msg, Charset.forName(UTF_8)); } catch (IOException e) { logger.info(">>WARNING: snappy compress report msg err:{}", e.getMessage()); return; } httpPost.setEntity(new ByteArrayEntity(compressed)); sendHttpDataSilently(httpPost, metadata); } HttpObserver(LookoutConfig lookoutConfig, AddressService addrService);  HttpObserver(LookoutConfig lookoutConfig, AddressService addrService, Registry registry);  HttpObserver(LookoutConfig lookoutConfig, AddressService addrService, Registry registry,
                        HttpRequestProcessor requestProcessor); @Override boolean isEnable(); @Override void update(List<LookoutMeasurement> measures, Map<String, String> metadata); List<List<LookoutMeasurement>> getBatches(List<LookoutMeasurement> ms, int batchSize); }
HttpObserver implements MetricObserver<LookoutMeasurement> { void reportSnappy2Agent(Address agentAddress, String msg, Map<String, String> metadata) { HttpPost httpPost = new HttpPost(buildRealAgentServerURL(agentAddress)); httpPost.setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_OCTET_STREAM); httpPost.setHeader(HttpHeaders.CONTENT_ENCODING, SNAPPY); byte[] compressed = new byte[0]; try { compressed = Snappy.compress(msg, Charset.forName(UTF_8)); } catch (IOException e) { logger.info(">>WARNING: snappy compress report msg err:{}", e.getMessage()); return; } httpPost.setEntity(new ByteArrayEntity(compressed)); sendHttpDataSilently(httpPost, metadata); } HttpObserver(LookoutConfig lookoutConfig, AddressService addrService);  HttpObserver(LookoutConfig lookoutConfig, AddressService addrService, Registry registry);  HttpObserver(LookoutConfig lookoutConfig, AddressService addrService, Registry registry,
                        HttpRequestProcessor requestProcessor); @Override boolean isEnable(); @Override void update(List<LookoutMeasurement> measures, Map<String, String> metadata); List<List<LookoutMeasurement>> getBatches(List<LookoutMeasurement> ms, int batchSize); static final String UTF_8; static final String APPLICATION_OCTET_STREAM; static final String SNAPPY; }