src/com/newrelic/metrics/publish/binding/Request.java
/**
     * Deliver the {@code Request} to the New Relic metrics API.
     */
Deliver the  Request to the New Relic metrics API.
Deliver the Request to the New Relic metrics API .
public void deliver() {
        if (metrics.isEmpty()) {
            logger.debug("No metrics were reported for this poll cycle");
        } else {
            HttpURLConnection connection = null;
            try {
                Map<String, Object> data = serialize();
                String json = JSONObject.toJSONString(data);
                logger.debug("Sending JSON: ", json);
                connection = context.createUrlConnectionForOutput();
                OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
                try {
                    out.write(json);
                } finally {
                    out.close();
                }
                processResponse(connection);
            }
            catch (Exception ex) {
                logger.error(ex, "An error occurred communicating with the New Relic service");
                if (connection != null) {
                    try {
                        logger.info("Response: ", connection.getResponseCode(), " : ", connection.getResponseMessage());
                     } catch (IOException e) {
                        logger.debug(ex, ex.getMessage());
                    }
                }
            } finally {
                if (connection != null) {
                    connection.disconnect();
                }
            }
        }
    }
public void deliver ( ) { if ( metrics . isEmpty ( ) ) { logger . debug ( "No metrics were reported for this poll cycle" ) ; } else { HttpURLConnection connection = null ; try { Map < String , Object > data = serialize ( ) ; String json = JSONObject . toJSONString ( data ) ; logger . debug ( "Sending JSON: " , json ) ; connection = context . createUrlConnectionForOutput ( ) ; OutputStreamWriter out = new OutputStreamWriter ( connection . getOutputStream ( ) ) ; try { out . write ( json ) ; } finally { out . close ( ) ; } processResponse ( connection ) ; } catch ( Exception ex ) { logger . error ( ex , "An error occurred communicating with the New Relic service" ) ; if ( connection != null ) { try { logger . info ( "Response: " , connection . getResponseCode ( ) , " : " , connection . getResponseMessage ( ) ) ; } catch ( IOException e ) { logger . debug ( ex , ex . getMessage ( ) ) ; } } } finally { if ( connection != null ) { connection . disconnect ( ) ; } } } }
Deliver the {@code Request} to the New Relic metrics API.
Deliver the { @code Request } to the New Relic metrics API .
// do not send an empty request // process and log response from the collector