예제 #1
0
 public override void AssignTask(DTTask dTTask, PhysicalMachine Donor)
 {
     if (AvailableMemory >= dTTask.MemoryConsumption)
     {
         TaskQueue.Add(dTTask);
         AvailableMemory -= dTTask.MemoryConsumption;
         Donor.TaskQueue.Remove(dTTask);
     }
     //else
     //{
     //    throw new Exception("Not enough memory for new task");
     //}
 }
예제 #2
0
        //public bool IsBusy
        //{
        //    get
        //    {
        //        if (CurrentTask != null)
        //        {
        //            return true;
        //        }
        //        else
        //        {
        //            return false;
        //        }
        //    }
        //}

        public void DoTask()
        {
            if (CurrentTask == null || CurrentTask.Volume <= 0)
            {
                if (Host.TaskQueue.Count > 0)
                {
                    CurrentTask = Host.TaskQueue[0];
                    Host.TaskQueue.RemoveAt(0);
                }
                else
                {
                    CurrentTask = null;
                }
            }
            else if (CurrentTask.Volume > 0)
            {
                CurrentTask.Volume -= Speed;
            }
        }
        /*
         * public override void AssignTasks(List<DTTask> dTTasks, PhysicalMachine Donor)
         * {
         *  throw new NotSupportedException("This class doesn`t support this method");
         * }
         */


        public void CreateTask() //creates task and give it to a random nearest machine
        {
            int             TargetIndex   = rnd.Next(0, AvailableDevices(AvailableDevicesSearchingMode.AllNearestMachines).Count);
            PhysicalMachine TargetMachine = (PhysicalMachine)AvailableDevices(AvailableDevicesSearchingMode.AllNearestMachines)[TargetIndex];
            DTTask          task;

            switch (Mode)
            {
            case GenerationMode.Random:

                task = new DTTask(rnd.Next(VolumeMinGenerationBound, VolumeMaxGenerationBound), rnd.Next(MemConsumptionMinGenerationBound, MemConsumptionMaxGenerationBound));

                if (task.MemoryConsumption <= TargetMachine.AvailableMemory)
                {
                    TargetMachine.TaskQueue.Add(task);
                    TargetMachine.AvailableMemory -= task.MemoryConsumption;
                }

                break;

            case GenerationMode.Defined:

                task = new DTTask(TaskVolume, TaskMemoryConsumption);

                if (task.MemoryConsumption <= TargetMachine.AvailableMemory)
                {
                    TargetMachine.TaskQueue.Add(task);
                    TargetMachine.AvailableMemory -= task.MemoryConsumption;
                }

                break;

            case GenerationMode.Manual:

                break;
            }
        }
 public override void AssignTask(DTTask dTTask, PhysicalMachine Donor)
 {
     throw new NotSupportedException("This class doesn`t support this method");
 }
        }                               //memory - how much tasks it can store

        abstract public void AssignTask(DTTask dTTask, PhysicalMachine Donor);