org.elasticsearch.client.ResponseListener Java Examples
The following examples show how to use
org.elasticsearch.client.ResponseListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ElasticsearchClientAsyncInstrumentation.java From apm-agent-java with Apache License 2.0 | 6 votes |
@Advice.OnMethodEnter(suppress = Throwable.class) private static void onBeforeExecute(@Advice.Argument(0) Request request, @Advice.Argument(value = 1, readOnly = false) ResponseListener responseListener, @Advice.Local("span") Span span, @Advice.Local("wrapped") boolean wrapped, @Advice.Local("helper") ElasticsearchRestClientInstrumentationHelper<HttpEntity, Response, ResponseListener> helper) { helper = esClientInstrHelperManager.getForClassLoaderOfClass(Request.class); if (helper != null) { span = helper.createClientSpan(request.getMethod(), request.getEndpoint(), request.getEntity()); if (span != null) { responseListener = helper.<ResponseListener>wrapResponseListener(responseListener, span); wrapped = true; } } }
Example #2
Source File: ElasticsearchClientAsyncInstrumentation.java From apm-agent-java with Apache License 2.0 | 6 votes |
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class) private static void onAfterExecute(@Advice.Argument(1) ResponseListener responseListener, @Advice.Local("span") @Nullable Span span, @Advice.Local("wrapped") boolean wrapped, @Advice.Local("helper") @Nullable ElasticsearchRestClientInstrumentationHelper<HttpEntity, Response, ResponseListener> helper, @Advice.Thrown @Nullable Throwable t) { if (span != null) { // Deactivate in this thread. Span will be ended and reported by the listener span.deactivate(); if (!wrapped) { // Listener is not wrapped- we need to end the span so to avoid leak and report error if occurred during method invocation helper.finishClientSpan(null, span, t); } } }
Example #3
Source File: ElasticsearchClientAsyncInstrumentation.java From apm-agent-java with Apache License 2.0 | 6 votes |
@Advice.OnMethodEnter(suppress = Throwable.class) private static void onBeforeExecute(@Advice.Argument(0) String method, @Advice.Argument(1) String endpoint, @Advice.Argument(3) @Nullable HttpEntity entity, @Advice.Argument(value = 5, readOnly = false) ResponseListener responseListener, @Advice.Local("span") Span span, @Advice.Local("wrapped") boolean wrapped, @Advice.Local("helper") ElasticsearchRestClientInstrumentationHelper<HttpEntity, Response, ResponseListener> helper) { helper = esClientInstrHelperManager.getForClassLoaderOfClass(Response.class); if (helper != null) { span = helper.createClientSpan(method, endpoint, entity); if (span != null) { responseListener = helper.<ResponseListener>wrapResponseListener(responseListener, span); wrapped = true; } } }
Example #4
Source File: ElasticsearchClientAsyncInstrumentation.java From apm-agent-java with Apache License 2.0 | 6 votes |
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class) private static void onAfterExecute(@Advice.Argument(5) ResponseListener responseListener, @Advice.Local("span") @Nullable Span span, @Advice.Local("wrapped") boolean wrapped, @Advice.Local("helper") @Nullable ElasticsearchRestClientInstrumentationHelper<HttpEntity, Response, ResponseListener> helper, @Advice.Thrown @Nullable Throwable t) { if (span != null) { // Deactivate in this thread. Span will be ended and reported by the listener span.deactivate(); if (!wrapped) { // Listener is not wrapped- we need to end the span so to avoid leak and report error if occurred during method invocation helper.finishClientSpan(null, span, t); } } }
Example #5
Source File: ElasticsearchRestClientInstrumentationIT.java From apm-agent-java with Apache License 2.0 | 6 votes |
private Response doPerformRequest(String method, String path) throws IOException, ExecutionException { if (async) { final CompletableFuture<Response> resultFuture = new CompletableFuture<>(); lowLevelClient.performRequestAsync(method, path, new ResponseListener() { @Override public void onSuccess(Response response) { resultFuture.complete(response); } @Override public void onFailure(Exception exception) { resultFuture.completeExceptionally(exception); } }); try { return resultFuture.get(); } catch (InterruptedException e) { e.printStackTrace(); } } return lowLevelClient.performRequest(method, path); }
Example #6
Source File: RxJavaTransport.java From immutables with Apache License 2.0 | 6 votes |
Single<Response> execute(Request request) { Objects.requireNonNull(request, "request"); return Single.create(source -> { restClient.performRequestAsync(request, new ResponseListener() { @Override public void onSuccess(Response response) { source.onSuccess(response); } @Override public void onFailure(Exception exception) { source.onError(exception); } }); }); }
Example #7
Source File: ElasticsearchClientSyncInstrumentation.java From apm-agent-java with Apache License 2.0 | 5 votes |
@Advice.OnMethodEnter(suppress = Throwable.class) private static void onBeforeExecute(@Advice.Argument(0) Request request, @Advice.Local("span") Span span, @Advice.Local("helper") ElasticsearchRestClientInstrumentationHelper<HttpEntity, Response, ResponseListener> helper) { helper = esClientInstrHelperManager.getForClassLoaderOfClass(Request.class); if (helper != null) { span = helper.createClientSpan(request.getMethod(), request.getEndpoint(), request.getEntity()); } }
Example #8
Source File: ElasticsearchClientSyncInstrumentation.java From apm-agent-java with Apache License 2.0 | 5 votes |
@Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class) public static void onAfterExecute(@Advice.Return @Nullable Response response, @Advice.Local("span") @Nullable Span span, @Advice.Local("helper") @Nullable ElasticsearchRestClientInstrumentationHelper<HttpEntity, Response, ResponseListener> helper, @Advice.Thrown @Nullable Throwable t) { if (helper != null && span != null) { try { helper.finishClientSpan(response, span, t); } finally { span.deactivate(); } } }
Example #9
Source File: ElasticsearchRestClientTest.java From java-specialagent with Apache License 2.0 | 5 votes |
private static void test2(final RestClient client, final HttpEntity entity) { final Request request = new Request("PUT", "/twitter/tweet/2"); request.setEntity(entity); client.performRequestAsync(request, new ResponseListener() { @Override public void onSuccess(final Response response) { } @Override public void onFailure(final Exception exception) { } }); }
Example #10
Source File: ElasticsearchITest.java From java-specialagent with Apache License 2.0 | 5 votes |
private static void runRestClient() throws IOException, InterruptedException { try (final RestClient restClient = RestClient.builder(new HttpHost("localhost", HTTP_PORT, "http")).build()) { final HttpEntity entity = new NStringEntity( "{\n" + " \"user\": \"user\",\n" + " \"post_date\": \"2009-11-15T14:12:12\",\n" + " \"message\": \"trying out Elasticsearch\"\n" + "}", ContentType.APPLICATION_JSON); final Request request1 = new Request("PUT", "/twitter/tweet/1"); request1.setEntity(entity); final Response indexResponse = restClient.performRequest(request1); System.out.println(indexResponse); final Request request2 = new Request("PUT", "/twitter/tweet/2"); request2.setEntity(entity); final CountDownLatch latch = new CountDownLatch(1); restClient.performRequestAsync(request2, new ResponseListener() { @Override public void onSuccess(final Response response) { latch.countDown(); } @Override public void onFailure(final Exception e) { latch.countDown(); } }); latch.await(30, TimeUnit.SECONDS); } }
Example #11
Source File: ResponseListenerWrapper.java From apm-agent-java with Apache License 2.0 | 4 votes |
ResponseListenerWrapper with(ResponseListener delegate, Span span) { // Order is important due to visibility - write to span last on this (initiating) thread this.delegate = delegate; this.span = span; return this; }
Example #12
Source File: ElasticsearchRestClientInstrumentationHelperImpl.java From apm-agent-java with Apache License 2.0 | 4 votes |
@Override public ResponseListener wrapResponseListener(ResponseListener listener, Span span) { return responseListenerObjectPool.createInstance().with(listener, span); }