Beispiel #1
0
        internal async Task <IEnumerable <IRpcWorkerChannel> > GetInitializedWorkerChannelsAsync()
        {
            Dictionary <string, TaskCompletionSource <IRpcWorkerChannel> > webhostChannelDictionary = _webHostLanguageWorkerChannelManager.GetChannels(_workerRuntime);
            List <IRpcWorkerChannel> webhostChannels = null;

            if (webhostChannelDictionary != null)
            {
                webhostChannels = new List <IRpcWorkerChannel>();
                foreach (string workerId in webhostChannelDictionary.Keys)
                {
                    if (webhostChannelDictionary.TryGetValue(workerId, out TaskCompletionSource <IRpcWorkerChannel> initializedLanguageWorkerChannelTask))
                    {
                        webhostChannels.Add(await initializedLanguageWorkerChannelTask.Task);
                    }
                }
            }
            IEnumerable <IRpcWorkerChannel> workerChannels = webhostChannels == null?_jobHostLanguageWorkerChannelManager.GetChannels() : webhostChannels.Union(_jobHostLanguageWorkerChannelManager.GetChannels());

            IEnumerable <IRpcWorkerChannel> initializedWorkers = workerChannels.Where(ch => ch.State == RpcWorkerChannelState.Initialized);

            if (initializedWorkers.Count() > _maxProcessCount)
            {
                throw new InvalidOperationException($"Number of initialized language workers exceeded:{initializedWorkers.Count()} exceeded maxProcessCount: {_maxProcessCount}");
            }
            return(initializedWorkers);
        }
        internal async Task <IEnumerable <IRpcWorkerChannel> > GetAllWorkerChannelsAsync()
        {
            var webhostChannelDictionary             = _webHostLanguageWorkerChannelManager.GetChannels(_workerRuntime);
            List <IRpcWorkerChannel> webhostChannels = null;

            if (webhostChannelDictionary != null)
            {
                webhostChannels = new List <IRpcWorkerChannel>();
                foreach (var pair in webhostChannelDictionary)
                {
                    var workerChannel = await pair.Value.Task;
                    webhostChannels.Add(workerChannel);
                }
            }

            IEnumerable <IRpcWorkerChannel> workerChannels = webhostChannels == null?_jobHostLanguageWorkerChannelManager.GetChannels() : webhostChannels.Union(_jobHostLanguageWorkerChannelManager.GetChannels());

            return(workerChannels);
        }