private void StartPrimaryJobTrackerProcess(string clientUrl, long fileSize, long numSplits, string mapperName, byte[] mapperCode)
        {
            currentJobTrackerUrl = this.myURL;
            serverRole = ServerRole.JOB_TRACKER;
            status = ExecutionState.WORKING;
            isPrimary = true;
            jtInformation = new JobTrackerInformation(this, numSplits);
            this.clientURL = clientUrl;
            this.fileSize = fileSize;
            client = (IClient)Activator.GetObject(typeof(IClient), clientURL);
            this.mapperName = mapperName;
            this.mapperCode = mapperCode;
            Thread trackWorkersThread = new Thread(() =>
            {
                while (!jtInformation.DidFinishJob() && isPrimary && serverRole == ServerRole.JOB_TRACKER)
                {
                    /* wait until if I am unfrozen and revert to Worker if needed */
                    if (WaitForUnfreezeAndCheckChanges())
                        break;
                    /* --------------------------- */

                    Logger.LogInfo("[CHECKING SLOW WORKERS]");
                    SplitInfo slowSplit = jtInformation.FindSlowSplit();
                    if (slowSplit != null)
                    {
                        //Logger.LogWarn("There is a slow split - " + slowSplit.splitId);
                        IWorker freeWorker = jtInformation.GetFirstFreeWorker();
                        if (freeWorker != null)
                        {
                            Logger.LogWarn("[SLOWWWWWWW SPLIT] RESENDING " + slowSplit.remainingSplits);
                            ResendSplitToNextWorker(freeWorker, slowSplit.fileSize, slowSplit.totalSplits, slowSplit.remainingSplits);
                        }
                    }
                    Thread.Sleep(4000);
                }

                serverRole = ServerRole.NONE;
                status = ExecutionState.WAITING;
            });
            trackWorkersThread.Start();

            Thread ConfigureSecondaryServerThread = new Thread(() =>
            {
                //wait for an available backUrl, then pings it then sets up as primary Server
                while (isPrimary && serverRole == ServerRole.JOB_TRACKER && !jtInformation.DidFinishJob())
                {
                    if (backURL == myURL)
                    {
                        continue;
                    }

                    //Logger.LogInfo("Waiting for an available url to be the secondary JT");
                    secondaryJT = (IWorker)Activator.GetObject(typeof(IWorker), backURL);

                    try
                    {
                        secondaryJT.PingJT();
                        backupSecondaryServerIfFailsUrl = secondaryJT.SetUpAsSecondaryServer(this.clientURL, this.myURL, fileSize, numSplits, mapperName, mapperCode);

                        backupSecondaryServerIfFails = (IWorker)Activator.GetObject(typeof(IWorker), backupSecondaryServerIfFailsUrl);

                        Logger.LogInfo("Success setting setup backupserver");
                        break;
                    }
                    catch(Exception)
                    {
                        Logger.LogInfo("There is still no backUrl available to become backup server");
                    }

                    Thread.Sleep(1000);
                }

            });
            ConfigureSecondaryServerThread.Start();

            if (!primaryDidStartedJob && !firstRequest)
            {
                primaryDidStartedJob = true;
                ReceiveWork(clientUrl, fileSize, numSplits, mapperName, mapperCode);
            }

            firstRequest = false;
        }
        public string SetUpAsSecondaryServer(string clientUrl, string primaryJTurl, long fileSize, long numSplits, string mapperName, byte[] mapperCode)
        {
            this.clientURL = clientUrl;
            firstRequest = false;
            client = (IClient)Activator.GetObject(typeof(IClient), clientURL);
            isPrimary = false;
            this.fileSize = fileSize;
            primaryJobTracker = (IWorker)Activator.GetObject(typeof(IWorker), primaryJTurl);
            jtInformation = new JobTrackerInformation(this, numSplits);
            this.mapperName = mapperName;
            this.mapperCode = mapperCode;
            Thread SendIAmAliveThread = new Thread(() =>
            {
                while (!isPrimary && !jtInformation.DidFinishJob())
                {
                    /* wait until if I am unfrozen and revert to Worker if needed */
                    if (WaitForUnfreezeAndCheckChanges())
                        break;
                    /* --------------------------- */

                    //Logger.LogInfo("Sending I am alive");
                    try
                    {
                        primaryJobTracker.PingJT();
                        receivedAliveFromServer = true;
                    }
                    catch (Exception)
                    {
                        Logger.LogErr("TIMEOUT");
                    }

                    if (!receivedAliveFromServer)
                    {
                        Logger.LogErr("PRIMARY JOB TRACKER IS DOWN");
                        nodeDown();
                        PrintUpdateNetwork();
                        jtInformation.AlertChangeOfJobTracker(myURL);
                        this.StartPrimaryJobTrackerProcess(clientUrl, fileSize, jtInformation.numSplits, mapperName, mapperCode);
                        break;
                    }

                    receivedAliveFromServer = false;
                    Thread.Sleep(PingTimeout);

                }
            });
            SendIAmAliveThread.Start();

            return backURL;
        }