예제 #1
0
        /// <summary>
        /// This function is called before submit so that
        /// the client can get a reference to the master
        /// worker/tracker to which to submit jobs.
        /// </summary>
        /// <param name="entryURL"></param>
        /// <param name="entryServiceName"></param>
        public void SetupWorkerChannel(string entryURL, string entryServiceName)
        {
            workerService =
                (WorkerService)Factory.Instance.GetService(
                    typeof(WorkerService), entryURL);

            // catch this on console
            if (workerService == null) {
                throw new RemotingException("error: cannot locate worker!");
            }

            workerService.AddWorker(workerService);
        }
예제 #2
0
        private System.Timers.Timer createCheckFaultyWorkerTimer(WorkerService worker)
        {
            System.Timers.Timer newTimer = new System.Timers.Timer();
            int workerId = worker.Id;

            newTimer.Elapsed += (sender, args) => {
                OnFaultyWorkerTimeExpiredEvent(newTimer, new FaultyWorkerEventArgs(workerId));
            };
            newTimer.Interval = TIME_TO_WAIT_FOR_WORKER_LIFEMSG;
            newTimer.Enabled = true;

            return newTimer;
        }
예제 #3
0
 public OverseenWorker(WorkerService service, System.Timers.Timer lifeproofTimer)
 {
     this.WorkerId = service.Id;
     this.Service = service;
     this.LifeproofTimer = lifeproofTimer;
     this.Assignment = null;
 }
예제 #4
0
        /// <summary>
        /// Method used by the worker to let this tracker know
        /// that it's alive, resetting the timer in the process.
        /// </summary>
        /// <param name="workerURL"></param>
        /// <returns>This service master tracker.</returns>
        public WorkerService ReceiveLifeproof(int workerId, WorkerService proofWorker)
        {
            //logger.Log("Received lifeproof from: W" + workerId);

            // if worker recovered, or re-linked from a crashed MasterTracker, reuse it.
            AddWorker(proofWorker);

            foreach (OverseenWorker worker in manager.ListWorkers) {
                if (worker.WorkerId == workerId) {
                    // Resets the timer for this worker
                    if (worker.LifeproofTimer != null) {
                        worker.LifeproofTimer.Stop();
                        try {
                            worker.LifeproofTimer.Start();
                        } catch (Exception) {
                            continue;
                        }
                    }
                }
            }

            return GetMasterTracker();
        }
예제 #5
0
 public void SetMasterTrackerFather(WorkerService service)
 {
     worker.SetMasterTrackerFather(service);
 }
예제 #6
0
        private void SendLifeproof(object tracker) {
            WorkerService masterTracker = (WorkerService)tracker;

            try {
                SetMasterTrackerFather(masterTracker.ReceiveLifeproof(id, service));
                //logger.Log("Sent lifeproof to W" + masterTrackerId);

                if (lifeProofTimer != null) {
                    lifeProofTimer.Stop();
                    lifeProofTimer.Start();
                } else {
                    lifeProofTimer = createSendLifeproofTimer(masterTracker);
                }
            } catch (Exception) {
                logger.Log("Master Tracker not responding!");

                if (masterTrackerId != -1) {
                    service.WorkerFailureHandle(new WorkerService.FaultyWorkerEventArgs(masterTrackerId));
                }

                try {
                    lifeProofTimer.Dispose();
                } catch (Exception) {
                    // some error goes here when timer was already disposed???
                }

                if (masterTrackerFather != null) {
                    masterTrackerService = masterTrackerFather;
                    masterTrackerFather = null;
                    try {
                        SetMasterTrackerFather(masterTrackerService.ReceiveLifeproof(id, service));
                    } finally {
                        lifeProofTimer = createSendLifeproofTimer(masterTrackerService);
                    }
                }
            }
        }
예제 #7
0
        /// <summary>
        /// This method is called by the workers when they are created
        /// so that the tracker can keep track them.
        /// </summary>
        /// <param name="newWorker"></param>
        public void AddWorker(WorkerService newWorker, bool isPropagate = false)
        {
            worker.PropagateWorker(newWorker);

            // check if it already contains this worker
            if (manager.Exists(newWorker.Id)) { return; }

            if (!isPropagate) {
                newWorker.SetMasterTracker(this);
                newWorker.SetMasterTrackerFather(GetMasterTracker());

                System.Timers.Timer newTimer = createCheckFaultyWorkerTimer(newWorker);

                // Finally, add the new worker to the list
                manager.AddOverseenWorker(new OverseenWorker(newWorker, newTimer));
            } else {
                manager.AddOverseenWorker(new OverseenWorker(newWorker, null));
            }

            logger.Log("Received new worker notification from W" + newWorker.Id);

            // Let the other workers know about this new worker
            foreach (OverseenWorker otherWorker in manager.ListWorkers) {
                if (otherWorker.WorkerId != id) {
                    WorkerService otherWorkerService = otherWorker.Service;
                    otherWorkerService.ReceiveNewWorkerUpdate(otherWorker);
                }
            }

            // Update the new worker with the list of workers in the network
            newWorker.ReceiveCurrentWorkerList(manager.ListWorkers);
        }
예제 #8
0
        private void notifyMasterTracker(string entryURL) {
            WorkerService tracker =
                (WorkerService)Factory.Instance.GetService(
                    typeof(WorkerService), entryURL);

            tracker.AddWorker(this.service);

            masterTrackerFather = tracker.GetMasterTracker();

            lifeProofTimer = createSendLifeproofTimer(masterTrackerService);
        }
예제 #9
0
        private System.Timers.Timer createSendLifeproofTimer(WorkerService tracker) {
            System.Timers.Timer newTimer = new System.Timers.Timer();
            newTimer.Elapsed += (sender, args) => {
                SendLifeproof(tracker);
            };
            newTimer.Interval = TIME_BETWEEN_LIFEPROOFS;
            newTimer.Enabled = true;

            return newTimer;
        }
예제 #10
0
        private void setupService() {
            string serviceName = Constants.WORKER_SERVICE_NAME;
            service = new WorkerService(this);

            if (Factory.Instance.CreateService(port, serviceName,
                    service, typeof(WorkerService), serviceURL)) {

                logger.Log("I'm a new worker at " + serviceURL);

                workerThread = new Thread(new ThreadStart(WorkerJob));
                workerThread.Start();
            } else {
                logger.Log("Can'start worker at " + serviceURL);
            }
        }
예제 #11
0
        // --------------------------------------- IWorker Implementation //

        public bool IsMasterTracker() {
            try {
                if (masterTrackerService != null) {
                    masterTrackerService.ProbeObject();
                }
            } catch (Exception) {
                masterTrackerService = masterTrackerFather;
                masterTrackerFather = null;
                return IsMasterTracker();
            }
            return masterTrackerService == null;
        }
예제 #12
0
 public void PropagateWorker(WorkerService worker) {
     if (masterTrackerService != null) {
         Factory.Instance.SafelyUseService(masterTrackerService, (service) => {
             service.AddWorker(worker, true);
         });
     }
 }
예제 #13
0
 public void SetMasterTrackerFather(WorkerService service) {
     this.masterTrackerFather = service;
 }
예제 #14
0
 public void SetMasterTracker(WorkerService service) {
     this.masterTrackerService = service;
     try {
         masterTrackerId = service.Id;
     } catch (Exception) {
         masterTrackerId = -1;
     }
 }