public async virtual ValueTask <IChannel> AcquireNewOr(long timeout)
        {
            IChannel chl;
            bool     b = this.store.TryDequeue(out chl);


            this.timeout = timeout;
            if (!b)
            {
                Bootstrap bs = this.bootstrap.Clone();
                //Bootstrap bs =  new Bootstrap();
                bs.Attribute(PoolKey, this);

                log.Debug(" ... try get parent pool channel ... " + parentPool);
                try
                {
                    IChannel chnl = await parentPool.AcquireAsync();

                    log.Debug(" ... Channel " + chnl);

                    await ConnectChannel(chnl, timeout);

                    return(chnl);
                }
                catch (Exception e)
                {
                    log.Error("Something went wromg here: .. " + e.Message);
                }

                return(null);
            }

            IEventLoop eventLoop = chl.EventLoop;

            if (eventLoop.InEventLoop)
            {
                return(await this.DoHealthCheck(chl, timeout));
            }
            else
            {
                var completionSource = new TaskCompletionSource <IChannel>();
                eventLoop.Execute(this.DoHealthCheck, chl, completionSource);
                return(await completionSource.Task);
            }
            // return acquire(bootstrap.Config().group().next().newPromise<IChannel>());
        }
コード例 #2
0
        public virtual ValueTask <IChannel> AcquireAsync()
        {
            if (!this.TryPollChannel(out IChannel channel))
            {
                Bootstrap bs = this.Bootstrap.Clone();
                bs.Attribute(PoolKey, this);
                return(new ValueTask <IChannel>(this.ConnectChannel(bs)));
            }

            IEventLoop eventLoop = channel.EventLoop;

            if (eventLoop.InEventLoop)
            {
                return(this.DoHealthCheck(channel));
            }
            else
            {
                var completionSource = new TaskCompletionSource <IChannel>();
                eventLoop.Execute(this.DoHealthCheck, channel, completionSource);
                return(new ValueTask <IChannel>(completionSource.Task));
            }
        }