/** * Send an HTTP message to a worker and get the result * * <p>Note: expects the worker to respond with OK (200) status code. * * @param uriRequest The request to make * @return An InputStream of the response content */ private InputStream askWorker(HttpUriRequest uriRequest) { try { HttpResponse response = httpClient.execute(uriRequest); if (response.getStatusLine().getStatusCode() != Response.Status.OK.getStatusCode()) { StatusLine statusLine = response.getStatusLine(); EntityUtils.consume(response.getEntity()); logger.warn( "Problem asking worker <" + metadata.getWorkerId() + "> " + "(" + uriRequest.getURI() + "), " + "reason [" + statusLine.getStatusCode() + ": " + statusLine.getReasonPhrase() + "]"); } return response.getEntity().getContent(); } catch (IOException e) { logger.warn("Unable to communicated with worker " + metadata.toString()); throw Throwables.propagate(e); } }
/** * Send an HTTP message to a worker, producing helpful logging if there was a problem * * @param uriRequest The request to make * @param expectedStatus The expected return status * @return true if the method was successfully delivered & the worker gave the expected response */ private boolean tellWorker(HttpUriRequest uriRequest, Response.Status expectedStatus) { try { HttpResponse response = httpClient.execute(uriRequest); if (response.getStatusLine().getStatusCode() != expectedStatus.getStatusCode()) { StatusLine statusLine = response.getStatusLine(); EntityUtils.consume(response.getEntity()); logger.warn( "Problem telling worker <" + metadata.getWorkerId() + "> " + "(" + uriRequest.getURI() + "), " + "reason [" + statusLine.getStatusCode() + ": " + statusLine.getReasonPhrase() + "]"); return false; } return true; } catch (IOException e) { logger.warn("Unable to communicated with worker " + metadata.toString()); return false; } }