Rest Client: improve listener naming
This commit is contained in:
parent
41e97a7cb1
commit
e27203534a
|
@ -248,14 +248,14 @@ public final class RestClient implements Closeable {
|
||||||
URI uri = buildUri(endpoint, params);
|
URI uri = buildUri(endpoint, params);
|
||||||
HttpRequestBase request = createHttpRequest(method, uri, entity);
|
HttpRequestBase request = createHttpRequest(method, uri, entity);
|
||||||
setHeaders(request, headers);
|
setHeaders(request, headers);
|
||||||
FailureTrackingListener failureTrackingListener = new FailureTrackingListener(responseListener);
|
FailureTrackingResponseListener failureTrackingResponseListener = new FailureTrackingResponseListener(responseListener);
|
||||||
long startTime = System.nanoTime();
|
long startTime = System.nanoTime();
|
||||||
performRequest(startTime, nextHost().iterator(), request, responseConsumer, failureTrackingListener);
|
performRequest(startTime, nextHost().iterator(), request, responseConsumer, failureTrackingResponseListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void performRequest(final long startTime, final Iterator<HttpHost> hosts, final HttpRequestBase request,
|
private void performRequest(final long startTime, final Iterator<HttpHost> hosts, final HttpRequestBase request,
|
||||||
final HttpAsyncResponseConsumer<HttpResponse> responseConsumer,
|
final HttpAsyncResponseConsumer<HttpResponse> responseConsumer,
|
||||||
final FailureTrackingListener listener) {
|
final FailureTrackingResponseListener listener) {
|
||||||
final HttpHost host = hosts.next();
|
final HttpHost host = hosts.next();
|
||||||
//we stream the request body if the entity allows for it
|
//we stream the request body if the entity allows for it
|
||||||
HttpAsyncRequestProducer requestProducer = HttpAsyncMethods.create(host, request);
|
HttpAsyncRequestProducer requestProducer = HttpAsyncMethods.create(host, request);
|
||||||
|
@ -473,11 +473,11 @@ public final class RestClient implements Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FailureTrackingListener {
|
private static class FailureTrackingResponseListener {
|
||||||
private final ResponseListener responseListener;
|
private final ResponseListener responseListener;
|
||||||
private volatile Exception exception;
|
private volatile Exception exception;
|
||||||
|
|
||||||
FailureTrackingListener(ResponseListener responseListener) {
|
FailureTrackingResponseListener(ResponseListener responseListener) {
|
||||||
this.responseListener = responseListener;
|
this.responseListener = responseListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,9 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link org.elasticsearch.client.RestClient.FailureListener} impl that allows to track when it gets called
|
* {@link org.elasticsearch.client.RestClient.FailureListener} impl that allows to track when it gets called for which host.
|
||||||
*/
|
*/
|
||||||
class TrackingFailureListener extends RestClient.FailureListener {
|
class HostsTrackingFailureListener extends RestClient.FailureListener {
|
||||||
private volatile Set<HttpHost> hosts = new HashSet<>();
|
private volatile Set<HttpHost> hosts = new HashSet<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -66,7 +66,7 @@ public class RestClientMultipleHostsTests extends RestClientTestCase {
|
||||||
|
|
||||||
private RestClient restClient;
|
private RestClient restClient;
|
||||||
private HttpHost[] httpHosts;
|
private HttpHost[] httpHosts;
|
||||||
private TrackingFailureListener failureListener;
|
private HostsTrackingFailureListener failureListener;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -101,7 +101,7 @@ public class RestClientMultipleHostsTests extends RestClientTestCase {
|
||||||
for (int i = 0; i < numHosts; i++) {
|
for (int i = 0; i < numHosts; i++) {
|
||||||
httpHosts[i] = new HttpHost("localhost", 9200 + i);
|
httpHosts[i] = new HttpHost("localhost", 9200 + i);
|
||||||
}
|
}
|
||||||
failureListener = new TrackingFailureListener();
|
failureListener = new HostsTrackingFailureListener();
|
||||||
restClient = new RestClient(httpClient, 10000, new Header[0], httpHosts, failureListener);
|
restClient = new RestClient(httpClient, 10000, new Header[0], httpHosts, failureListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class RestClientSingleHostTests extends RestClientTestCase {
|
||||||
private Header[] defaultHeaders;
|
private Header[] defaultHeaders;
|
||||||
private HttpHost httpHost;
|
private HttpHost httpHost;
|
||||||
private CloseableHttpAsyncClient httpClient;
|
private CloseableHttpAsyncClient httpClient;
|
||||||
private TrackingFailureListener failureListener;
|
private HostsTrackingFailureListener failureListener;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -141,7 +141,7 @@ public class RestClientSingleHostTests extends RestClientTestCase {
|
||||||
defaultHeaders[i] = new BasicHeader(headerName, headerValue);
|
defaultHeaders[i] = new BasicHeader(headerName, headerValue);
|
||||||
}
|
}
|
||||||
httpHost = new HttpHost("localhost", 9200);
|
httpHost = new HttpHost("localhost", 9200);
|
||||||
failureListener = new TrackingFailureListener();
|
failureListener = new HostsTrackingFailureListener();
|
||||||
restClient = new RestClient(httpClient, 10000, defaultHeaders, new HttpHost[]{httpHost}, failureListener);
|
restClient = new RestClient(httpClient, 10000, defaultHeaders, new HttpHost[]{httpHost}, failureListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue