Exemple #1
0
        private ThreadExecutor <T> AddThreadExecutor(string itemKey)
        {
            ModuleProc         PROC     = new ModuleProc(DYN_MODULE_NAME, "Initialize");
            ThreadExecutor <T> executor = null;

            try
            {
                IThreadSafeQueue <ThreadExecutorItem <T> > threadQueue = null;

                if (_kernelModeQueue)
                {
                    threadQueue = new BlockingBoundQueueKernel <ThreadExecutorItem <T> >(this.ThreadExecutorService, this.QueueCapacity);
                }
                else
                {
                    threadQueue = new BlockingBoundQueueUser <ThreadExecutorItem <T> >(this.ThreadExecutorService, this.QueueCapacity);
                }

                executor                       = new ThreadExecutor <T>(this.ThreadExecutorService, threadQueue, false, itemKey);
                executor.ProcessItem          += new ExecutorProcessItemHandler <T>(OnExecutor_ProcessItem);
                executor.ProcessItemCompleted += new ExecutorProcessItemCompletedHandler <T>(OnExecutor_ProcessItemCompleted);
                _activeWorkersCount.Add(itemKey, new ThreadHashValue()
                {
                    Executor  = executor,
                    ItemCount = 0
                });
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }

            return(executor);
        }
Exemple #2
0
        private void Initialize(bool checkItemCount)
        {
            ModuleProc PROC = new ModuleProc(DYN_MODULE_NAME, "Initialize");

            try
            {
                _uniqueKey = "QueueThreadsThreadPoolExecutor_" + Guid.NewGuid().ToString();
                Log.InfoV(PROC, "{0} : Capacity : {1:D}, Queue Capacity : {2:D}", _uniqueKey, this.Capacity, this.QueueCapacity);

                this.RegisterForShutdown();
                this.ExecutorService.AddExecutor(this);

                _workerThreads      = new List <ThreadExecutor <T> >();
                _activeWorkersCount = new SortedDictionary <string, ThreadHashValue>(StringComparer.InvariantCultureIgnoreCase);
                _workerThreadItems  = new SortedDictionary <int, int>();
                _rnd = new Random(0);

                for (int i = 0; i < this.Capacity; i++)
                {
                    IThreadSafeQueue <ThreadExecutorItem <T> > threadQueue = null;

                    if (_kernelModeQueue)
                    {
                        threadQueue = new BlockingBoundQueueKernel <ThreadExecutorItem <T> >(this.ThreadExecutorService, this.QueueCapacity);
                    }
                    else
                    {
                        threadQueue = new BlockingBoundQueueUser <ThreadExecutorItem <T> >(this.ThreadExecutorService, this.QueueCapacity);
                    }

                    ThreadExecutor <T> executor = new ThreadExecutor <T>(this.ThreadExecutorService, threadQueue, checkItemCount, string.Empty);
                    executor.ProcessItem          += new ExecutorProcessItemHandler <T>(OnExecutor_ProcessItem);
                    executor.ProcessItemCompleted += new ExecutorProcessItemCompletedHandler <T>(OnExecutor_ProcessItemCompleted);
                    executor.ContainerIndex        = i;
                    _workerThreads.Add(executor);
                    _activeWorkersCount.Add(executor.UniqueKey, new ThreadHashValue()
                    {
                        Executor  = executor,
                        ItemCount = 0
                    });
                    if (!_workerThreadItems.ContainsKey(i))
                    {
                        _workerThreadItems.Add(i, 0);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }
        }
        private void Initialize(bool kernelModeQueue)
        {
            ModuleProc PROC = new ModuleProc(DYN_MODULE_NAME, "Initialize");

            try
            {
                _uniqueKey = "FreeThreadPoolExecutor_" + Guid.NewGuid().ToString();
                this.RegisterForShutdown();
                this.ExecutorService.AddExecutor(this);
                Log.InfoV(PROC, "{0} : Capacity : {1:D}", _uniqueKey, this.Capacity);

                _workersFree     = new LinkedList <ThreadExecutor <T> >();
                _workersRunning  = new SortedDictionary <string, ThreadExecutor <T> >(StringComparer.InvariantCultureIgnoreCase);
                _workerSequences = new SortedDictionary <string, List <ThreadExecutorItem <T> > >(StringComparer.InvariantCultureIgnoreCase);

                for (int i = 0; i < this.Capacity; i++)
                {
                    IThreadSafeQueue <ThreadExecutorItem <T> > threadQueue = null;

                    if (kernelModeQueue)
                    {
                        threadQueue = new BlockingBoundQueueKernel <ThreadExecutorItem <T> >(this.ExecutorService, 1);
                    }
                    else
                    {
                        threadQueue = new BlockingBoundQueueUser <ThreadExecutorItem <T> >(this.ExecutorService, 1);
                    }

                    ThreadExecutor <T> executor = new ThreadExecutor <T>(this.ExecutorService, threadQueue);
                    executor.ProcessItem          += new ExecutorProcessItemHandler <T>(OnExecutor_ProcessItem);
                    executor.ProcessItemCompleted += new ExecutorProcessItemCompletedHandler <T>(OnExecutor_ProcessItemCompleted);
                    _workersFree.AddLast(new LinkedListNode <ThreadExecutor <T> >(executor));
                }
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }
        }