static void flushToServer ( long now ) { LOG . debug ( "Flush to BeeInstant Server" ) ; Collection < String > readyToSubmit = new ArrayList <> ( ) ; metricsQueue . drainTo ( readyToSubmit ) ; StringBuilder builder = new StringBuilder ( ) ; readyToSubmit . forEach ( string -> { builder . append ( string ) ; builder . append ( "\n" ) ; } ) ; if ( ! readyToSubmit . isEmpty ( ) && beeInstantHost != null ) { try { final String body = builder . toString ( ) ; StringEntity entity = new StringEntity ( body ) ; entity . setContentType ( "text/plain" ) ; String uri = "/PutMetric" ; final String signature = sign ( entity ) ; if ( ! signature . isEmpty ( ) ) { uri += "?signature=" + URLEncoder . encode ( signature , "UTF-8" ) ; uri += "&publicKey=" + URLEncoder . encode ( publicKey , "UTF-8" ) ; uri += "&timestamp=" + now ; HttpPost putMetricCommand = new HttpPost ( uri ) ; try { putMetricCommand . setEntity ( entity ) ; HttpResponse response = httpClient . execute ( beeInstantHost , putMetricCommand ) ; LOG . info ( "Response: " + response . getStatusLine ( ) . getStatusCode ( ) ) ; } finally { putMetricCommand . releaseConnection ( ) ; } } } catch ( Throwable e ) { LOG . error ( "Fail to emit metrics" , e ) ; } } }
Flush metrics to BeeInstant Server