Java Code Examples for io.netty.resolver.DefaultAddressResolverGroup#INSTANCE

The following examples show how to use io.netty.resolver.DefaultAddressResolverGroup#INSTANCE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientTransportConfig.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 2
Source File: ProxyToServerConnection.java    From PowerTunnel with MIT License 4 votes vote down vote up
/**
 * 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();
    }
}
 
Example 3
Source File: MasterSlaveConnectionManager.java    From redisson with Apache License 2.0 4 votes vote down vote up
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);
}