Skip to content

Commit 46d8bbe

Browse files
committed
Adopt to Reactor Netty changes.
Also, ignore deprecations as we cannot switch to the Sinks API easily. [#466] Signed-off-by: Mark Paluch <[email protected]>
1 parent 88819eb commit 46d8bbe

7 files changed

+27
-109
lines changed

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@
267267
<compilerArgs>
268268
<arg>-Werror</arg>
269269
<arg>-Xlint:all</arg>
270+
<arg>-Xlint:-deprecation</arg>
270271
<arg>-Xlint:-options</arg>
271272
<arg>-Xlint:-processing</arg>
272273
<arg>-Xlint:-serial</arg>

src/main/java/io/r2dbc/postgresql/ExtendedFlowDelegate.java

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
* Utility to execute the {@code Parse/Bind/Describe/Execute/Sync} portion of the <a href="https://www.postgresql.org/docs/current/static/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY">Extended query</a>
7070
* message flow.
7171
*/
72+
@SuppressWarnings("deprecation")
7273
class ExtendedFlowDelegate {
7374

7475
static final Predicate<BackendMessage> RESULT_FRAME_FILTER = not(or(BindComplete.class::isInstance, NoData.class::isInstance));

src/main/java/io/r2dbc/postgresql/ExtendedQueryPostgresqlStatement.java

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
/**
4545
* {@link Statement} using the <a href="https://www.postgresql.org/docs/current/static/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY">Extended Query Flow</a>.
4646
*/
47+
@SuppressWarnings("deprecation")
4748
final class ExtendedQueryPostgresqlStatement implements PostgresqlStatement {
4849

4950
private final Bindings bindings;

src/main/java/io/r2dbc/postgresql/PostgresqlConnectionConfiguration.java

+19-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package io.r2dbc.postgresql;
1818

19+
import io.netty.handler.ssl.IdentityCipherSuiteFilter;
20+
import io.netty.handler.ssl.OpenSsl;
21+
import io.netty.handler.ssl.SslContext;
1922
import io.netty.handler.ssl.SslContextBuilder;
2023
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
2124
import io.r2dbc.postgresql.client.DefaultHostnameVerifier;
@@ -28,10 +31,10 @@
2831
import io.r2dbc.postgresql.extension.Extension;
2932
import io.r2dbc.postgresql.util.Assert;
3033
import reactor.netty.resources.LoopResources;
31-
import reactor.netty.tcp.SslProvider;
3234
import reactor.util.annotation.Nullable;
3335

3436
import javax.net.ssl.HostnameVerifier;
37+
import javax.net.ssl.SSLException;
3538
import java.io.File;
3639
import java.io.IOException;
3740
import java.io.InputStream;
@@ -50,7 +53,6 @@
5053
import java.util.function.ToIntFunction;
5154

5255
import static io.r2dbc.postgresql.message.frontend.Execute.NO_LIMIT;
53-
import static reactor.netty.tcp.SslProvider.DefaultConfigurationType.TCP;
5456

5557
/**
5658
* Connection configuration information for connecting to a PostgreSQL database.
@@ -896,7 +898,7 @@ private SSLConfig createSslConfig() {
896898
return new SSLConfig(this.sslMode, createSslProvider(), hostnameVerifier);
897899
}
898900

899-
private Supplier<SslProvider> createSslProvider() {
901+
private Supplier<SslContext> createSslProvider() {
900902
SslContextBuilder sslContextBuilder = SslContextBuilder.forClient();
901903
if (this.sslMode.verifyCertificate()) {
902904
if (this.sslRootCert != null) {
@@ -906,6 +908,13 @@ private Supplier<SslProvider> createSslProvider() {
906908
sslContextBuilder.trustManager(InsecureTrustManagerFactory.INSTANCE);
907909
}
908910

911+
sslContextBuilder.sslProvider(
912+
OpenSsl.isAvailable() ?
913+
io.netty.handler.ssl.SslProvider.OPENSSL :
914+
io.netty.handler.ssl.SslProvider.JDK)
915+
.ciphers(null, IdentityCipherSuiteFilter.INSTANCE)
916+
.applicationProtocolConfig(null);
917+
909918
URL sslKey = this.sslKey;
910919
URL sslCert = this.sslCert;
911920

@@ -941,10 +950,13 @@ private Supplier<SslProvider> createSslProvider() {
941950
});
942951
}
943952

944-
return () -> SslProvider.builder()
945-
.sslContext(this.sslContextBuilderCustomizer.apply(sslContextBuilder))
946-
.defaultConfiguration(TCP)
947-
.build();
953+
return () -> {
954+
try {
955+
return this.sslContextBuilderCustomizer.apply(sslContextBuilder).build();
956+
} catch (SSLException e) {
957+
throw new IllegalStateException("Failed to create SslContext", e);
958+
}
959+
};
948960
}
949961

950962
interface StreamConsumer {

src/main/java/io/r2dbc/postgresql/client/AbstractPostgresSSLHandlerAdapter.java

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ abstract class AbstractPostgresSSLHandlerAdapter extends ChannelInboundHandlerAd
4242
AbstractPostgresSSLHandlerAdapter(ByteBufAllocator alloc, SSLConfig sslConfig) {
4343
this.sslConfig = sslConfig;
4444
this.sslEngine = sslConfig.getSslProvider().get()
45-
.getSslContext()
4645
.newEngine(alloc);
4746
this.handshakeFuture = new CompletableFuture<>();
4847
this.sslHandler = new SslHandler(this.sslEngine);

src/main/java/io/r2dbc/postgresql/client/ReactorNettyClient.java

+1-97
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import io.netty.channel.ChannelHandlerContext;
2323
import io.netty.channel.ChannelOption;
2424
import io.netty.channel.ChannelPipeline;
25-
import io.netty.channel.EventLoopGroup;
26-
import io.netty.channel.epoll.Epoll;
2725
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
2826
import io.netty.handler.logging.LogLevel;
2927
import io.netty.handler.logging.LoggingHandler;
@@ -379,7 +377,7 @@ public static Mono<ReactorNettyClient> connect(ConnectionProvider connectionProv
379377
TcpClient tcpClient = TcpClient.create(connectionProvider).remoteAddress(() -> socketAddress);
380378

381379
if (!(socketAddress instanceof InetSocketAddress)) {
382-
tcpClient = tcpClient.runOn(new SocketLoopResources(connectionSettings.hasLoopResources() ? connectionSettings.getRequiredLoopResources() : TcpResources.get()), true);
380+
tcpClient = tcpClient.runOn(connectionSettings.hasLoopResources() ? connectionSettings.getRequiredLoopResources() : TcpResources.get(), true);
383381
} else {
384382

385383
if (connectionSettings.hasLoopResources()) {
@@ -574,100 +572,6 @@ public ResponseQueueException(String message) {
574572

575573
}
576574

577-
@SuppressWarnings({"deprecation"})
578-
static class SocketLoopResources implements LoopResources {
579-
580-
@Nullable
581-
private static final Class<? extends Channel> EPOLL_SOCKET = findClass("io.netty.channel.epoll.EpollDomainSocketChannel");
582-
583-
@Nullable
584-
private static final Class<? extends Channel> KQUEUE_SOCKET = findClass("io.netty.channel.kqueue.KQueueDomainSocketChannel");
585-
586-
private static final boolean kqueue;
587-
588-
static {
589-
boolean kqueueCheck = false;
590-
try {
591-
Class.forName("io.netty.channel.kqueue.KQueue");
592-
kqueueCheck = io.netty.channel.kqueue.KQueue.isAvailable();
593-
} catch (ClassNotFoundException cnfe) {
594-
}
595-
kqueue = kqueueCheck;
596-
}
597-
598-
private static final boolean epoll;
599-
600-
static {
601-
boolean epollCheck = false;
602-
try {
603-
Class.forName("io.netty.channel.epoll.Epoll");
604-
epollCheck = Epoll.isAvailable();
605-
} catch (ClassNotFoundException cnfe) {
606-
}
607-
epoll = epollCheck;
608-
}
609-
610-
private final LoopResources delegate;
611-
612-
public SocketLoopResources(LoopResources delegate) {
613-
this.delegate = delegate;
614-
}
615-
616-
@SuppressWarnings("unchecked")
617-
private static Class<? extends Channel> findClass(String className) {
618-
try {
619-
return (Class<? extends Channel>) SocketLoopResources.class.getClassLoader().loadClass(className);
620-
} catch (ClassNotFoundException e) {
621-
return null;
622-
}
623-
}
624-
625-
@Override
626-
public Class<? extends Channel> onChannel(EventLoopGroup group) {
627-
628-
if (epoll && EPOLL_SOCKET != null) {
629-
return EPOLL_SOCKET;
630-
}
631-
632-
if (kqueue && KQUEUE_SOCKET != null) {
633-
return KQUEUE_SOCKET;
634-
}
635-
636-
return this.delegate.onChannel(group);
637-
}
638-
639-
@Override
640-
public EventLoopGroup onClient(boolean useNative) {
641-
return this.delegate.onClient(useNative);
642-
}
643-
644-
@Override
645-
public EventLoopGroup onServer(boolean useNative) {
646-
return this.delegate.onServer(useNative);
647-
}
648-
649-
@Override
650-
public EventLoopGroup onServerSelect(boolean useNative) {
651-
return this.delegate.onServerSelect(useNative);
652-
}
653-
654-
@Override
655-
public boolean daemon() {
656-
return this.delegate.daemon();
657-
}
658-
659-
@Override
660-
public void dispose() {
661-
this.delegate.dispose();
662-
}
663-
664-
@Override
665-
public Mono<Void> disposeLater() {
666-
return this.delegate.disposeLater();
667-
}
668-
669-
}
670-
671575
/**
672576
* Value object representing a single conversation. The driver permits a single conversation at a time to ensure that request messages get routed to the proper response receiver and do not leak
673577
* into other conversations. A conversation must be finished in the sense that the {@link Publisher} of {@link FrontendMessage} has completed before the next conversation is started.

src/main/java/io/r2dbc/postgresql/client/SSLConfig.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package io.r2dbc.postgresql.client;
1818

19+
import io.netty.handler.ssl.SslContext;
1920
import io.r2dbc.postgresql.util.Assert;
20-
import reactor.netty.tcp.SslProvider;
2121
import reactor.util.annotation.Nullable;
2222

2323
import javax.net.ssl.HostnameVerifier;
@@ -31,9 +31,9 @@ public final class SSLConfig {
3131
private final SSLMode sslMode;
3232

3333
@Nullable
34-
private final Supplier<SslProvider> sslProvider;
34+
private final Supplier<SslContext> sslProvider;
3535

36-
public SSLConfig(SSLMode sslMode, @Nullable Supplier<SslProvider> sslProvider, @Nullable HostnameVerifier hostnameVerifier) {
36+
public SSLConfig(SSLMode sslMode, @Nullable Supplier<SslContext> sslProvider, @Nullable HostnameVerifier hostnameVerifier) {
3737
if (sslMode != SSLMode.DISABLE) {
3838
Assert.requireNonNull(sslProvider, "Ssl provider is required for ssl mode " + sslMode);
3939
}
@@ -57,7 +57,7 @@ public SSLMode getSslMode() {
5757
return this.sslMode;
5858
}
5959

60-
public Supplier<SslProvider> getSslProvider() {
60+
public Supplier<SslContext> getSslProvider() {
6161
if (this.sslProvider == null) {
6262
throw new IllegalStateException("SSL Mode disabled. SslProvider not available");
6363
}

0 commit comments

Comments
 (0)