public void AllocateResource() { //Step1: Free Resources for next allocation FreeResources(); //Step2: Check if any task remaining for allocation lock (_schMutex) { if (waitingColTasks.Count == 0 && runningColTasks.Count == 0) { VerifyDST(); //IsCompleted(); //IsTaskAvailable = false; return; } } //Step3: Check if any slot avaialbe for waiting tasks if (runningColTasks.Count >= MAX_RUNNING_COL_TASK) { return; } //Step4: Allocate resources to waiting tasks while (runningColTasks.Count < MAX_RUNNING_COL_TASK && waitingColTasks.Count != 0) { var first = default(LinkedListNode <String>); lock (_schMutex) { first = waitingColTasks.First; if (first != null) { waitingColTasks.RemoveFirst(); } } if (first != null && first.Value != null && collectionTasksMap.ContainsKey(first.Value)) { var colName = first.Value; IStateTransferTask task = collectionTasksMap[colName]; task.Start(); task.Status = StateTxfrStatus.Running; lock (_schMutex) { runningColTasks.AddLast(first); } } } }
public void AllocateResource() { ////Step1: Check if any task remaining for allocation //if (IsCompleted()) //{ // if (LoggerManager.Instance.StateXferLogger != null && LoggerManager.Instance.StateXferLogger.IsInfoEnabled) // LoggerManager.Instance.StateXferLogger.Info("NodeStateTxfrMgr.AllocateResource()", "State transfer of the node " + this.context.LocalAddress + " completed successfully."); // return; //} //Step2: Allocate already task resoruces AllocateRunningDBs(); //Step3: Free Resources for next allocation FreeResources(); ////Step1: Check if any task remaining for allocation //lock(waitingDBTasks) //{ // if(waitingDBTasks.Count==0) // { // IsTaskAvailable=false; // return; // } //} //Step4: Check if any slot avaialbe for waiting tasks if (runningDBTasks.Count >= MAX_RUNNING_DB_TASK) { return; } //Step5: Allocate resources to waiting tasks while (runningDBTasks.Count < MAX_RUNNING_DB_TASK && waitingDBTasks.Count > 0) { var firstNode = default(LinkedListNode <String>); lock (_schMutex) { firstNode = waitingDBTasks.First; if (firstNode != null) { waitingDBTasks.RemoveFirst(); } } if (firstNode != null && firstNode.Value != null && dbStateTxferMgrMap.ContainsKey(firstNode.Value)) { var dbName = firstNode.Value; IStateTransferTask task = null; lock (dbStateTxferMgrMap) { task = dbStateTxferMgrMap[dbName]; } task.Start(); task.Status = StateTxfrStatus.Running; lock (_schMutex) { runningDBTasks.AddLast(firstNode); } } } }