Esempio n. 1
0
        public override void MachineAction()
        {
            BidLock      = -1;
            EvacuateMode = false;
            //inital sleep before push or pull
            //Thread.Sleep(10*Global.Second);
            while (Started)
            {
                //change to time based on backoff algorithm
                var bft = GetBackOffTime();
                Thread.Sleep(bft);
                lock (_hostLock)
                {
                    var s = LoadManager.CheckSystemState(true, MinUtilization, MaxUtilization); //can this be up
                    if (BidLock == -1 && !EvacuateMode)
                    {
                        TryToChangeSystemState(s);
                    }
                    else if (EvacuateMode && BidLock == -1)
                    {
                        if (!SendPushRequest())
                        {
                            break;
                        }
                    }
                }
            }
            var message = new EvacuationDone(0, this.MachineId);

            CommunicationModule.SendMessage(message);
            //Console.WriteLine("Hahahahha");
        }
Esempio n. 2
0
        public override void MachineAction()
        {
            Task t = new Task(async() =>
            {
                double lastDelay = 10;

                Random r = new Random();

                while (Started)
                {
                    await Task.Delay((int)lastDelay * Global.Second);

                    double d  = 5 + r.NextGaussian() * 2;
                    d        += lastDelay;
                    lastDelay = d;
                    if (lastDelay > 120)
                    {
                        lastDelay = 10;
                    }
                    if (_currentActionType == StrategyActionType.PushAction)
                    {
                        MaxUtilization *= 1 - (r.Next(1, 5) / 100.0);
                    }
                    else
                    {
                        MinUtilization *= 1 + (r.Next(1, 5) / 100.0);
                    }
                    //if (MaxUtilization < 0.5)
                    //{
                    //    MaxUtilization = 0.7;
                    //    MinUtilization = 0.3;
                    //    //throw new NotImplementedException("Goal Arrived");
                    //}
                }
            });

            t.Start();
            //inital sleep before push or pull
            //Thread.Sleep(10*Global.Second);
            while (Started)
            {
                Thread.Sleep(GetBackOffTime());
                //lock (_hostLock)
                {
                    if (BidLock == -1)
                    {
                        var s = LoadManager.CheckSystemState(false, MinUtilization, MaxUtilization); //can this be up
                        TryToChangeSystemState(s);
                    }
                }
            }
            //var message = new EvacuationDone(0, this.MachineId);
            //CommunicationModule.SendMessage(message);
            //Console.WriteLine("Hahahahha");
        }
        public override void MachineAction()
        {
            _hostState.CurrentAction  = HostCurrentAction.None;
            _hostState.EvacuationMode = false;
            _hostState.AuctionId      = 0;
            while (Started)
            {
                //change to time based on backoff algorithm
                var bft = GetBackOffTime();
                Thread.Sleep(bft);
                lock (_hostLock)
                {
                    var s = LoadManager.CheckSystemState(true, MinUtilization, MaxUtilization); //can this be up
                    if (_hostState.CurrentAction == HostCurrentAction.None && !_hostState.EvacuationMode)
                    {
                        TryToChangeSystemState(s);
                    }
                    else if (_hostState.EvacuationMode && _hostState.CurrentAction == HostCurrentAction.None)
                    {
                        if (!SendPushRequest())
                        {
                            break;
                        }
                    }
                }
            }
            var message = new EvacuationDone(0, this.MachineId);

            CommunicationModule.SendMessage(message);

            //lock (_hostLock)
            //{

            //    if (Started)
            //    {
            //        if (ContainerTable.GetContainersCount() > 0)
            //        {

            //        }
            //        var message = new EvacuationDone(0, this.MachineId);
            //        CommunicationModule.SendMessage(message);
            //    }
            //}
        }