private IAsyncResultHandler<IEngineResult> wrapResultHandler(final IAsyncResultHandler<IEngineResult> handler) {
        return (IAsyncResult<IEngineResult> result) -> {
            boolean doRecord = true;
            if (result.isError()) {
                recordErrorMetrics(result.getError());
            } else {
                IEngineResult engineResult = result.getResult();
                if (engineResult.isFailure()) {
                    recordFailureMetrics(engineResult.getPolicyFailure());
                } else {
                    recordSuccessMetrics(engineResult.getApiResponse());
                    doRecord = false; // don't record the metric now because we need to record # of bytes downloaded, which hasn't happened yet
                }
            }
            requestMetric.setRequestEnd(new Date());
            if (doRecord) {
                metrics.record(requestMetric);
            }
            handler.handle(result);
        };
    }
private IAsyncResultHandler < IEngineResult > wrapResultHandler ( final IAsyncResultHandler < IEngineResult > handler ) { return ( IAsyncResult < IEngineResult > result ) -> { boolean doRecord = true ; if ( result . isError ( ) ) { recordErrorMetrics ( result . getError ( ) ) ; } else { IEngineResult engineResult = result . getResult ( ) ; if ( engineResult . isFailure ( ) ) { recordFailureMetrics ( engineResult . getPolicyFailure ( ) ) ; } else { recordSuccessMetrics ( engineResult . getApiResponse ( ) ) ; doRecord = false ; } } requestMetric . setRequestEnd ( new Date ( ) ) ; if ( doRecord ) { metrics . record ( requestMetric ) ; } handler . handle ( result ) ; } ; }
Wraps the result handler so that metrics can be properly recorded.