Skip to content

Commit

Permalink
Avoid using reflection in the transports so substrateVM can build nat…
Browse files Browse the repository at this point in the history
…ive images without having to manually whilelist classes

Signed-off-by: Paulo Lopes <paulo@mlopes.net>
  • Loading branch information
pmlopes committed Jul 6, 2018
1 parent efc3b56 commit a4d661b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 37 deletions.
Expand Up @@ -129,7 +129,7 @@ private void doConnect(

Bootstrap bootstrap = new Bootstrap();
bootstrap.group(context.nettyEventLoop());
bootstrap.channel(client.getVertx().transport().channelType(false));
bootstrap.channelFactory(client.getVertx().transport().channelType(false));

applyConnectionOptions(bootstrap);

Expand Down
Expand Up @@ -66,7 +66,7 @@ private static void checkPort(int port) {
public static AsyncResolveConnectHelper doBind(VertxInternal vertx, SocketAddress socketAddress,
ServerBootstrap bootstrap) {
AsyncResolveConnectHelper asyncResolveConnectHelper = new AsyncResolveConnectHelper();
bootstrap.channel(vertx.transport().serverChannelType(socketAddress.path() != null));
bootstrap.channelFactory(vertx.transport().serverChannelType(socketAddress.path() != null));
if (socketAddress.path() != null) {
java.net.SocketAddress converted = vertx.transport().convert(socketAddress, true);
ChannelFuture future = bootstrap.bind(converted);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/vertx/core/net/impl/NetClientImpl.java
Expand Up @@ -175,7 +175,7 @@ protected void doConnect(SocketAddress remoteAddress, String serverName, Handler
sslHelper.validate(vertx);
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(context.nettyEventLoop());
bootstrap.channel(vertx.transport().channelType(remoteAddress.path() != null));
bootstrap.channelFactory(vertx.transport().channelType(remoteAddress.path() != null));

applyConnectionOptions(bootstrap);

Expand Down
17 changes: 7 additions & 10 deletions src/main/java/io/vertx/core/net/impl/transport/EpollTransport.java
Expand Up @@ -13,10 +13,7 @@

import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.ServerChannel;
import io.netty.channel.*;
import io.netty.channel.epoll.Epoll;
import io.netty.channel.epoll.EpollChannelOption;
import io.netty.channel.epoll.EpollDatagramChannel;
Expand Down Expand Up @@ -108,19 +105,19 @@ public DatagramChannel datagramChannel(InternetProtocolFamily family) {
}

@Override
public Class<? extends Channel> channelType(boolean domain) {
public ChannelFactory<? extends Channel> channelType(boolean domain) {
if (domain) {
return EpollDomainSocketChannel.class;
return EpollDomainSocketChannel::new;
} else {
return EpollSocketChannel.class;
return EpollSocketChannel::new;
}
}

public Class<? extends ServerChannel> serverChannelType(boolean domain) {
public ChannelFactory<? extends ServerChannel> serverChannelType(boolean domain) {
if (domain) {
return EpollServerDomainSocketChannel.class;
return EpollServerDomainSocketChannel::new;
}
return EpollServerSocketChannel.class;
return EpollServerSocketChannel::new;
}

@Override
Expand Down
Expand Up @@ -12,13 +12,9 @@
package io.vertx.core.net.impl.transport;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.ServerChannel;
import io.netty.channel.*;
import io.netty.channel.epoll.EpollChannelOption;
import io.netty.channel.kqueue.KQueue;
import io.netty.channel.kqueue.KQueueChannelOption;
import io.netty.channel.kqueue.KQueueDatagramChannel;
import io.netty.channel.kqueue.KQueueDomainSocketChannel;
import io.netty.channel.kqueue.KQueueEventLoopGroup;
Expand All @@ -27,7 +23,6 @@
import io.netty.channel.kqueue.KQueueSocketChannel;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.socket.InternetProtocolFamily;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.unix.DomainSocketAddress;
import io.vertx.core.net.NetServerOptions;

Expand Down Expand Up @@ -84,20 +79,20 @@ public DatagramChannel datagramChannel(InternetProtocolFamily family) {
}

@Override
public Class<? extends Channel> channelType(boolean domain) {
public ChannelFactory<? extends Channel> channelType(boolean domain) {
if (domain) {
return KQueueDomainSocketChannel.class;
return KQueueDomainSocketChannel::new;
} else {
return KQueueSocketChannel.class;
return KQueueSocketChannel::new;
}
}

@Override
public Class<? extends ServerChannel> serverChannelType(boolean domain) {
public ChannelFactory<? extends ServerChannel> serverChannelType(boolean domain) {
if (domain) {
return KQueueServerDomainSocketChannel.class;
return KQueueServerDomainSocketChannel::new;
} else {
return KQueueServerSocketChannel.class;
return KQueueServerSocketChannel::new;
}
}

Expand Down
15 changes: 5 additions & 10 deletions src/main/java/io/vertx/core/net/impl/transport/Transport.java
Expand Up @@ -13,11 +13,7 @@

import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.ServerChannel;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.socket.InternetProtocolFamily;
Expand All @@ -34,7 +30,6 @@
import java.net.SocketAddress;
import java.net.SocketException;
import java.util.concurrent.ThreadFactory;
import java.util.function.BiConsumer;

/**
* The transport used by a {@link io.vertx.core.Vertx} instance.
Expand Down Expand Up @@ -151,22 +146,22 @@ public DatagramChannel datagramChannel(InternetProtocolFamily family) {
* @return the type for channel
* @param domain whether to create a unix domain channel or a socket channel
*/
public Class<? extends Channel> channelType(boolean domain) {
public ChannelFactory<? extends Channel> channelType(boolean domain) {
if (domain) {
throw new IllegalArgumentException();
}
return NioSocketChannel.class;
return NioSocketChannel::new;
}

/**
* @return the type for server channel
* @param domain whether to create a server unix domain channel or a regular server socket channel
*/
public Class<? extends ServerChannel> serverChannelType(boolean domain) {
public ChannelFactory<? extends ServerChannel> serverChannelType(boolean domain) {
if (domain) {
throw new IllegalArgumentException();
}
return NioServerSocketChannel.class;
return NioServerSocketChannel::new;
}

public void configure(DatagramChannel channel, DatagramSocketOptions options) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/vertx/test/core/EventLoopGroupTest.java
Expand Up @@ -61,7 +61,7 @@ public void testNettyServerUsesContextEventLoop() throws Exception {
awaitLatch(latch);
ServerBootstrap bs = new ServerBootstrap();
bs.group(context.nettyEventLoop());
bs.channel(((VertxInternal)vertx).transport().serverChannelType(false)) ;
bs.channelFactory(((VertxInternal)vertx).transport().serverChannelType(false)) ;
bs.option(ChannelOption.SO_BACKLOG, 100);
bs.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
Expand Down
Expand Up @@ -311,7 +311,7 @@ public void testAsyncResolveConnectIsNotifiedOnChannelEventLoop() throws Excepti
AtomicReference<Thread> channelThread = new AtomicReference<>();
CountDownLatch connectLatch = new CountDownLatch(1);
Bootstrap bootstrap = new Bootstrap();
bootstrap.channel(((VertxInternal)vertx).transport().channelType(false));
bootstrap.channelFactory(((VertxInternal)vertx).transport().channelType(false));
bootstrap.group(vertx.nettyEventLoopGroup());
bootstrap.resolver(((VertxInternal) vertx).nettyAddressResolverGroup());
bootstrap.handler(new ChannelInitializer<Channel>() {
Expand Down

0 comments on commit a4d661b

Please sign in to comment.