Exemplo n.º 1
0
            public OverseenWorker RemoveOverseenWorker(int workerId)
            {
                OverseenWorker res = GetOverseenWorker(workerId);

                listWorkers.Remove(res);
                return(res);
            }
Exemplo n.º 2
0
            public bool ProbeWorker(int workerId)
            {
                OverseenWorker o = GetOverseenWorker(workerId);

                try {
                    o.Service.ProbeObject();
                    return(true);
                } catch (Exception) {
                    return(false);
                }
            }
Exemplo n.º 3
0
            public void AddOverseenWorker(OverseenWorker w)
            {
                OverseenWorker o = GetOverseenWorker(w.WorkerId);

                if (o != null)
                {
                    if (o.LifeproofTimer == null)
                    {
                        o.LifeproofTimer = w.LifeproofTimer;
                    }
                }
                else
                {
                    listWorkers.Add(w);
                }
            }
Exemplo n.º 4
0
        /// <summary>
        /// Removes the worker from this services and all MasterTrackers.
        /// </summary>
        /// <param name="workerId"></param>
        public void DisposeWorker(int workerId)
        {
            OverseenWorker o = manager.RemoveOverseenWorker(workerId);

            if (o != null)
            {
                if (o.LifeproofTimer != null)
                {
                    o.LifeproofTimer.Dispose();
                }

                WorkerService s = GetMasterTracker();

                if (s != null)
                {
                    s.DisposeWorker(workerId);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Lets this tracker know that the job assigned to
        /// 'workerURL' has been done. So, remove the job from
        /// the jobAssignment list and from the worker reference.
        /// </summary>
        /// <param name="workerURL"></param>
        public void ReceiveWorkDoneNotify(int workerId)
        {
            OverseenWorker worker = manager.GetOverseenWorker(workerId);

            if (worker != null)
            {
                worker.Assignment = null;
            }

            WorkerService masterTracker = GetMasterTracker();

            if (masterTracker != null)
            {
                masterTracker.ReceiveWorkDoneNotify(workerId);
            }
            else
            {
                logger.Log("WORKER DONE: W" + workerId);

                Thread checkJobStatusThread;
                checkJobStatusThread = new Thread(new ThreadStart(checkForStruggleWorkers));
                checkJobStatusThread.Start();
            }
        }
Exemplo n.º 6
0
        public void WorkerFailureHandle(FaultyWorkerEventArgs args)
        {
            OverseenWorker worker = null;

            worker = manager.GetOverseenWorker(args.WorkerId);
            if (worker == null)
            {
                return;
            }

            DisposeWorker(worker.WorkerId);

            if (worker.WorkerId == id)
            {
                return;
            }                                      // TODO: this just hides the phantom worker bug
            if (worker.Assignment == null)
            {
                logger.Log("WORKER FAILURE: W" + args.WorkerId);
                return;
            }

            logger.Log("WORKER FAILURE WITH JOBS TO DO: W" + args.WorkerId);

            int workerControllerId = (worker.WorkerId + 1) % (manager.Count + 1);

            if (workerControllerId == 0)
            {
                workerControllerId = 1;
            }

            OverseenWorker controllerWorker = manager.GetOverseenWorker(workerControllerId);

            logger.Log("JUST CHEKING THE CONTROLLER OF WORKER " + worker.WorkerId + " IS THE RIGHT ONE " + controllerWorker.WorkerId);

            if (controllerWorker != null)
            {
                while (true)
                {
                    // Reassign work - search for the first worker that is free

                    if (controllerWorker.Assignment == null)
                    {
                        logger.Log("Assigning work to: W" + controllerWorker.WorkerId);
                        controllerWorker.Assignment = worker.Assignment;
                        if (controllerWorker.Assignment != null)
                        {
                            controllerWorker.Assignment.WorkerId = controllerWorker.WorkerId;
                        }

                        // Gets the service for the worker, but checks if that worker is himself
                        WorkerService otherWorkerService = null;
                        if (controllerWorker.WorkerId == Id)
                        {
                            AsyncSetWorkerResumeContext submit = new AsyncSetWorkerResumeContext(this.LoadResumeContext);
                            submit.BeginInvoke(clientURL, mapClass, code, controllerWorker.Assignment.Jobs, null, null);
                        }
                        else
                        {
                            otherWorkerService = controllerWorker.Service;
                            otherWorkerService.LoadResumeContext(clientURL, this.mapClass, this.code, controllerWorker.Assignment.Jobs);
                        }

                        return;
                    }
                    // What if you don't find any free worker?
                    // Sleep for 5 seconds and go to the beginning of the loop
                    Thread.Sleep(5000);
                }
            }
            else
            {
                // Do this ad infinitum until finding a free worker (in case they are all busy atm)
                while (true)
                {
                    // Reassign work - search for the first worker that is free
                    foreach (OverseenWorker otherWorker in manager.ListWorkers)
                    {
                        if (otherWorker.Assignment == null)
                        {
                            logger.Log("Assigning work to: W" + otherWorker.WorkerId);
                            otherWorker.Assignment = worker.Assignment;
                            if (otherWorker.Assignment != null)
                            {
                                otherWorker.Assignment.WorkerId = otherWorker.WorkerId;
                            }

                            // Gets the service for the worker, but checks if that worker is himself
                            WorkerService otherWorkerService = null;
                            if (otherWorker.WorkerId == Id)
                            {
                                AsyncSetWorkerResumeContext submit = new AsyncSetWorkerResumeContext(this.LoadResumeContext);
                                submit.BeginInvoke(clientURL, mapClass, code, otherWorker.Assignment.Jobs, null, null);
                            }
                            else
                            {
                                otherWorkerService = otherWorker.Service;
                                otherWorkerService.LoadResumeContext(clientURL, this.mapClass, this.code, otherWorker.Assignment.Jobs);
                            }

                            return;
                        }
                    }
                    // What if you don't find any free worker?
                    // Sleep for 5 seconds and go to the beginning of the loop
                    Thread.Sleep(5000);
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// This method is used when receiving an update from another tracker
 /// about a new worker that entered the network.
 /// WARNING: this node won't provide fault tolerance if the worker fails in the
 /// future! Must be warned by the Master tracker of that node!
 /// </summary>
 /// <param name="newWorkerURL"></param>
 public void ReceiveNewWorkerUpdate(OverseenWorker newWorker)
 {
     manager.AddOverseenWorker(newWorker);
 }
Exemplo n.º 8
0
 public void AddOverseenWorker(OverseenWorker w)
 {
     OverseenWorker o = GetOverseenWorker(w.WorkerId);
     if (o != null) {
         if (o.LifeproofTimer == null) {
             o.LifeproofTimer = w.LifeproofTimer;
         }
     } else {
         listWorkers.Add(w);
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// This method is used when receiving an update from another tracker
 /// about a new worker that entered the network.
 /// WARNING: this node won't provide fault tolerance if the worker fails in the
 /// future! Must be warned by the Master tracker of that node!
 /// </summary>
 /// <param name="newWorkerURL"></param>
 public void ReceiveNewWorkerUpdate(OverseenWorker newWorker)
 {
     manager.AddOverseenWorker(newWorker);
 }