void dispatchSync ( DispatchQueue networkQueue ) { long requestStartTime = System . currentTimeMillis ( ) ; try { sendRequestSync ( ) ; } catch ( NetworkUnavailableException e ) { responseCode = - 1 ; // indicates failure errorMessage = e . getMessage ( ) ; ApptentiveLog . w ( NETWORK , e . getMessage ( ) ) ; ApptentiveLog . w ( NETWORK , "Cancelled? %b" , isCancelled ( ) ) ; } catch ( Exception e ) { responseCode = - 1 ; // indicates failure errorMessage = e . getMessage ( ) ; ApptentiveLog . e ( NETWORK , "Cancelled? %b" , isCancelled ( ) ) ; if ( ! isCancelled ( ) ) { ApptentiveLog . e ( NETWORK , "Unable to perform request: %s" , this ) ; } // TODO: send error metrics with the details of the request } ApptentiveLog . d ( NETWORK , "Request finished in %d ms" , System . currentTimeMillis ( ) - requestStartTime ) ; // attempt a retry if request failed if ( isFailed ( ) && retryRequest ( networkQueue , responseCode ) ) { // we schedule request retry on the same queue as it was originally dispatched return ; } // use custom callback queue (if any) if ( callbackQueue != null ) { callbackQueue . dispatchAsync ( new DispatchTask ( ) { @ Override protected void execute ( ) { finishRequest ( ) ; } } ) ; } else { finishRequest ( ) ; // we don't care where the callback is dispatched until it's on a background queue } }
Send request synchronously on a background network queue