private void Execute()
        {
            Thread     jobThread = null;
            ArchiveJob archJob   = null;
            ThreadBean tBean     = null;

            initDBNameDictionary();
            //Init Error Messages
            log.Info(string.Format("Execution started with no of threads {0}", this.totalCount));
            if (!ArchJobErrorDesc.getInstance().getStatus())
            {
                log.Error("Problem in initializing Error Messages , stopping process");
                return;
            }
            var  tempList      = new List <vo.PawnDocRegVO>();
            var  totList       = new List <vo.PawnDocRegVO>();
            bool dbCreateError = false;
            bool docGetError   = false;

            totList = GetDocumentToArchOnlyRecovery(out dbCreateError, out docGetError);
            if (totList == null || totList.Count() == 0)
            {
                log.Info("No data found to do retry");
                return;
            }

            while (true)
            {
                if (worker.CancellationPending)
                {
                    log.Info("cancel pressed felt in : main workder :step1 ");
                    WaitUntillAllJobsCompleted();
                    return;
                }

                if (totList.Count() == 0)
                {
                    //totList = GetDocumentToArch(out dbCreateError,out docGetError);
                    //totList = GetDocumentToArchTemp(out dbCreateError, out docGetError);
                    //totList = GetDocumentToArchOnlyRecovery(out dbCreateError, out docGetError);

                    if (docGetError)
                    {
                        log.Error("Execution aborted due to error in getting doc from SP");
                        return;
                    }
                    if (dbCreateError) //check for error's during db creation
                    {
                        log.Error("Execution aborted due to error in DB creation in couch or db");
                        return;
                    }
                    if (totList == null || totList.Count == 0)
                    {
                        WaitUntillAllJobsCompleted();
                        log.Debug("All jobs completed , Exiting");
                        log.Debug("******************************************Reutne");
                        return;
                    }
                }
                int allowedJob = GetAllowedJob();

                /*if (this.completedList.Count()==119)
                 * {
                 *  log.Info("Reached 119");
                 * }*/
                worker.ReportProgress(computePercent(this.completedList.Count(), totalCount),
                                      string.Format("{0}:{1}:{2}", totalCount, completedList.Count(),
                                                    (totalCount - completedList.Count())));
                //compl count with duplicate

                /*worker.ReportProgress(computePercent(this.completedList.Count()+duplCount, totalCount),
                 *                  string.Format("{0}:{1}:{2}", totalCount, completedList.Count()+this.duplCount,
                 *                                (totalCount - (completedList.Count()+this.duplCount))));*/
                //compl count with duplicate
                int jobCount = 0;
                foreach (var pawnDocRegVo in totList)
                {
                    if (jobCount < allowedJob)
                    {
                        archJob = new ArchiveJob(pawnDocRegVo, this.mainForm.getMainForm().getSourceCouch(),
                                                 this.mainForm.getMainForm().getTargetCouch(), isRecovery);
                        jobThread        = new Thread(new ThreadStart(archJob.process));
                        jobThread.Name   = "T" + pawnDocRegVo.DocID.ToString();
                        tBean            = new ThreadBean();
                        tBean.Job        = archJob;
                        tBean.DocumentID = pawnDocRegVo.DocID;
                        tBean.ThreadObj  = jobThread;
                        runningList.Add(tBean);
                        tempList.Add(pawnDocRegVo);
                        jobThread.Start();
                        jobCount++;
                    }
                    else
                    {
                        break;
                    }
                }
                //clear allocated job from totlist

                /*foreach (var threadBean in runningList)
                 * {
                 *  totList.Remove(threadBean.Job.getVO());
                 * }*/
                if (tempList.Count > 0)
                {
                    foreach (var tempBeanVo in tempList)
                    {
                        totList.Remove(tempBeanVo);
                    }
                    tempList.Clear();
                }
                if (criticalErrorOccured)
                {
                    log.Error("Process Cancelled################### ");
                    this.worker.CancelAsync();
                }
                Thread.Sleep(50);
            }
        }
示例#2
0
        private void Execute()
        {
            Thread      jobThread = null;
            ArchiveJob2 archJob   = null;
            ThreadBean  tBean     = null;

            initDBNameDictionary();
            //Init Error Messages
            log.Info(string.Format("Execution started with no of threads {0}", this.totalCount));
            if (!ArchJobErrorDesc.getInstance().getStatus())
            {
                log.Error("Problem in initializing Error Messages , stopping process");
                return;
            }
            var  tempList                = new List <vo.PawnDocRegVO>();
            var  totList                 = new List <vo.PawnDocRegVO>();
            bool dbCreateError           = false;
            bool docGetError             = false;
            int  currentThreadCount      = 0;
            long maxMemory               = 0;
            int  threadNameCount         = 1;
            List <PawnDocRegVO> subList1 = new List <PawnDocRegVO>();
            int jobCount                 = 0;
            int endCount                 = 20;

            while (true)
            {
                checkAndStartFetchThread();

                if (worker.CancellationPending)
                {
                    log.Info("cancel pressed felt in : main workder :step1 ");
                    WaitUntillAllJobsCompleted();
                    return;
                }

                if (totList.Count() == 0)
                {
                    log.Info("Going to get data............................");
                    //totList = GetDocumentToArch(out dbCreateError,out docGetError);
                    totList = GetDocumentToArchTemp(out dbCreateError, out docGetError);
                    if (docGetError)
                    {
                        log.Error("Execution aborted due to error in getting doc from SP");
                        return;
                    }
                    if (dbCreateError) //check for error's during db creation
                    {
                        log.Error("Execution aborted due to error in DB creation in couch or db");
                        return;
                    }
                    if (totList == null || totList.Count == 0)
                    {
                        WaitUntillAllJobsCompleted();
                        log.Debug("All jobs completed , Exiting");
                        log.Debug("******************************************Reutne");
                        return;
                    }
                }
                int allowedJob = GetAllowedJob();

                /* worker.ReportProgress(computePercent(completedCount, totalCount),
                 *                     string.Format("{0}:{1}:{2}", totalCount, completedCount, (totalCount - completedCount)));*/
                //compl count with duplicate


                //Thread.Sleep(100);
                //tempList = new List<PawnDocRegVO>();
                log.Info("Memory usage :" + System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64 / 1024 / 1024 + "MB");


                jobCount = 0;
                endCount = 20;

                while (jobCount < allowedJob)
                {
                    if (worker.CancellationPending)
                    {
                        log.Error("Process Cancelled due to  cancel###### ");
                        //this.worker.CancelAsync();
                        break;
                    }

                    currentThreadCount = System.Diagnostics.Process.GetCurrentProcess().Threads.Count;
                    maxMemory          = System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64 / 1024 / 1024;

                    if (maxMemory > maxAllowedMemory)
                    {
                        log.Info("Max memory reached , allocation aborted current:" + maxMemory + " ,allowed :" + maxAllowedMemory);
                        break;
                    }
                    if (currentThreadCount >= noOfThreads)
                    {
                        log.Info("Max thread count reached , allocation aborted current:" + currentThreadCount + " ,allowed :" + noOfThreads);
                        break;
                    }


                    if (totList.Count < endCount)
                    {
                        endCount = totList.Count;
                    }
                    subList1.Clear();

                    for (int i = 0; i < endCount; i++)
                    {
                        subList1.Add(totList[i]);
                    }

                    archJob           = new ArchiveJob2(subList1, isRecovery);
                    jobThread         = new Thread(new ThreadStart(archJob.process));
                    jobThread.Name    = "T" + threadNameCount;
                    archJob.JobThread = jobThread;
                    runningList.Add(archJob);
                    //tempList.Add(pawnDocRegVo);
                    jobThread.Start();
                    threadNameCount++;
                    foreach (var jobFrmSubList in subList1)
                    {
                        totList.Remove(jobFrmSubList);
                    }
                    if (totList.Count == 0)
                    {
                        break;
                    }
                    jobCount++;
                }

                if (criticalErrorOccured)
                {
                    log.Error("Process Cancelled################### ");
                    this.worker.CancelAsync();
                }
            }
        }