Changeset 1253


Ignore:
Timestamp:
Mar 22, 2010, 8:42:01 PM (12 years ago)
Author:
arnold
Message:

P2PJobAdmin: Inserted a Timer, so the Worker will ask the Manager several times for new jobs. So no worker will act like a "Helling" ;-)

Location:
trunk/CrypPlugins
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/PeerToPeerJobs/PeerToPeerJobs.csproj

    r1137 r1253  
    6262    </ProjectReference>
    6363  </ItemGroup>
    64   <ItemGroup>
    65     <None Include="cdJobClasses.cd" />
    66     <None Include="cdJobMessage.cd" />
    67   </ItemGroup>
    6864  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    6965  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  • trunk/CrypPlugins/PeerToPeerWorker_NEW/P2PJobAdminBase.cs

    r1166 r1253  
    2222using Cryptool.PluginBase.Miscellaneous;
    2323using Cryptool.Plugins.PeerToPeer.Jobs;
     24using System.Timers;
    2425
    2526/* TWO DIFFERENT STOPPING CASE:
     
    5859
    5960        /// <summary>
     61        /// if worker sends a "free" msg to the manager, but it doesn't react on this,
     62        /// although there are some jobs to distribute...
     63        /// </summary>
     64        Timer timerWaitingForJobs = new Timer(5000);
     65
     66        /// <summary>
    6067        /// if more than one job arrived at the same time, buffer it in this dictionary
    6168        /// (can't happen under normal circumstances, but when it happens, we are prepared)
     
    7986        public P2PJobAdminBase(IP2PControl p2pControl, IControlWorker controlWorker) : base(p2pControl)
    8087        {
     88            this.timerWaitingForJobs.Elapsed += new ElapsedEventHandler(timerWaitingForJobs_Elapsed);
    8189            this.workerControl = controlWorker;
    8290
     
    120128                this.workerControl.OnProcessingSuccessfullyEnded -= workerControl_OnProcessingSuccessfullyEnded;
    121129                this.workerControl.OnInfoTextReceived -= workerControl_OnInfoTextReceived;
     130
     131                this.timerWaitingForJobs.Stop();
     132
    122133                base.Stop(msgType);
    123134
     
    226237        private void workerControl_OnProcessingSuccessfullyEnded(BigInteger jobId, byte[] result)
    227238        {
     239            //GuiLogging("Sending job result to Manager. JobId: " + jobId.ToString() + ". Mngr-Id: '" + base.ActualPublisher.ToString() + "'.", NotificationLevel.Info);
    228240            GuiLogging("Sending job result to Manager. JobId: " + jobId.ToString() + ". Mngr-Id: '" + base.ActualPublisher.ToString() + "'.", NotificationLevel.Info);
    229241            this.p2pControl.SendToPeer(JobMessages.CreateJobResultMessage(jobId, result), base.ActualPublisher);
     
    235247                OnSuccessfullyEnded();
    236248
    237             CheckIfAnyJobsLeft();
    238            
     249            CheckIfAnyJobsLeft();   
    239250        }
    240251
     
    251262                this.p2pControl.SendToPeer(JobMessages.CreateFreeWorkerStatusMessage(true), base.ActualPublisher);
    252263                GuiLogging("No jobs in the 'waitingJob'-Stack, so send 'free'-information to the Manager. Mngr-Id: '" + base.ActualPublisher.ToString() + "'.", NotificationLevel.Info);
     264                // If this timer elapses, it will check if the isWorking flag is true. Than it will stop the timer.
     265                // Otherwise it will send a new free msg to the Manager, if the last free msg got lost
     266                this.timerWaitingForJobs.Start();
     267            }
     268        }
     269
     270        // Added by Arnold - 2010.03.22
     271        /// <summary>
     272        /// this method is only necessary when the regular free message got lost on the way to the manager.
     273        /// In this case the Worker won't get any more jobs, so it sends a free message
     274        /// </summary>
     275        /// <param name="sender"></param>
     276        /// <param name="e"></param>
     277        void timerWaitingForJobs_Elapsed(object sender, ElapsedEventArgs e)
     278        {
     279            if (!isWorking)
     280            {
     281                this.p2pControl.SendToPeer(JobMessages.CreateFreeWorkerStatusMessage(true), base.ActualPublisher);
     282                GuiLogging("Because the last 'free worker'-Message got lost, try again.", NotificationLevel.Info);
     283            }
     284            else
     285            {
     286                // when Worker is working, than the time can be stopped
     287                timerWaitingForJobs.Stop();
     288                GuiLogging("Next trial to send 'free worker'-Mesasge was successful, so the timer was stopped.", NotificationLevel.Info);
    253289            }
    254290        }
Note: See TracChangeset for help on using the changeset viewer.