public static AsyncResolveConnectHelper doBind(VertxInternal vertx, SocketAddress socketAddress, ServerBootstrap bootstrap) { AsyncResolveConnectHelper asyncResolveConnectHelper = new AsyncResolveConnectHelper(); bootstrap.channelFactory(vertx.transport().serverChannelFactory(socketAddress.path() != null)); if (socketAddress.path() != null) { java.net.SocketAddress converted = vertx.transport().convert(socketAddress, true); ChannelFuture future = bootstrap.bind(converted); future.addListener(f -> {
public static Transport transport(boolean preferNative) { if (preferNative) { Transport nativeTransport = Transport.nativeTransport(); if (nativeTransport != null && nativeTransport.isAvailable()) { return nativeTransport; } else { return Transport.JDK; } } else { return Transport.JDK; } }
@Override public void configure(NetServerOptions options, boolean domainSocket, ServerBootstrap bootstrap) { if (!domainSocket) { bootstrap.option(KQueueChannelOption.SO_REUSEPORT, options.isReusePort()); } super.configure(options, domainSocket, bootstrap); }
Bootstrap bootstrap = new Bootstrap(); bootstrap.group(context.nettyEventLoop()); bootstrap.channelFactory(vertx.transport().channelFactory(remoteAddress.path() != null));
ServerBootstrap bs = new ServerBootstrap(); bs.group(context.nettyEventLoop()); bs.channelFactory(((VertxInternal)vertx).transport().serverChannelFactory(false)) ; bs.option(ChannelOption.SO_BACKLOG, 100); bs.childHandler(new ChannelInitializer<SocketChannel>() {
private DatagramSocketImpl(VertxInternal vertx, DatagramSocketOptions options) { Transport transport = vertx.transport(); DatagramChannel channel = transport.datagramChannel(options.isIpV6() ? InternetProtocolFamily.IPv6 : InternetProtocolFamily.IPv4); transport.configure(channel, new DatagramSocketOptions(options)); ContextInternal context = vertx.getOrCreateContext(); channel.config().setOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, true); MaxMessagesRecvByteBufAllocator bufAllocator = channel.config().getRecvByteBufAllocator(); bufAllocator.maxMessagesPerRead(1); context.nettyEventLoop().register(channel); if (options.getLogActivity()) { channel.pipeline().addLast("logging", new LoggingHandler()); } VertxMetrics metrics = vertx.metricsSPI(); this.metrics = metrics != null ? metrics.createDatagramSocketMetrics(options) : null; this.channel = channel; this.context = context; this.demand = Long.MAX_VALUE; }
/** * The native transport, it may be {@code null} or failed. */ public static Transport nativeTransport() { Transport transport = null; try { Transport epoll = new EpollTransport(); if (epoll.isAvailable()) { return epoll; } else { transport = epoll; } } catch (Throwable ignore) { // Jar not here } try { Transport kqueue = new KQueueTransport(); if (kqueue.isAvailable()) { return kqueue; } else if (transport == null) { transport = kqueue; } } catch (Throwable ignore) { // Jar not here } return transport; }
static VertxImpl vertx(VertxOptions options) { VertxImpl vertx = new VertxImpl(options, Transport.transport(options.getPreferNativeTransport())); vertx.init(); return vertx; }
private void handleConnect(SocketAddress remoteAddress, SocketAddress peerAddress, String serverName, Handler<AsyncResult<Channel>> channelHandler) { VertxInternal vertx = context.owner(); bootstrap.resolver(vertx.nettyAddressResolverGroup()); bootstrap.handler(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel ch) { initSSL(peerAddress, serverName, ch, channelHandler); } }); ChannelFuture fut = bootstrap.connect(vertx.transport().convert(remoteAddress, false)); fut.addListener(res -> { if (res.isSuccess()) { connected(fut.channel(), channelHandler); } else { channelHandler.handle(io.vertx.core.Future.failedFuture(res.cause())); } }); }
@Override protected io.netty.resolver.AddressResolver<InetSocketAddress> newResolver(EventExecutor executor) throws Exception { ChannelFactory<DatagramChannel> channelFactory = () -> vertx.transport().datagramChannel(); DnsAddressResolverGroup group = new DnsAddressResolverGroup(channelFactory, nameServerAddressProvider) { @Override
checker = new BlockedThreadChecker(options.getBlockedThreadCheckInterval(), options.getBlockedThreadCheckIntervalUnit(), options.getWarningExceptionTime(), options.getWarningExceptionTimeUnit()); eventLoopThreadFactory = new VertxThreadFactory("vert.x-eventloop-thread-", checker, false, options.getMaxEventLoopExecuteTime(), options.getMaxEventLoopExecuteTimeUnit()); eventLoopGroup = transport.eventLoopGroup(options.getEventLoopPoolSize(), eventLoopThreadFactory, NETTY_IO_RATIO); ThreadFactory acceptorEventLoopThreadFactory = new VertxThreadFactory("vert.x-acceptor-thread-", checker, false, options.getMaxEventLoopExecuteTime(), options.getMaxEventLoopExecuteTimeUnit()); acceptorEventLoopGroup = transport.eventLoopGroup(1, acceptorEventLoopThreadFactory, 100);
bootstrap.channelFactory(client.getVertx().transport().channelFactory(false));
ServerBootstrap bs = new ServerBootstrap(); bs.group(context.nettyEventLoop()); bs.channelFactory(((VertxInternal)vertx).transport().serverChannelFactory(false)) ; bs.option(ChannelOption.SO_BACKLOG, 100); bs.childHandler(new ChannelInitializer<SocketChannel>() {
private DatagramSocketImpl(VertxInternal vertx, DatagramSocketOptions options) { Transport transport = vertx.transport(); DatagramChannel channel = transport.datagramChannel(options.isIpV6() ? InternetProtocolFamily.IPv6 : InternetProtocolFamily.IPv4); transport.configure(channel, new DatagramSocketOptions(options)); ContextInternal context = vertx.getOrCreateContext(); if (context.isMultiThreadedWorkerContext()) { throw new IllegalStateException("Cannot use DatagramSocket in a multi-threaded worker verticle"); } channel.config().setOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, true); MaxMessagesRecvByteBufAllocator bufAllocator = channel.config().getRecvByteBufAllocator(); bufAllocator.maxMessagesPerRead(1); context.nettyEventLoop().register(channel); if (options.getLogActivity()) { channel.pipeline().addLast("logging", new LoggingHandler()); } VertxMetrics metrics = vertx.metricsSPI(); this.metrics = metrics != null ? metrics.createDatagramSocketMetrics(options) : null; this.channel = channel; this.context = context; this.demand = Long.MAX_VALUE; }
/** * The native transport, it may be {@code null} or failed. */ public static Transport nativeTransport() { Transport transport = null; try { Transport epoll = new EpollTransport(); if (epoll.isAvailable()) { return epoll; } else { transport = epoll; } } catch (Throwable ignore) { // Jar not here } try { Transport kqueue = new KQueueTransport(); if (kqueue.isAvailable()) { return kqueue; } else if (transport == null) { transport = kqueue; } } catch (Throwable ignore) { // Jar not here } return transport; }
static void clusteredVertx(VertxOptions options, Handler<AsyncResult<Vertx>> resultHandler) { VertxImpl vertx = new VertxImpl(options, Transport.transport(options.getPreferNativeTransport())); vertx.joinCluster(options, resultHandler); }
java.net.SocketAddress targetAddress = vertx.transport().convert(remoteAddress, false);
channel = transport.datagramChannel(this.dnsServer.getAddress() instanceof Inet4Address ? InternetProtocolFamily.IPv4 : InternetProtocolFamily.IPv6); channel.config().setOption(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, true); MaxMessagesRecvByteBufAllocator bufAllocator = channel.config().getRecvByteBufAllocator();
checker = new BlockedThreadChecker(options.getBlockedThreadCheckInterval(), options.getBlockedThreadCheckIntervalUnit(), options.getWarningExceptionTime(), options.getWarningExceptionTimeUnit()); eventLoopThreadFactory = new VertxThreadFactory("vert.x-eventloop-thread-", checker, false, options.getMaxEventLoopExecuteTime(), options.getMaxEventLoopExecuteTimeUnit()); eventLoopGroup = transport.eventLoopGroup(options.getEventLoopPoolSize(), eventLoopThreadFactory, NETTY_IO_RATIO); ThreadFactory acceptorEventLoopThreadFactory = new VertxThreadFactory("vert.x-acceptor-thread-", checker, false, options.getMaxEventLoopExecuteTime(), options.getMaxEventLoopExecuteTimeUnit()); acceptorEventLoopGroup = transport.eventLoopGroup(1, acceptorEventLoopThreadFactory, 100);
CountDownLatch connectLatch = new CountDownLatch(1); Bootstrap bootstrap = new Bootstrap(); bootstrap.channelFactory(((VertxInternal)vertx).transport().channelFactory(false)); bootstrap.group(vertx.nettyEventLoopGroup()); bootstrap.resolver(((VertxInternal) vertx).nettyAddressResolverGroup());