Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit b0fc74e

Browse files
committed
Remove blocking on future in ClientRuntime for async requests
- [Grizzly connector] Process response on grizzly's client application thread pool
1 parent 24981b8 commit b0fc74e

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

connectors/grizzly-connector/src/main/java/org/glassfish/jersey/grizzly/connector/GrizzlyConnector.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,13 @@ public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception {
286286

287287
HeaderUtils.checkHeaderChanges(clientHeadersSnapshot, request.getHeaders(),
288288
GrizzlyConnector.this.getClass().getName());
289-
290-
callback.response(translate(request, this.status, headers, entityStream));
289+
// hand-off to grizzly's application thread pool for response processing
290+
processResponse(new Runnable() {
291+
@Override
292+
public void run() {
293+
callback.response(translate(request, status, headers, entityStream));
294+
}
295+
});
291296
return STATE.CONTINUE;
292297
}
293298

@@ -412,6 +417,14 @@ public OutputStream getOutputStream(int contentLength) throws IOException {
412417
return builder.build();
413418
}
414419

420+
/**
421+
* Submits the response processing on Grizzly client's application thread pool
422+
* @param responseTask task to be processed on application thread pool
423+
*/
424+
public void processResponse(Runnable responseTask) {
425+
this.grizzlyClient.getConfig().executorService().submit(responseTask);
426+
}
427+
415428
/**
416429
* Utility OutputStream implementation that can feed Grizzly chunk-encoded body generator.
417430
*/

core-client/src/main/java/org/glassfish/jersey/client/ClientRuntime.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,17 @@
4040
package org.glassfish.jersey.client;
4141

4242
import java.util.Arrays;
43-
import java.util.concurrent.ExecutionException;
4443
import java.util.concurrent.ExecutorService;
4544
import java.util.concurrent.Future;
4645
import java.util.concurrent.atomic.AtomicBoolean;
4746
import java.util.logging.Level;
4847
import java.util.logging.Logger;
4948

5049
import javax.ws.rs.ProcessingException;
51-
import javax.ws.rs.client.ResponseProcessingException;
5250
import javax.ws.rs.core.HttpHeaders;
5351
import javax.ws.rs.core.MultivaluedMap;
5452

53+
import org.glassfish.hk2.api.ServiceLocator;
5554
import org.glassfish.jersey.client.internal.LocalizationMessages;
5655
import org.glassfish.jersey.client.spi.AsyncConnectorCallback;
5756
import org.glassfish.jersey.client.spi.Connector;
@@ -67,10 +66,6 @@
6766
import org.glassfish.jersey.process.internal.Stage;
6867
import org.glassfish.jersey.process.internal.Stages;
6968

70-
import org.glassfish.hk2.api.ServiceLocator;
71-
72-
import jersey.repackaged.com.google.common.util.concurrent.SettableFuture;
73-
7469
/**
7570
* Client-side request processing runtime.
7671
*
@@ -162,24 +157,26 @@ public void run() {
162157
return;
163158
}
164159

165-
final SettableFuture<ClientResponse> responseFuture = SettableFuture.create();
166160
final AsyncConnectorCallback connectorCallback = new AsyncConnectorCallback() {
167161

168162
@Override
169163
public void response(final ClientResponse response) {
170-
responseFuture.set(response);
164+
requestScope.runInScope(new Runnable(){
165+
public void run() {
166+
processResponse(response, callback);
167+
}});
171168
}
172169

173170
@Override
174171
public void failure(final Throwable failure) {
175-
responseFuture.setException(failure);
172+
requestScope.runInScope(new Runnable() {
173+
public void run() {
174+
processFailure(failure, callback);
175+
}
176+
});
176177
}
177178
};
178179
connector.apply(processedRequest, connectorCallback);
179-
180-
processResponse(responseFuture.get(), callback);
181-
} catch (final ExecutionException e) {
182-
processFailure(e.getCause(), callback);
183180
} catch (final Throwable throwable) {
184181
processFailure(throwable, callback);
185182
}

0 commit comments

Comments
 (0)