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

Commit 8791345

Browse files
committed
Moving to Java 8 and minimizing Guava usage.
Change-Id: I24f173d6cacc2e9cb8c7b82758b12a1f1ac98225
1 parent 6e623ee commit 8791345

File tree

227 files changed

+2713
-2057
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+2713
-2057
lines changed

connectors/apache-connector/src/main/java/org/glassfish/jersey/apache/connector/ApacheConnector.java

Lines changed: 13 additions & 13 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
@@ -37,6 +37,7 @@
3737
* only if the new code is made subject to such option by the copyright
3838
* holder.
3939
*/
40+
4041
package org.glassfish.jersey.apache.connector;
4142

4243
import java.io.BufferedInputStream;
@@ -51,6 +52,7 @@
5152
import java.util.ArrayList;
5253
import java.util.List;
5354
import java.util.Map;
55+
import java.util.concurrent.CompletableFuture;
5456
import java.util.concurrent.Future;
5557
import java.util.concurrent.atomic.AtomicLong;
5658
import java.util.logging.Level;
@@ -122,8 +124,6 @@
122124
import org.apache.http.util.TextUtils;
123125
import org.apache.http.util.VersionInfo;
124126

125-
import jersey.repackaged.com.google.common.util.concurrent.MoreExecutors;
126-
127127
/**
128128
* A {@link Connector} that utilizes the Apache HTTP Client to send and receive
129129
* HTTP request and responses.
@@ -484,16 +484,16 @@ public ClientResponse apply(final ClientRequest clientRequest) throws Processing
484484

485485
@Override
486486
public Future<?> apply(final ClientRequest request, final AsyncConnectorCallback callback) {
487-
return MoreExecutors.sameThreadExecutor().submit(new Runnable() {
488-
@Override
489-
public void run() {
490-
try {
491-
callback.response(apply(request));
492-
} catch (final Throwable t) {
493-
callback.failure(t);
494-
}
495-
}
496-
});
487+
try {
488+
ClientResponse response = apply(request);
489+
callback.response(response);
490+
return CompletableFuture.completedFuture(response);
491+
} catch (Throwable t) {
492+
callback.failure(t);
493+
CompletableFuture<Object> future = new CompletableFuture<>();
494+
future.completeExceptionally(t);
495+
return future;
496+
}
497497
}
498498

499499
@Override

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.util.List;
4747
import java.util.Map;
4848
import java.util.Properties;
49+
import java.util.concurrent.CompletableFuture;
4950
import java.util.concurrent.ExecutionException;
5051
import java.util.concurrent.ExecutorService;
5152
import java.util.concurrent.Executors;
@@ -86,8 +87,6 @@
8687
import com.ning.http.client.providers.grizzly.GrizzlyAsyncHttpProvider;
8788
import com.ning.http.util.ProxyUtils;
8889

89-
import jersey.repackaged.com.google.common.util.concurrent.SettableFuture;
90-
9190
/**
9291
* The transport using the AsyncHttpClient.
9392
*
@@ -204,7 +203,7 @@ public ClientResponse apply(final ClientRequest request) {
204203
final Request connectorRequest = translate(request);
205204
final Map<String, String> clientHeadersSnapshot = writeOutBoundHeaders(request.getHeaders(), connectorRequest);
206205

207-
final SettableFuture<ClientResponse> responseFuture = SettableFuture.create();
206+
final CompletableFuture<ClientResponse> responseFuture = new CompletableFuture<>();
208207
final ByteBufferInputStream entityStream = new ByteBufferInputStream();
209208
final AtomicBoolean futureSet = new AtomicBoolean(false);
210209

@@ -227,7 +226,7 @@ public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception {
227226
HeaderUtils.checkHeaderChanges(clientHeadersSnapshot, request.getHeaders(),
228227
GrizzlyConnector.this.getClass().getName());
229228

230-
responseFuture.set(translate(request, this.status, headers, entityStream));
229+
responseFuture.complete(translate(request, this.status, headers, entityStream));
231230
return STATE.CONTINUE;
232231
}
233232

@@ -249,7 +248,7 @@ public void onThrowable(Throwable t) {
249248

250249
if (futureSet.compareAndSet(false, true)) {
251250
t = t instanceof IOException ? new ProcessingException(t.getMessage(), t) : t;
252-
responseFuture.setException(t);
251+
responseFuture.completeExceptionally(t);
253252
}
254253
}
255254
});
@@ -328,9 +327,9 @@ public void onThrowable(Throwable t) {
328327
if (callbackInvoked.compareAndSet(false, true)) {
329328
callback.failure(failure);
330329
}
331-
final SettableFuture<Object> errorFuture = SettableFuture.create();
332-
errorFuture.setException(failure);
333-
return errorFuture;
330+
CompletableFuture<Object> future = new CompletableFuture<>();
331+
future.completeExceptionally(failure);
332+
return future;
334333
}
335334

336335
@Override

connectors/jetty-connector/src/main/java/org/glassfish/jersey/jetty/connector/JettyConnector.java

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import java.util.List;
5353
import java.util.Map;
5454
import java.util.concurrent.CancellationException;
55+
import java.util.concurrent.CompletableFuture;
5556
import java.util.concurrent.Future;
5657
import java.util.concurrent.TimeUnit;
5758
import java.util.concurrent.atomic.AtomicBoolean;
@@ -97,10 +98,6 @@
9798
import org.eclipse.jetty.util.ssl.SslContextFactory;
9899
import org.eclipse.jetty.util.thread.QueuedThreadPool;
99100

100-
import jersey.repackaged.com.google.common.util.concurrent.FutureCallback;
101-
import jersey.repackaged.com.google.common.util.concurrent.Futures;
102-
import jersey.repackaged.com.google.common.util.concurrent.SettableFuture;
103-
104101
/**
105102
* A {@link Connector} that utilizes the Jetty HTTP Client to send and receive
106103
* HTTP request and responses.
@@ -388,20 +385,16 @@ public Future<?> apply(final ClientRequest jerseyRequest, final AsyncConnectorCa
388385
final AtomicBoolean callbackInvoked = new AtomicBoolean(false);
389386
final Throwable failure;
390387
try {
391-
final SettableFuture<ClientResponse> responseFuture = SettableFuture.create();
392-
Futures.addCallback(responseFuture, new FutureCallback<ClientResponse>() {
393-
@Override
394-
public void onSuccess(final ClientResponse result) {
395-
}
388+
final CompletableFuture<ClientResponse> responseFuture =
389+
new CompletableFuture<ClientResponse>().whenComplete(
390+
(clientResponse, throwable) -> {
391+
if (throwable != null && throwable instanceof CancellationException) {
392+
// take care of future cancellation
393+
jettyRequest.abort(throwable);
394+
395+
}
396+
});
396397

397-
@Override
398-
public void onFailure(final Throwable t) {
399-
if (t instanceof CancellationException) {
400-
// take care of future cancellation
401-
jettyRequest.abort(t);
402-
}
403-
}
404-
});
405398
final AtomicReference<ClientResponse> jerseyResponse = new AtomicReference<>();
406399
final ByteBufferInputStream entityStream = new ByteBufferInputStream();
407400
jettyRequest.send(new Response.Listener.Adapter() {
@@ -429,7 +422,7 @@ public void onContent(final Response jettyResponse, final ByteBuffer content) {
429422
final ProcessingException pe = new ProcessingException(ex);
430423
entityStream.closeQueue(pe);
431424
// try to complete the future with an exception
432-
responseFuture.setException(pe);
425+
responseFuture.completeExceptionally(pe);
433426
Thread.currentThread().interrupt();
434427
}
435428
}
@@ -438,14 +431,14 @@ public void onContent(final Response jettyResponse, final ByteBuffer content) {
438431
public void onComplete(final Result result) {
439432
entityStream.closeQueue();
440433
// try to complete the future with the response only once truly done
441-
responseFuture.set(jerseyResponse.get());
434+
responseFuture.complete(jerseyResponse.get());
442435
}
443436

444437
@Override
445438
public void onFailure(final Response response, final Throwable t) {
446439
entityStream.closeQueue(t);
447440
// try to complete the future with an exception
448-
responseFuture.setException(t);
441+
responseFuture.completeExceptionally(t);
449442
if (callbackInvoked.compareAndSet(false, true)) {
450443
callback.failure(t);
451444
}
@@ -460,7 +453,9 @@ public void onFailure(final Response response, final Throwable t) {
460453
if (callbackInvoked.compareAndSet(false, true)) {
461454
callback.failure(failure);
462455
}
463-
return Futures.immediateFailedFuture(failure);
456+
CompletableFuture<Object> future = new CompletableFuture<>();
457+
future.completeExceptionally(failure);
458+
return future;
464459
}
465460

466461
private static ClientResponse translateResponse(final ClientRequest jerseyRequest,

connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/JerseyClientHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.io.IOException;
4545
import java.io.InputStream;
4646
import java.util.Map;
47+
import java.util.concurrent.CompletableFuture;
4748
import java.util.concurrent.LinkedBlockingDeque;
4849

4950
import javax.ws.rs.core.Response;
@@ -59,7 +60,6 @@
5960
import io.netty.handler.codec.http.LastHttpContent;
6061
import io.netty.util.concurrent.Future;
6162
import io.netty.util.concurrent.GenericFutureListener;
62-
import jersey.repackaged.com.google.common.util.concurrent.SettableFuture;
6363
import org.glassfish.jersey.client.ClientRequest;
6464
import org.glassfish.jersey.client.ClientResponse;
6565
import org.glassfish.jersey.client.spi.AsyncConnectorCallback;
@@ -77,10 +77,10 @@ class JerseyClientHandler extends SimpleChannelInboundHandler<HttpObject> {
7777

7878
private final AsyncConnectorCallback asyncConnectorCallback;
7979
private final ClientRequest jerseyRequest;
80-
private final SettableFuture future;
80+
private final CompletableFuture future;
8181

8282
JerseyClientHandler(NettyConnector nettyConnector, ClientRequest request,
83-
AsyncConnectorCallback callback, SettableFuture future) {
83+
AsyncConnectorCallback callback, CompletableFuture future) {
8484
this.connector = nettyConnector;
8585
this.asyncConnectorCallback = callback;
8686
this.jerseyRequest = request;
@@ -139,7 +139,7 @@ public int read() throws IOException {
139139
@Override
140140
public void run() {
141141
asyncConnectorCallback.response(jerseyResponse);
142-
future.set(jerseyResponse);
142+
future.complete(jerseyResponse);
143143
}
144144
});
145145
}
@@ -175,7 +175,7 @@ public void run() {
175175
}
176176
});
177177
}
178-
future.setException(cause);
178+
future.completeExceptionally(cause);
179179
isList.add(NettyInputStream.END_OF_INPUT_ERROR);
180180
}
181181
}

connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyConnector.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.net.URI;
4747
import java.util.List;
4848
import java.util.Map;
49+
import java.util.concurrent.CompletableFuture;
4950
import java.util.concurrent.ExecutionException;
5051
import java.util.concurrent.ExecutorService;
5152
import java.util.concurrent.Executors;
@@ -81,7 +82,6 @@
8182
import io.netty.handler.ssl.JdkSslContext;
8283
import io.netty.handler.stream.ChunkedWriteHandler;
8384
import io.netty.util.concurrent.GenericFutureListener;
84-
import jersey.repackaged.com.google.common.util.concurrent.SettableFuture;
8585
import org.glassfish.jersey.client.ClientProperties;
8686
import org.glassfish.jersey.client.ClientRequest;
8787
import org.glassfish.jersey.client.ClientResponse;
@@ -160,7 +160,7 @@ public void failure(Throwable failure) {
160160
@Override
161161
public Future<?> apply(final ClientRequest jerseyRequest, final AsyncConnectorCallback jerseyCallback) {
162162

163-
final SettableFuture<Object> settableFuture = SettableFuture.create();
163+
final CompletableFuture<Object> settableFuture = new CompletableFuture<>();
164164

165165
final URI requestUri = jerseyRequest.getUri();
166166
String host = requestUri.getHost();
@@ -221,7 +221,7 @@ protected void initChannel(SocketChannel ch) throws Exception {
221221
@Override
222222
public void operationComplete(io.netty.util.concurrent.Future<? super Void> future) throws Exception {
223223
if (!settableFuture.isDone()) {
224-
settableFuture.setException(new IOException("Channel closed."));
224+
settableFuture.completeExceptionally(new IOException("Channel closed."));
225225
}
226226
}
227227
};
@@ -284,7 +284,7 @@ public void run() {
284284
jerseyRequest.writeEntity();
285285
} catch (IOException e) {
286286
jerseyCallback.failure(e);
287-
settableFuture.setException(e);
287+
settableFuture.completeExceptionally(e);
288288
}
289289
}
290290
});
@@ -299,7 +299,7 @@ public void run() {
299299
}
300300

301301
} catch (InterruptedException e) {
302-
settableFuture.setException(e);
302+
settableFuture.completeExceptionally(e);
303303
return settableFuture;
304304
}
305305

containers/grizzly2-http/src/main/java/org/glassfish/jersey/grizzly2/httpserver/GrizzlyHttpServerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
import org.glassfish.grizzly.ssl.SSLEngineConfigurator;
6161
import org.glassfish.grizzly.utils.Charsets;
6262

63-
import jersey.repackaged.com.google.common.util.concurrent.ThreadFactoryBuilder;
63+
import org.glassfish.jersey.internal.guava.ThreadFactoryBuilder;
6464

6565
/**
6666
* Factory for creating Grizzly Http Server.

containers/jdk-http/src/main/java/org/glassfish/jersey/jdkhttp/JdkHttpServerFactory.java

Lines changed: 2 additions & 2 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
@@ -64,7 +64,7 @@
6464
import com.sun.net.httpserver.HttpsConfigurator;
6565
import com.sun.net.httpserver.HttpsServer;
6666

67-
import jersey.repackaged.com.google.common.util.concurrent.ThreadFactoryBuilder;
67+
import org.glassfish.jersey.internal.guava.ThreadFactoryBuilder;
6868

6969
/**
7070
* Factory for creating {@link HttpServer JDK HttpServer} instances to run Jersey applications.

containers/jersey-servlet-core/src/main/java/org/glassfish/jersey/servlet/ServletPropertiesDelegate.java

Lines changed: 4 additions & 12 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
@@ -41,15 +41,12 @@
4141
package org.glassfish.jersey.servlet;
4242

4343
import java.util.Collection;
44-
import java.util.Iterator;
44+
import java.util.Collections;
4545

4646
import javax.servlet.http.HttpServletRequest;
4747

4848
import org.glassfish.jersey.internal.PropertiesDelegate;
4949

50-
import jersey.repackaged.com.google.common.collect.Iterators;
51-
import jersey.repackaged.com.google.common.collect.Lists;
52-
5350
/**
5451
* @author Martin Matula
5552
*/
@@ -67,13 +64,8 @@ public Object getProperty(String name) {
6764

6865
@Override
6966
public Collection<String> getPropertyNames() {
70-
return Lists.newLinkedList(new Iterable<String>() {
71-
@Override
72-
@SuppressWarnings("unchecked")
73-
public Iterator<String> iterator() {
74-
return Iterators.forEnumeration(request.getAttributeNames());
75-
}
76-
});
67+
//noinspection unchecked
68+
return Collections.list(request.getAttributeNames());
7769
}
7870

7971
@Override

0 commit comments

Comments
 (0)