public InputStream call ( String methodName , MessageLite request ) throws DatastoreException { logger . fine ( "remote datastore call " + methodName ) ; long startTime = System . currentTimeMillis ( ) ; try { HttpResponse httpResponse ; try { rpcCount . incrementAndGet ( ) ; ProtoHttpContent payload = new ProtoHttpContent ( request ) ; HttpRequest httpRequest = client . buildPostRequest ( resolveURL ( methodName ) , payload ) ; httpRequest . getHeaders ( ) . put ( API_FORMAT_VERSION_HEADER , API_FORMAT_VERSION ) ; // Don't throw an HTTPResponseException on error. It converts the response to a String and // throws away the original, whereas we need the raw bytes to parse it as a proto. httpRequest . setThrowExceptionOnExecuteError ( false ) ; // Datastore requests typically time out after 60s; set the read timeout to slightly longer // than that by default (can be overridden via the HttpRequestInitializer). httpRequest . setReadTimeout ( 65 * 1000 ) ; if ( initializer != null ) { initializer . initialize ( httpRequest ) ; } httpResponse = httpRequest . execute ( ) ; if ( ! httpResponse . isSuccessStatusCode ( ) ) { try ( InputStream content = GzipFixingInputStream . maybeWrap ( httpResponse . getContent ( ) ) ) { throw makeException ( url , methodName , content , httpResponse . getContentType ( ) , httpResponse . getContentCharset ( ) , null , httpResponse . getStatusCode ( ) ) ; } } return GzipFixingInputStream . maybeWrap ( httpResponse . getContent ( ) ) ; } catch ( SocketTimeoutException e ) { throw makeException ( url , methodName , Code . DEADLINE_EXCEEDED , "Deadline exceeded" , e ) ; } catch ( IOException e ) { throw makeException ( url , methodName , Code . UNAVAILABLE , "I/O error" , e ) ; } } finally { long elapsedTime = System . currentTimeMillis ( ) - startTime ; logger . fine ( "remote datastore call " + methodName + " took " + elapsedTime + " ms" ) ; } }
Makes an RPC call using the client . Logs how long it took and any exceptions .