static Method getGaugeMethod ( Registry registry , Id id , Object obj , String method ) { try { final Method m = Utils . getMethod ( obj . getClass ( ) , method ) ; try { // Make sure we can cast the response to a Number final Number n = ( Number ) m . invoke ( obj ) ; REGISTRY_LOGGER . debug ( "registering gauge {}, using method [{}], with initial value {}" , id , m , n ) ; return m ; } catch ( Exception e ) { final String msg = "exception thrown invoking method [" + m + "], skipping registration of gauge " + id ; registry . propagate ( msg , e ) ; } } catch ( NoSuchMethodException e ) { final String mname = obj . getClass ( ) . getName ( ) + "." + method ; final String msg = "invalid method [" + mname + "], skipping registration of gauge " + id ; registry . propagate ( msg , e ) ; } return null ; }
Return a method supplying a value for a gauge .