Пример #1
0
 /// <summary>
 /// Adds a new jobs to the queue.  This implies that the slave
 /// will be in charge of executing this particular job.
 /// </summary>
 public virtual void ScheduleJob(IJob job)
 {
     lock (_jobs)
     {
         if (job.Sent)
         {
             // just in case
             State.Output.Fatal("Tried to reschedule an existing job");
         }
         _jobs.Insert(_jobs.Count, job);
         SlaveMonitor.NotifyMonitor(_jobs);
     }
 }
Пример #2
0
        public virtual void Shutdown(IEvolutionState state)
        {
            // prevent me from hitting this multiple times
            lock (_shutDownLock)
            {
                if (ShuttingDown)
                {
                    return;
                }

                ShuttingDown = true;
            }

            // don't want to miss any of these so we'll wrap them individually
            try
            {
                // BRS: TODO : Not sure if shutdown status was intended here?
                DataOut.Write((byte)SlaveEvaluationType.Shutdown);
            }
            catch (Exception) { } // exception, not IOException, because JZLib throws some array exceptions
            try { DataOut.Flush(); }
            catch (Exception) { }
            try { DataOut.Close(); }
            catch (Exception) { }
            try { DataIn.Close(); }
            catch (Exception) { }
            try { EvalSocket.Close(); }
            catch (IOException) { }

            State.Output.SystemMessage(ToString() + " Slave is shutting down....");
            SlaveMonitor.UnregisterSlave(this); // unregister me BEFORE I reschedule my jobs
            RescheduleJobs(State);
            lock (_jobs)
            {
                // notify my threads now that I've closed stuff in case they're still waiting
                SlaveMonitor.NotifyMonitor(_jobs);
                Reader.Interrupt(); // not important right now but...
                Writer.Interrupt(); // very important that we be INSIDE the jobs synchronization here so the writer doesn't try to wait on the monitor again.
            }
            State.Output.SystemMessage(ToString() + " Slave exits....");
        }