/// <summary> /// Creates a new <see cref="SimpleChannelPool"/> instance. /// </summary> /// <param name="bootstrap">The <see cref="Bootstrapping.Bootstrap"/> that is used for connections.</param> /// <param name="handler"> /// The <see cref="IChannelPoolHandler"/> that will be notified for the different pool actions. /// </param> /// <param name="healthChecker"> /// The <see cref="IChannelHealthChecker"/> that will be used to check if a <see cref="IChannel"/> is still /// healthy when obtained from the <see cref="IChannelPool"/>. /// </param> /// <param name="releaseHealthCheck"> /// If <c>true</c>, will check channel health before offering back. Otherwise, channel health is only checked /// at acquisition time. /// </param> /// <param name="lastRecentUsed"> /// If <c>true</c>, <see cref="IChannel"/> selection will be LIFO. If <c>false</c>, it will be FIFO. /// </param> public SimpleChannelPool(Bootstrap bootstrap, IChannelPoolHandler handler, IChannelHealthChecker healthChecker, bool releaseHealthCheck, bool lastRecentUsed) { if (handler is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.handler); } if (healthChecker is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.healthChecker); } if (bootstrap is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.bootstrap); } Handler = handler; HealthChecker = healthChecker; ReleaseHealthCheck = releaseHealthCheck; // Clone the original Bootstrap as we want to set our own handler Bootstrap = bootstrap.Clone(); _ = Bootstrap.Handler(new ActionChannelInitializer <IChannel>(OnChannelInitializing)); _store = lastRecentUsed ? (IQueue <IChannel>) new CompatibleConcurrentStack <IChannel>() : new CompatibleConcurrentQueue <IChannel>(); }
protected override HttpChannelPool NewPool(NettyFullAddress key) { /* * When there is a proxy configured, the client must not try to resolve the server address * because the server could be on a network unreachable to the client */ Bootstrap poolBootstrap = cb.Clone(); poolBootstrap.RemoteAddress(key.Address); if (log.IsDebugEnabled) { log.Debug("New HTTP channel pool created. Remote address: " + key.Address); } IChannelPoolHandler handler = outerInstance.decorateChannelPoolHandler(new HttpChannelPoolHandler(key)); return(new HttpChannelPool(key, poolBootstrap, handler)); }
/// <summary> /// Creates a new <see cref="SimpleChannelPool"/> instance. /// </summary> /// <param name="bootstrap">The <see cref="Bootstrapping.Bootstrap"/> that is used for connections.</param> /// <param name="handler"> /// The <see cref="IChannelPoolHandler"/> that will be notified for the different pool actions. /// </param> /// <param name="healthChecker"> /// The <see cref="IChannelHealthChecker"/> that will be used to check if a <see cref="IChannel"/> is still /// healthy when obtained from the <see cref="IChannelPool"/>. /// </param> /// <param name="releaseHealthCheck"> /// If <c>true</c>, will check channel health before offering back. Otherwise, channel health is only checked /// at acquisition time. /// </param> /// <param name="lastRecentUsed"> /// If <c>true</c>, <see cref="IChannel"/> selection will be LIFO. If <c>false</c>, it will be FIFO. /// </param> public SimpleChannelPool(Bootstrap bootstrap, IChannelPoolHandler handler, IChannelHealthChecker healthChecker, bool releaseHealthCheck, bool lastRecentUsed) { Contract.Requires(handler != null); Contract.Requires(healthChecker != null); Contract.Requires(bootstrap != null); this.Handler = handler; this.HealthChecker = healthChecker; this.ReleaseHealthCheck = releaseHealthCheck; // Clone the original Bootstrap as we want to set our own handler this.Bootstrap = bootstrap.Clone(); this.Bootstrap.Handler(new ActionChannelInitializer <IChannel>(this.OnChannelInitializing)); this.store = lastRecentUsed ? (IQueue <IChannel>) new CompatibleConcurrentStack <IChannel>() : new CompatibleConcurrentQueue <IChannel>(); }
public virtual ValueTask <IChannel> AcquireAsync() { if (!TryPollChannel(out IChannel channel)) { Bootstrap bs = Bootstrap.Clone(); _ = bs.Attribute(PoolKey, this); return(new ValueTask <IChannel>(ConnectChannel(bs))); } IEventLoop eventLoop = channel.EventLoop; if (eventLoop.InEventLoop) { return(DoHealthCheck(channel)); } else { var completionSource = new TaskCompletionSource <IChannel>(); eventLoop.Execute(DoHealthCheck, channel, completionSource); return(new ValueTask <IChannel>(completionSource.Task)); } }