@ SuppressWarnings ( "unchecked" ) private void gatherOneMetric ( String metricName , Metrics . MetricPublisherPublishMessage . Builder builder ) { Object metricValue = metrics . get ( metricName ) . getValueAndReset ( ) ; // Decide how to handle the metric based on type if ( metricValue == null ) { return ; } if ( metricValue instanceof Map ) { for ( Map . Entry < Object , Object > entry : ( ( Map < Object , Object > ) metricValue ) . entrySet ( ) ) { if ( entry . getKey ( ) != null && entry . getValue ( ) != null ) { addDataToMetricPublisher ( builder , metricName + "/" + entry . getKey ( ) . toString ( ) , entry . getValue ( ) ) ; } } } else if ( metricValue instanceof Collection ) { int index = 0 ; for ( Object value : ( Collection ) metricValue ) { addDataToMetricPublisher ( builder , metricName + "/" + ( index ++ ) , value ) ; } } else { addDataToMetricPublisher ( builder , metricName , metricValue ) ; } }
and add it to MetricPublisherPublishMessage builder given .