io.netty.channel.epoll.EpollDatagramChannel#io.netty.resolver.DefaultAddressResolverGroup源码实例Demo

下面列出了io.netty.channel.epoll.EpollDatagramChannel#io.netty.resolver.DefaultAddressResolverGroup 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: reactor-netty   文件: ClientTransportConfig.java
protected ClientTransportConfig(ConnectionProvider connectionProvider, Map<ChannelOption<?>, ?> options,
		Supplier<? extends SocketAddress> remoteAddress) {
	super(options);
	this.connectionProvider = Objects.requireNonNull(connectionProvider, "connectionProvider");
	this.remoteAddress = Objects.requireNonNull(remoteAddress, "remoteAddress");
	this.resolver = DefaultAddressResolverGroup.INSTANCE;
}
 
源代码2 项目: PowerTunnel   文件: ProxyToServerConnection.java
/**
 * Set up our connection parameters based on server address and chained
 * proxies.
 *
 * @throws UnknownHostException when unable to resolve the hostname to an IP address
 */
private void setupConnectionParameters() throws UnknownHostException {
    if (chainedProxy != null
            && chainedProxy != ChainedProxyAdapter.FALLBACK_TO_DIRECT_CONNECTION) {
        this.transportProtocol = chainedProxy.getTransportProtocol();
        this.chainedProxyType = chainedProxy.getChainedProxyType();
        this.localAddress = chainedProxy.getLocalAddress();
        this.remoteAddress = chainedProxy.getChainedProxyAddress();
        this.remoteAddressResolver = DefaultAddressResolverGroup.INSTANCE;
        this.username = chainedProxy.getUsername();
        this.password = chainedProxy.getPassword();
    } else {
        this.transportProtocol = TransportProtocol.TCP;
        this.chainedProxyType = ChainedProxyType.HTTP;
        this.username = null;
        this.password = null;

        // Report DNS resolution to HttpFilters
        this.remoteAddress = this.currentFilters.proxyToServerResolutionStarted(serverHostAndPort);

        // save the hostname and port of the unresolved address in hostAndPort, in case name resolution fails
        String hostAndPort = null;
        try {
            if (this.remoteAddress == null) {
                hostAndPort = serverHostAndPort;
                this.remoteAddress = addressFor(serverHostAndPort, proxyServer);
            } else if (this.remoteAddress.isUnresolved()) {
                // filter returned an unresolved address, so resolve it using the proxy server's resolver
                hostAndPort = HostAndPort.fromParts(this.remoteAddress.getHostName(), this.remoteAddress.getPort()).toString();
                this.remoteAddress = proxyServer.getServerResolver().resolve(this.remoteAddress.getHostName(),
                        this.remoteAddress.getPort());
            }
        } catch (UnknownHostException e) {
            // unable to resolve the hostname to an IP address. notify the filters of the failure before allowing the
            // exception to bubble up.
            this.currentFilters.proxyToServerResolutionFailed(hostAndPort);

            throw e;
        }

        this.currentFilters.proxyToServerResolutionSucceeded(serverHostAndPort, this.remoteAddress);


        this.localAddress = proxyServer.getLocalAddress();
    }
}
 
源代码3 项目: reactor-netty   文件: TcpClientTests.java
@Test
@SuppressWarnings("deprecation")
public void testBootstrap() {
	DisposableServer server =
			TcpServer.create()
			         .port(0)
			         .handle((req, res) -> res.send(req.receive()
			                                           .retain()))
			         .wiretap(true)
			         .bindNow();

	AtomicInteger invoked = new AtomicInteger();
	Connection conn =
			TcpClient.create()
			         .bootstrap(b ->
			             b.attr(AttributeKey.valueOf("testBootstrap"), "testBootstrap")
			              .group(new NioEventLoopGroup())
			              .option(ChannelOption.valueOf("testBootstrap"), "testBootstrap")
			              .remoteAddress(server.address())
			              .resolver(DefaultAddressResolverGroup.INSTANCE)
			              .handler(new ChannelInboundHandlerAdapter() {
			                  @Override
			                  public void channelActive(ChannelHandlerContext ctx) throws Exception {
			                      invoked.set(1);
			                      super.channelActive(ctx);
			                  }
			              }))
			         .connectNow();

	conn.outbound()
	    .sendString(Mono.just("testBootstrap"))
	    .then()
	    .subscribe();

	String result =
			conn.inbound()
			    .receive()
			    .asString()
			    .blockFirst();

	assertEquals("testBootstrap", result);
	assertEquals(1, invoked.get());

	conn.disposeNow();
	server.disposeNow();
}
 
源代码4 项目: armeria   文件: ClientFactoryBuilder.java
private ClientFactoryOptions buildOptions() {
    options.computeIfAbsent(ClientFactoryOption.EVENT_LOOP_SCHEDULER_FACTORY, k -> {
        final Function<? super EventLoopGroup, ? extends EventLoopScheduler> eventLoopSchedulerFactory =
                eventLoopGroup -> new DefaultEventLoopScheduler(
                        eventLoopGroup, maxNumEventLoopsPerEndpoint, maxNumEventLoopsPerHttp1Endpoint,
                        maxNumEventLoopsFunctions);
        return ClientFactoryOption.EVENT_LOOP_SCHEDULER_FACTORY.newValue(eventLoopSchedulerFactory);
    });

    options.computeIfAbsent(ClientFactoryOption.ADDRESS_RESOLVER_GROUP_FACTORY, k -> {
        final Function<? super EventLoopGroup,
                ? extends AddressResolverGroup<? extends InetSocketAddress>> addressResolverGroupFactory =
                eventLoopGroup -> {
                    // FIXME(ikhoon): Remove DefaultAddressResolverGroup registration after fixing Window
                    //                domain name resolution failure.
                    //                https://github.com/line/armeria/issues/2243
                    if (Flags.useJdkDnsResolver() && dnsResolverGroupCustomizers == null) {
                        return DefaultAddressResolverGroup.INSTANCE;
                    }
                    final DnsResolverGroupBuilder builder = new DnsResolverGroupBuilder();
                    if (dnsResolverGroupCustomizers != null) {
                        dnsResolverGroupCustomizers.forEach(consumer -> consumer.accept(builder));
                    }
                    return builder.build(eventLoopGroup);
                };
        return ClientFactoryOption.ADDRESS_RESOLVER_GROUP_FACTORY.newValue(addressResolverGroupFactory);
    });

    final ClientFactoryOptions newOptions = ClientFactoryOptions.of(options.values());
    final long idleTimeoutMillis = newOptions.idleTimeoutMillis();
    final long pingIntervalMillis = newOptions.pingIntervalMillis();
    if (idleTimeoutMillis > 0 && pingIntervalMillis > 0) {
        final long clampedPingIntervalMillis = Math.max(pingIntervalMillis, MIN_PING_INTERVAL_MILLIS);
        if (clampedPingIntervalMillis >= idleTimeoutMillis) {
            return ClientFactoryOptions.of(newOptions, ZERO_PING_INTERVAL);
        }
        if (pingIntervalMillis == MIN_PING_INTERVAL_MILLIS) {
            return newOptions;
        }
        if (clampedPingIntervalMillis == MIN_PING_INTERVAL_MILLIS) {
            return ClientFactoryOptions.of(newOptions, MIN_PING_INTERVAL);
        }
    }
    return newOptions;
}
 
源代码5 项目: armeria   文件: ClientFactoryBuilderTest.java
@Test
@EnabledIfSystemProperty(named = "com.linecorp.armeria.useJdkDnsResolver", matches = "true")
void useDefaultAddressResolverGroup() {
    final DefaultClientFactory clientFactory = (DefaultClientFactory) ClientFactory.ofDefault();
    assertThat(clientFactory.addressResolverGroup()).isSameAs(DefaultAddressResolverGroup.INSTANCE);
}
 
源代码6 项目: redisson   文件: MasterSlaveConnectionManager.java
protected MasterSlaveConnectionManager(Config cfg, UUID id) {
    this.id = id.toString();
    Version.logVersion();

    if (cfg.getTransportMode() == TransportMode.EPOLL) {
        if (cfg.getEventLoopGroup() == null) {
            this.group = new EpollEventLoopGroup(cfg.getNettyThreads(), new DefaultThreadFactory("redisson-netty"));
        } else {
            this.group = cfg.getEventLoopGroup();
        }

        this.socketChannelClass = EpollSocketChannel.class;
        if (PlatformDependent.isAndroid()) {
            this.resolverGroup = DefaultAddressResolverGroup.INSTANCE;
        } else {
            this.resolverGroup = cfg.getAddressResolverGroupFactory().create(EpollDatagramChannel.class, DnsServerAddressStreamProviders.platformDefault());
        }
    } else if (cfg.getTransportMode() == TransportMode.KQUEUE) {
        if (cfg.getEventLoopGroup() == null) {
            this.group = new KQueueEventLoopGroup(cfg.getNettyThreads(), new DefaultThreadFactory("redisson-netty"));
        } else {
            this.group = cfg.getEventLoopGroup();
        }

        this.socketChannelClass = KQueueSocketChannel.class;
        if (PlatformDependent.isAndroid()) {
            this.resolverGroup = DefaultAddressResolverGroup.INSTANCE;
        } else {
            this.resolverGroup = cfg.getAddressResolverGroupFactory().create(KQueueDatagramChannel.class, DnsServerAddressStreamProviders.platformDefault());
        }
    } else {
        if (cfg.getEventLoopGroup() == null) {
            this.group = new NioEventLoopGroup(cfg.getNettyThreads(), new DefaultThreadFactory("redisson-netty"));
        } else {
            this.group = cfg.getEventLoopGroup();
        }

        this.socketChannelClass = NioSocketChannel.class;
        if (PlatformDependent.isAndroid()) {
            this.resolverGroup = DefaultAddressResolverGroup.INSTANCE;
        } else {
            this.resolverGroup = cfg.getAddressResolverGroupFactory().create(NioDatagramChannel.class, DnsServerAddressStreamProviders.platformDefault());
        }
    }
    
    if (cfg.getExecutor() == null) {
        int threads = Runtime.getRuntime().availableProcessors() * 2;
        if (cfg.getThreads() != 0) {
            threads = cfg.getThreads();
        }
        executor = Executors.newFixedThreadPool(threads, new DefaultThreadFactory("redisson"));
    } else {
        executor = cfg.getExecutor();
    }

    this.cfg = cfg;
    this.codec = cfg.getCodec();
    this.commandExecutor = new CommandSyncService(this);
}