io.netty.resolver.AddressResolverGroup Java Examples
The following examples show how to use
io.netty.resolver.AddressResolverGroup.
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: Http2ConnectionProvider.java From reactor-netty with Apache License 2.0 | 6 votes |
PooledConnectionAllocator( ConnectionProvider parent, TransportConfig config, int maxConnections, PoolFactory<Connection> poolFactory, Supplier<SocketAddress> remoteAddress, AddressResolverGroup<?> resolver) { this.parent = parent; this.config = (HttpClientConfig) config; this.initialMaxConnection = maxConnections; this.remoteAddress = remoteAddress; this.resolver = resolver; this.allocationStrategy = new SizeBasedAllocationStrategy(0, maxConnections); this.pool = poolFactory.newPool(connectChannel(), new SizeBasedAllocationStrategy(0, maxConnections), DEFAULT_DESTROY_HANDLER, DEFAULT_EVICTION_PREDICATE); }
Example #2
Source File: DNSMonitor.java From redisson with Apache License 2.0 | 5 votes |
public DNSMonitor(ConnectionManager connectionManager, RedisClient masterHost, Collection<RedisURI> slaveHosts, long dnsMonitoringInterval, AddressResolverGroup<InetSocketAddress> resolverGroup) { this.resolver = resolverGroup.getResolver(connectionManager.getGroup().next()); masterHost.resolveAddr().syncUninterruptibly(); masters.put(masterHost.getConfig().getAddress(), masterHost.getAddr()); for (RedisURI host : slaveHosts) { Future<InetSocketAddress> resolveFuture = resolver.resolve(InetSocketAddress.createUnresolved(host.getHost(), host.getPort())); resolveFuture.syncUninterruptibly(); slaves.put(host, resolveFuture.getNow()); } this.connectionManager = connectionManager; this.dnsMonitoringInterval = dnsMonitoringInterval; }
Example #3
Source File: TransportConnector.java From reactor-netty with Apache License 2.0 | 5 votes |
/** * Connect a {@link Channel} to the remote peer. * * @param config the transport configuration * @param remoteAddress the {@link SocketAddress} to connect to * @param resolverGroup the resolver which will resolve the address of the unresolved named address * @param channelInitializer the {@link ChannelInitializer} that will be used for initializing the channel pipeline * @return a {@link Mono} of {@link Channel} */ public static Mono<Channel> connect(TransportConfig config, SocketAddress remoteAddress, AddressResolverGroup<?> resolverGroup, ChannelInitializer<Channel> channelInitializer) { Objects.requireNonNull(config, "config"); Objects.requireNonNull(remoteAddress, "remoteAddress"); Objects.requireNonNull(resolverGroup, "resolverGroup"); Objects.requireNonNull(channelInitializer, "channelInitializer"); return doInitAndRegister(config, channelInitializer, remoteAddress instanceof DomainSocketAddress) .flatMap(channel -> doResolveAndConnect(channel, config, remoteAddress, resolverGroup)); }
Example #4
Source File: ClientTransport.java From reactor-netty with Apache License 2.0 | 5 votes |
/** * Connect the {@link ClientTransport} and return a {@link Mono} of {@link Connection}. If * {@link Mono} is cancelled, the underlying connection will be aborted. Once the * {@link Connection} has been emitted and is not necessary anymore, disposing must be * done by the user via {@link Connection#dispose()}. * * @return a {@link Mono} of {@link Connection} */ protected Mono<? extends Connection> connect() { CONF config = configuration(); ConnectionObserver observer = config.defaultConnectionObserver().then(config.observer); AddressResolverGroup<?> resolver = config.resolverInternal(); Mono<? extends Connection> mono = config.connectionProvider() .acquire(config, observer, config.remoteAddress, resolver); if (config.doOnConnect != null) { mono = mono.doOnSubscribe(s -> config.doOnConnect.accept(config)); } return mono; }
Example #5
Source File: ClientTransportConfig.java From reactor-netty with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") protected AddressResolverGroup<?> resolverInternal() { if (metricsRecorder != null) { return new AddressResolverGroupMetrics( (AddressResolverGroup<SocketAddress>) resolver, Objects.requireNonNull(metricsRecorder.get(), "Metrics recorder supplier returned null")); } else { return resolver; } }
Example #6
Source File: Http2ConnectionProvider.java From reactor-netty with Apache License 2.0 | 5 votes |
@Override protected InstrumentedPool<Connection> createPool( TransportConfig config, PooledConnectionProvider.PoolFactory<Connection> poolFactory, SocketAddress remoteAddress, AddressResolverGroup<?> resolverGroup) { return new PooledConnectionAllocator(parent, config, maxHttp2Connections, poolFactory, () -> remoteAddress, resolverGroup).pool; }
Example #7
Source File: HttpConnectionProvider.java From reactor-netty with Apache License 2.0 | 5 votes |
@Override public Mono<? extends Connection> acquire( TransportConfig config, ConnectionObserver connectionObserver, @Nullable Supplier<? extends SocketAddress> remoteAddress, @Nullable AddressResolverGroup<?> resolverGroup) { if (((HttpClientConfig) config)._protocols == HttpClientConfig.h11) { return http1ConnectionProvider.acquire(config, connectionObserver, remoteAddress, resolverGroup); } else { return h2ConnectionProviderSupplier.get().acquire(config, connectionObserver, remoteAddress, resolverGroup); } }
Example #8
Source File: ClientFactoryOptionsTest.java From armeria with Apache License 2.0 | 5 votes |
@Override public Stream<? extends Arguments> provideArguments(ExtensionContext context) throws Exception { final Function<? super EventLoopGroup, ? extends EventLoopScheduler> schedulerFactory = eventLoopGroup -> new DefaultEventLoopScheduler(eventLoopGroup, 0, 0, ImmutableList.of()); final Function<? super EventLoopGroup, ? extends AddressResolverGroup<? extends InetSocketAddress>> addressResolverGroupFactory = eventLoopGroup -> new DnsResolverGroupBuilder().build(eventLoopGroup); return Stream.of( arguments(WORKER_GROUP, executors), arguments(SHUTDOWN_WORKER_GROUP_ON_CLOSE, true), arguments(CHANNEL_OPTIONS, ImmutableMap.of()), arguments(EVENT_LOOP_SCHEDULER_FACTORY, schedulerFactory), arguments(ADDRESS_RESOLVER_GROUP_FACTORY, addressResolverGroupFactory), arguments(HTTP2_INITIAL_CONNECTION_WINDOW_SIZE, 1), arguments(HTTP2_INITIAL_STREAM_WINDOW_SIZE, 2), arguments(HTTP2_MAX_FRAME_SIZE, 3), arguments(HTTP2_MAX_HEADER_LIST_SIZE, 4), arguments(HTTP1_MAX_INITIAL_LINE_LENGTH, 5), arguments(HTTP1_MAX_HEADER_SIZE, 6), arguments(HTTP1_MAX_CHUNK_SIZE, 7), arguments(IDLE_TIMEOUT_MILLIS, 8), arguments(USE_HTTP2_PREFACE, true), arguments(USE_HTTP1_PIPELINING, false), arguments(CONNECTION_POOL_LISTENER, ConnectionPoolListener.noop()), arguments(METER_REGISTRY, Metrics.globalRegistry)); }
Example #9
Source File: TcpResources.java From reactor-netty with Apache License 2.0 | 5 votes |
@Override public Mono<? extends Connection> acquire(TransportConfig config, ConnectionObserver observer, @Nullable Supplier<? extends SocketAddress> remoteAddress, @Nullable AddressResolverGroup<?> resolverGroup) { return defaultProvider.acquire(config, observer, remoteAddress, resolverGroup); }
Example #10
Source File: PooledConnectionProvider.java From reactor-netty with Apache License 2.0 | 5 votes |
@Override public final Mono<? extends Connection> acquire( TransportConfig config, ConnectionObserver connectionObserver, @Nullable Supplier<? extends SocketAddress> remote, @Nullable AddressResolverGroup<?> resolverGroup) { Objects.requireNonNull(remote, "remoteAddress"); Objects.requireNonNull(resolverGroup, "resolverGroup"); return Mono.create(sink -> { SocketAddress remoteAddress = Objects.requireNonNull(remote.get(), "Remote Address supplier returned null"); PoolKey holder = new PoolKey(remoteAddress, config.channelHash()); PoolFactory<T> poolFactory = poolFactory(remoteAddress); InstrumentedPool<T> pool = channelPools.computeIfAbsent(holder, poolKey -> { if (log.isDebugEnabled()) { log.debug("Creating a new [{}] client pool [{}] for [{}]", name, poolFactory, remoteAddress); } InstrumentedPool<T> newPool = createPool(config, poolFactory, remoteAddress, resolverGroup); if (poolFactory.metricsEnabled || config.metricsRecorder() != null) { PooledConnectionProviderMetrics.registerMetrics(name, poolKey.hashCode() + "", Metrics.formatSocketAddress(remoteAddress), newPool.metrics()); } return newPool; }); pool.acquire(Duration.ofMillis(poolFactory.pendingAcquireTimeout)) .subscribe(createDisposableAcquire(connectionObserver, config.channelOperationsProvider(), poolFactory.pendingAcquireTimeout, pool, sink)); }); }
Example #11
Source File: DefaultPooledConnectionProvider.java From reactor-netty with Apache License 2.0 | 5 votes |
PooledConnectionAllocator( TransportConfig config, PoolFactory<PooledConnection> provider, SocketAddress remoteAddress, AddressResolverGroup<?> resolver) { this.config = config; this.remoteAddress = remoteAddress; this.resolver = resolver; this.pool = provider.newPool(connectChannel(), null, DEFAULT_DESTROY_HANDLER, DEFAULT_EVICTION_PREDICATE); }
Example #12
Source File: DefaultPooledConnectionProvider.java From reactor-netty with Apache License 2.0 | 5 votes |
@Override protected InstrumentedPool<PooledConnection> createPool( TransportConfig config, PoolFactory<PooledConnection> poolFactory, SocketAddress remoteAddress, AddressResolverGroup<?> resolverGroup) { return new PooledConnectionAllocator(config, poolFactory, remoteAddress, resolverGroup).pool; }
Example #13
Source File: ClientFactoryBuilder.java From armeria with Apache License 2.0 | 4 votes |
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; }
Example #14
Source File: RedisClientConfig.java From redisson with Apache License 2.0 | 4 votes |
public AddressResolverGroup<InetSocketAddress> getResolverGroup() { return resolverGroup; }
Example #15
Source File: RedisClientConfig.java From redisson with Apache License 2.0 | 4 votes |
public RedisClientConfig setResolverGroup(AddressResolverGroup<InetSocketAddress> resolverGroup) { this.resolverGroup = resolverGroup; return this; }
Example #16
Source File: ClientFactoryOptions.java From armeria with Apache License 2.0 | 4 votes |
/** * Returns the factory that creates an {@link AddressResolverGroup} which resolves remote addresses into * {@link InetSocketAddress}es. */ public Function<? super EventLoopGroup, ? extends AddressResolverGroup<? extends InetSocketAddress>> addressResolverGroupFactory() { return get(ClientFactoryOption.ADDRESS_RESOLVER_GROUP_FACTORY); }
Example #17
Source File: HttpClientFactory.java From armeria with Apache License 2.0 | 4 votes |
@VisibleForTesting AddressResolverGroup<InetSocketAddress> addressResolverGroup() { return addressResolverGroup; }
Example #18
Source File: AddressResolverGroupMetrics.java From reactor-netty with Apache License 2.0 | 4 votes |
AddressResolverGroupMetrics(AddressResolverGroup<SocketAddress> resolverGroup, ChannelMetricsRecorder recorder) { this.resolverGroup = resolverGroup; this.recorder = recorder; }
Example #19
Source File: HttpClientFactory.java From armeria with Apache License 2.0 | 4 votes |
HttpClientFactory(ClientFactoryOptions options) { workerGroup = options.workerGroup(); @SuppressWarnings("unchecked") final AddressResolverGroup<InetSocketAddress> group = (AddressResolverGroup<InetSocketAddress>) options.addressResolverGroupFactory() .apply(workerGroup); addressResolverGroup = group; final Bootstrap bootstrap = new Bootstrap(); bootstrap.channel(TransportType.socketChannelType(workerGroup)); bootstrap.resolver(addressResolverGroup); options.channelOptions().forEach((option, value) -> { @SuppressWarnings("unchecked") final ChannelOption<Object> castOption = (ChannelOption<Object>) option; bootstrap.option(castOption, value); }); final ImmutableList<? extends Consumer<? super SslContextBuilder>> tlsCustomizers = ImmutableList.of(options.tlsCustomizer()); shutdownWorkerGroupOnClose = options.shutdownWorkerGroupOnClose(); eventLoopScheduler = options.eventLoopSchedulerFactory().apply(workerGroup); baseBootstrap = bootstrap; sslCtxHttp1Or2 = SslContextUtil.createSslContext(SslContextBuilder::forClient, false, tlsCustomizers); sslCtxHttp1Only = SslContextUtil.createSslContext(SslContextBuilder::forClient, true, tlsCustomizers); http2InitialConnectionWindowSize = options.http2InitialConnectionWindowSize(); http2InitialStreamWindowSize = options.http2InitialStreamWindowSize(); http2MaxFrameSize = options.http2MaxFrameSize(); http2MaxHeaderListSize = options.http2MaxHeaderListSize(); pingIntervalMillis = options.pingIntervalMillis(); http1MaxInitialLineLength = options.http1MaxInitialLineLength(); http1MaxHeaderSize = options.http1MaxHeaderSize(); http1MaxChunkSize = options.http1MaxChunkSize(); idleTimeoutMillis = options.idleTimeoutMillis(); useHttp2Preface = options.useHttp2Preface(); useHttp1Pipelining = options.useHttp1Pipelining(); connectionPoolListener = options.connectionPoolListener(); meterRegistry = options.meterRegistry(); proxyConfig = options.proxyConfig(); this.options = options; clientDelegate = new HttpClientDelegate(this, addressResolverGroup); }
Example #20
Source File: DefaultClientFactory.java From armeria with Apache License 2.0 | 4 votes |
@VisibleForTesting AddressResolverGroup<InetSocketAddress> addressResolverGroup() { return httpClientFactory.addressResolverGroup(); }
Example #21
Source File: HttpClientDelegate.java From armeria with Apache License 2.0 | 4 votes |
HttpClientDelegate(HttpClientFactory factory, AddressResolverGroup<InetSocketAddress> addressResolverGroup) { this.factory = requireNonNull(factory, "factory"); this.addressResolverGroup = requireNonNull(addressResolverGroup, "addressResolverGroup"); }
Example #22
Source File: HttpResourcesTest.java From reactor-netty with Apache License 2.0 | 4 votes |
@Before public void before() { loopDisposed = new AtomicBoolean(); poolDisposed = new AtomicBoolean(); LoopResources loopResources = new LoopResources() { @Override public EventLoopGroup onServer(boolean useNative) { throw new UnsupportedOperationException(); } @Override public Mono<Void> disposeLater(Duration quietPeriod, Duration timeout) { return Mono.<Void>empty().doOnSuccess(c -> loopDisposed.set(true)); } @Override public boolean isDisposed() { return loopDisposed.get(); } }; ConnectionProvider poolResources = new ConnectionProvider() { @Override public Mono<? extends Connection> acquire(TransportConfig config, ConnectionObserver observer, Supplier<? extends SocketAddress> remoteAddress, AddressResolverGroup<?> resolverGroup) { return Mono.never(); } @Override public Mono<Void> disposeLater() { return Mono.<Void>empty().doOnSuccess(c -> poolDisposed.set(true)); } @Override public boolean isDisposed() { return poolDisposed.get(); } }; testResources = new HttpResources(loopResources, poolResources); }
Example #23
Source File: TcpResourcesTest.java From reactor-netty with Apache License 2.0 | 4 votes |
@Before public void before() { loopDisposed = new AtomicBoolean(); poolDisposed = new AtomicBoolean(); LoopResources loopResources = new LoopResources() { @Override public EventLoopGroup onServer(boolean useNative) { throw new UnsupportedOperationException(); } @Override public Mono<Void> disposeLater(Duration quietPeriod, Duration timeout) { return Mono.<Void>empty().doOnSuccess(c -> loopDisposed.set(true)); } @Override public boolean isDisposed() { return loopDisposed.get(); } }; ConnectionProvider poolResources = new ConnectionProvider() { @Override public Mono<? extends Connection> acquire(TransportConfig config, ConnectionObserver observer, Supplier<? extends SocketAddress> remoteAddress, AddressResolverGroup<?> resolverGroup) { return Mono.never(); } @Override public Mono<Void> disposeLater() { return Mono.<Void>empty().doOnSuccess(c -> poolDisposed.set(true)); } @Override public boolean isDisposed() { return poolDisposed.get(); } }; tcpResources = new TcpResources(loopResources, poolResources); }
Example #24
Source File: BootstrapConfig.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
/** * Returns the configured {@link AddressResolverGroup} or the default if non is configured yet.返回已配置的AddressResolverGroup,如果尚未配置,则返回默认值。 */ public AddressResolverGroup<?> resolver() { return bootstrap.resolver(); }
Example #25
Source File: HttpClientConfig.java From reactor-netty with Apache License 2.0 | 4 votes |
@Override protected AddressResolverGroup<?> resolverInternal() { return super.resolverInternal(); }
Example #26
Source File: HttpClientConnect.java From reactor-netty with Apache License 2.0 | 4 votes |
@Override public void subscribe(CoreSubscriber<? super Connection> actual) { HttpClientHandler handler = new HttpClientHandler(config); Mono.<Connection>create(sink -> { HttpClientConfig _config = config; //append secure handler if needed if (handler.toURI.isSecure()) { if (_config.sslProvider == null) { _config = new HttpClientConfig(config); _config.sslProvider = HttpClientSecure.DEFAULT_HTTP_SSL_PROVIDER; } } else { if (_config.sslProvider != null) { _config = new HttpClientConfig(config); _config.sslProvider = null; } } if (_config.sslProvider != null) { if (_config.sslProvider.getDefaultConfigurationType() == null) { if ((_config._protocols & HttpClientConfig.h2) == HttpClientConfig.h2) { _config.sslProvider = SslProvider.updateDefaultConfiguration(_config.sslProvider, SslProvider.DefaultConfigurationType.H2); } else { _config.sslProvider = SslProvider.updateDefaultConfiguration(_config.sslProvider, SslProvider.DefaultConfigurationType.TCP); } } if ((_config._protocols & HttpClientConfig.h2c) == HttpClientConfig.h2c) { sink.error(new IllegalArgumentException( "Configured H2 Clear-Text protocol with TLS. " + "Use the non Clear-Text H2 protocol via HttpClient#protocol or disable TLS " + "via HttpClient#noSSL()")); return; } } else { if ((_config._protocols & HttpClientConfig.h2) == HttpClientConfig.h2) { sink.error(new IllegalArgumentException( "Configured H2 protocol without TLS. Use H2 Clear-Text " + "protocol via HttpClient#protocol or configure TLS via HttpClient#secure")); return; } } ConnectionObserver observer = new HttpObserver(sink, handler) .then(_config.defaultConnectionObserver()) .then(_config.connectionObserver()) .then(new HttpIOHandlerObserver(sink, handler)); AddressResolverGroup<?> resolver = _config.resolverInternal(); _config.connectionProvider() .acquire(_config, observer, handler, resolver) .subscribe(new ClientTransportSubscriber(sink)); }).retryWhen(Retry.indefinitely().filter(handler)) .subscribe(actual); }
Example #27
Source File: PooledConnectionProvider.java From reactor-netty with Apache License 2.0 | 4 votes |
protected abstract InstrumentedPool<T> createPool( TransportConfig config, PoolFactory<T> poolFactory, SocketAddress remoteAddress, AddressResolverGroup<?> resolverGroup);
Example #28
Source File: Bootstrap.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
final AddressResolverGroup<?> resolver() { return resolver; }
Example #29
Source File: ClientTransportConfig.java From reactor-netty with Apache License 2.0 | 2 votes |
/** * Return the {@link AddressResolverGroup} * * @return the {@link AddressResolverGroup} */ public final AddressResolverGroup<?> resolver() { return resolver; }
Example #30
Source File: ConnectionProvider.java From reactor-netty with Apache License 2.0 | 2 votes |
/** * Return an existing or new {@link Connection} on subscribe. * * @param config the transport configuration * @param connectionObserver the {@link ConnectionObserver} * @param remoteAddress the {@link SocketAddress} to connect to * @param resolverGroup the resolver which will resolve the address of the unresolved named address * @return an existing or new {@link Mono} of {@link Connection} */ Mono<? extends Connection> acquire(TransportConfig config, ConnectionObserver connectionObserver, @Nullable Supplier<? extends SocketAddress> remoteAddress, @Nullable AddressResolverGroup<?> resolverGroup);