Ejemplo n.º 1
0
        public QueryProcessorController GetAvailableFromPool(string Server, string Database, Guid newTaskId)
        {
            QueryProcessorController proc = null;
            int count    = 0;
            int maxCount = FI.Common.AppConfig.DA_OlapProcessorCount;

            // find avalailable
            while (true)
            {
                // check if it's canceled already
                if (IsTaskCanceled(newTaskId))
                {
                    throw new Exception("Task is canceled: " + newTaskId.ToString());
                }

                lock (this)
                {
                    for (int i = 0; i < _pool.Count; i++)
                    {
                        proc = (QueryProcessorController)_pool[i];
                        if (proc.Server == Server && proc.Database == Database)
                        {
                            count++;
                            if (!proc.IsAllocated)
                            {
                                proc.Allocate(newTaskId);
                                return(proc);
                            }
                        }
                    }

                    // if possible to add processor
                    if (count < maxCount)
                    {
                        proc = new QueryProcessorController(Server, Database);
                        _pool.Add(proc);

                        proc.Allocate(newTaskId);
                        return(proc);
                    }
                }


                // sleep till next loop
                System.Threading.Thread.Sleep(200);
            }
        }
Ejemplo n.º 2
0
        public void ReleaseByTaskId(Guid TaskId)
        {
            lock (this)
            {
                if (TaskId == Guid.Empty)
                {
                    throw new ArgumentException("Invalid TaskId:  Empty");
                }

                if (!_canceledTasks.Contains(TaskId.ToString()))
                {
                    _canceledTasks.Add(TaskId.ToString());
                }

                for (int i = 0; i < _pool.Count; i++)
                {
                    QueryProcessorController proc = (QueryProcessorController)_pool[i];
                    if (proc.TaskId == TaskId)
                    {
                        proc.Release(true);
                    }
                }
            }
        }