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

Commit 4bc0247

Browse files
committed
pull 201: adjustments, formatting, ..
Change-Id: Iae0f3d5e357c09d28dcc2de7a282242593f0805e
1 parent 8c06e4c commit 4bc0247

File tree

3 files changed

+131
-21
lines changed

3 files changed

+131
-21
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2010-2015 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2016 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -123,10 +123,10 @@ class GrizzlyConnector implements Connector {
123123
builder = builder.setExecutorService(executorService);
124124

125125
builder.setConnectTimeout(ClientProperties.getValue(config.getProperties(),
126-
ClientProperties.CONNECT_TIMEOUT, 0));
126+
ClientProperties.CONNECT_TIMEOUT, 0));
127127

128128
builder.setRequestTimeout(ClientProperties.getValue(config.getProperties(),
129-
ClientProperties.READ_TIMEOUT, 0));
129+
ClientProperties.READ_TIMEOUT, 0));
130130

131131
Object proxyUri;
132132
proxyUri = config.getProperty(ClientProperties.PROXY_URI);
@@ -193,9 +193,12 @@ public AsyncHttpClient getGrizzlyClient() {
193193
return grizzlyClient;
194194
}
195195

196-
/*
197-
* Sends the {@link javax.ws.rs.core.Request} via Grizzly transport and returns the {@link javax.ws.rs.core.Response}.
198-
*/
196+
/**
197+
* Sends the {@link javax.ws.rs.core.Request} via Grizzly transport and returns the {@link javax.ws.rs.core.Response}.
198+
*
199+
* @param request Jersey client request to be sent.
200+
* @return received response.
201+
*/
199202
@Override
200203
public ClientResponse apply(final ClientRequest request) {
201204
final Request connectorRequest = translate(request);
@@ -290,7 +293,7 @@ public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception {
290293
processResponse(new Runnable() {
291294
@Override
292295
public void run() {
293-
callback.response(translate(request, status, headers, entityStream));
296+
callback.response(translate(request, status, headers, entityStream));
294297
}
295298
});
296299
return STATE.CONTINUE;
@@ -418,10 +421,11 @@ public OutputStream getOutputStream(int contentLength) throws IOException {
418421
}
419422

420423
/**
421-
* Submits the response processing on Grizzly client's application thread pool
422-
* @param responseTask task to be processed on application thread pool
424+
* Submits the response processing on Grizzly client's application thread pool.
425+
*
426+
* @param responseTask task to be processed on application thread pool.
423427
*/
424-
public void processResponse(Runnable responseTask) {
428+
private void processResponse(Runnable responseTask) {
425429
this.grizzlyClient.getConfig().executorService().submit(responseTask);
426430
}
427431

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2012-2015 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2012-2016 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -161,18 +161,19 @@ public void run() {
161161

162162
@Override
163163
public void response(final ClientResponse response) {
164-
requestScope.runInScope(new Runnable(){
165-
public void run() {
166-
processResponse(response, callback);
167-
}});
164+
requestScope.runInScope(new Runnable() {
165+
public void run() {
166+
processResponse(response, callback);
167+
}
168+
});
168169
}
169170

170171
@Override
171172
public void failure(final Throwable failure) {
172-
requestScope.runInScope(new Runnable() {
173-
public void run() {
174-
processFailure(failure, callback);
175-
}
173+
requestScope.runInScope(new Runnable() {
174+
public void run() {
175+
processFailure(failure, callback);
176+
}
176177
});
177178
}
178179
};
@@ -242,7 +243,6 @@ private ClientRequest addUserAgent(final ClientRequest clientRequest, final Stri
242243
*
243244
* @param request client request to be invoked.
244245
* @return client response.
245-
*
246246
* @throws javax.ws.rs.ProcessingException in case of an invocation failure.
247247
*/
248248
public ClientResponse invoke(final ClientRequest request) {
@@ -284,7 +284,7 @@ public ClientConfig getConfig() {
284284
* This will be used as the last resort to clean things up
285285
* in the case that this instance gets garbage collected
286286
* before the client itself gets released.
287-
*
287+
* <p>
288288
* Close will be invoked either via finalizer
289289
* or via JerseyClient onShutdown hook, whatever comes first.
290290
*/
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
41+
package org.glassfish.jersey.tests.e2e.client.grizzlyconnector;
42+
43+
import java.util.concurrent.Future;
44+
45+
import javax.ws.rs.GET;
46+
import javax.ws.rs.Path;
47+
import javax.ws.rs.client.InvocationCallback;
48+
import javax.ws.rs.core.Application;
49+
50+
import org.glassfish.jersey.client.ClientConfig;
51+
import org.glassfish.jersey.grizzly.connector.GrizzlyConnectorProvider;
52+
import org.glassfish.jersey.server.ResourceConfig;
53+
import org.glassfish.jersey.test.JerseyTest;
54+
import org.junit.Test;
55+
import static org.junit.Assert.assertNotNull;
56+
import static org.junit.Assert.assertTrue;
57+
58+
/**
59+
* Grizzly connector non blocking test.
60+
*/
61+
public class NonBlockingTest extends JerseyTest {
62+
63+
@Path("/test")
64+
public static class Resource {
65+
66+
@GET
67+
public String get() {
68+
return "GET";
69+
}
70+
}
71+
72+
@Override
73+
protected Application configure() {
74+
return new ResourceConfig(Resource.class);
75+
}
76+
77+
@Override
78+
protected void configureClient(ClientConfig config) {
79+
config.connectorProvider(new GrizzlyConnectorProvider());
80+
}
81+
82+
private volatile String invocationCallbackThreadName;
83+
84+
@Test
85+
public void testNonBlockingConnector() throws Exception {
86+
Future<String> future = target("test")
87+
.request()
88+
.async()
89+
.get(new InvocationCallback<String>() {
90+
@Override
91+
public void completed(String response) {
92+
invocationCallbackThreadName = Thread.currentThread().getName();
93+
}
94+
95+
@Override
96+
public void failed(Throwable throwable) {
97+
invocationCallbackThreadName = Thread.currentThread().getName();
98+
}
99+
});
100+
101+
String response = future.get();
102+
assertNotNull(response);
103+
assertTrue("Invocation callback is not executed on the NIO pool thread.",
104+
!invocationCallbackThreadName.contains("jersey-client-async-executor"));
105+
}
106+
}

0 commit comments

Comments
 (0)