/// <summary>Set the modified time of an existing file to now.</summary> /// <throws> IOException if the file does not exist </throws> public override void TouchFile(string name) { EnsureOpen(); RAMFile file; lock (this) { file = fileMap[name]; } if (file == null) { throw new System.IO.FileNotFoundException(name); } long ts2, ts1 = System.DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond; do { try { System.Threading.Thread.Sleep(new System.TimeSpan((long)10000 * 0 + 100 * 1)); } catch (System.Threading.ThreadInterruptedException ie) { // In 3.0 we will change this to throw // InterruptedException instead ThreadClass.Current().Interrupt(); throw new System.SystemException(ie.Message, ie); } ts2 = System.DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond; }while (ts1 == ts2); file.LastModified = ts2; }
override public void Run() { try { for (int j = 0; j < Lucene.Net.Index.TestThreadedOptimize.NUM_ITER2; j++) { writerFinal.Optimize(false, null); for (int k = 0; k < 17 * (1 + iFinal); k++) { Document d = new Document(); d.Add(new Field("id", iterFinal + "_" + iFinal + "_" + j + "_" + k, Field.Store.YES, Field.Index.NOT_ANALYZED)); d.Add(new Field("contents", English.IntToEnglish(iFinal + k), Field.Store.NO, Field.Index.ANALYZED)); writerFinal.AddDocument(d, null); } for (int k = 0; k < 9 * (1 + iFinal); k++) { writerFinal.DeleteDocuments(null, new Term("id", iterFinal + "_" + iFinal + "_" + j + "_" + k)); } writerFinal.Optimize(null); } } catch (System.Exception t) { Enclosing_Instance.setFailed(); System.Console.Out.WriteLine(ThreadClass.Current().Name + ": hit exception"); System.Console.Out.WriteLine(t.StackTrace); } }
private static void Message(System.String message) { if (infoStream != null) { infoStream.WriteLine("SIS [" + ThreadClass.Current().Name + "]: " + message); } }
public void Debug(string s) { if (ShowDebugInfo) { Console.Error.WriteLine(ThreadClass.Current().Name + "->" + s); } }
private bool DecrWaiters() { NumWaiting--; bool removed = Waiting.Remove(ThreadClass.Current()); Debug.Assert(removed); return(NumWaiting >= 0); }
private bool IncWaiters() { NumWaiting++; bool existed = Waiting.ContainsKey(ThreadClass.Current()); Debug.Assert(!existed); Waiting[ThreadClass.Current()] = true; return(NumWaiting > 0); }
private static RandomizedContext Create(ThreadGroup tg, Type suiteClass, RandomizedRunner runner) { lock (globalLock) { var context = new RandomizedContext(tg, suiteClass, runner); contexts.Add(tg, context); context.threadResources.Add(ThreadClass.Current(), new ThreadResources()); return(context); } }
public /*internal*/ override bool TestPoint(System.String name) { if (Enclosing_Instance.doFail.Value != null && !name.Equals("startDoFlush") && r.Next(20) == 17) { if (Lucene.Net.Index.TestIndexWriterExceptions.DEBUG) { System.Console.Out.WriteLine(ThreadClass.Current().Name + ": NOW FAIL: " + name); //new Throwable().printStackTrace(System.out); } throw new System.SystemException(ThreadClass.Current().Name + ": intentionally failing at " + name); } return(true); }
private void InitMergeThreadPriority() { lock (this) { if (mergeThreadPriority == -1) { // Default to slightly higher priority than our // calling thread mergeThreadPriority = 1 + (System.Int32)ThreadClass.Current().Priority; if (mergeThreadPriority > (int)System.Threading.ThreadPriority.Highest) { mergeThreadPriority = (int)System.Threading.ThreadPriority.Highest; } } } }
private void InitMergeThreadPriority() { lock (this) { if (MergeThreadPriority_Renamed == -1) { // Default to slightly higher priority than our // calling thread MergeThreadPriority_Renamed = 1 + (int)ThreadClass.Current().Priority; if (MergeThreadPriority_Renamed > (int)ThreadPriority.Highest) { MergeThreadPriority_Renamed = (int)ThreadPriority.Highest; } } } }
override public void Run() { long stopTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) + 1000 * RUN_TIME_SEC; try { while ((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) < stopTime && !AnyErrors()) { DoWork(); } } catch (System.Exception e) { System.Console.Out.WriteLine(ThreadClass.Current() + ": exc"); System.Console.Out.WriteLine(e.StackTrace); failed = true; } }
/// <summary> /// Reschedules the jobs in this job queue to other slaves in the system. It assumes that the slave associated /// with this queue has already been removed from the available slaves, such that it is not assigned its own jobs. /// </summary> /// <remarks>Only called when we're shutting down, so we're not waiting for any notification.</remarks> public virtual void RescheduleJobs(IEvolutionState state) { while (true) { IJob job; lock (_jobs) { if ((_jobs.Count == 0)) { return; } var tempObject = _jobs[0]; _jobs.RemoveAt(0); job = tempObject; } Debug(ThreadClass.Current().Name + " Waiting for a slave to reschedule the evaluation."); job.Sent = false; // reuse SlaveMonitor.ScheduleJobForEvaluation(State, job); Debug(ThreadClass.Current().Name + " Got a slave to reschedule the evaluation."); } }
private void Message(System.String message) { infoStream.WriteLine("IFD [" + new DateTime().ToString() + "; " + ThreadClass.Current().Name + "]: " + message); }
public virtual void Run() { ThreadClass.Current().Name = "SlaveMonitor:: "; TcpClient slaveSock; while (!Enclosing_Instance.ShutdownInProgress) { slaveSock = null; while (slaveSock == null && !Enclosing_Instance.ShutdownInProgress) { try { slaveSock = Enclosing_Instance.ServSock.AcceptTcpClient(); } catch (IOException) { slaveSock = null; } } Enclosing_Instance.Debug(ThreadClass.Current().Name + " Slave attempts to connect."); if (Enclosing_Instance.ShutdownInProgress) { break; } try { Stream tmpIn = slaveSock.GetStream(); Stream tmpOut = slaveSock.GetStream(); if (Enclosing_Instance.UseCompression) { /* * state.Output.Fatal("JDK 1.5 has broken compression. For now, you must set eval.compression=false"); * tmpIn = new CompressingInputStream(tmpIn); * tmpOut = new CompressingOutputStream(tmpOut); */ tmpIn = Output.MakeCompressingInputStream(tmpIn); tmpOut = Output.MakeCompressingOutputStream(tmpOut); if (tmpIn == null || tmpOut == null) { Output.InitialError( "You do not appear to have JZLib installed on your system, and so must set eval.compression=false. " + "To get JZLib, download from the ECJ website or from http://www.jcraft.com/jzlib/", false); Environment.Exit(1); // This was originally part of the InitialError call in ECJ. But we make SlaveMonitor responsible. } } var dataIn = new BinaryReader(tmpIn); var dataOut = new BinaryWriter(tmpOut); var slaveName = dataIn.ReadString(); dataOut.Write(Enclosing_Instance.RandomSeed); Enclosing_Instance.RandomSeed += SEED_INCREMENT; // Write random state for eval thread to slave dataOut.Flush(); // write out additional data as necessary _problemPrototype.SendAdditionalData(_state, dataOut); dataOut.Flush(); // write out additional data as necessary _problemPrototype.SendAdditionalData(_state, dataOut); dataOut.Flush(); Enclosing_Instance.RegisterSlave(_state, slaveName, slaveSock, dataOut, dataIn); _state.Output.SystemMessage("Slave " + slaveName + " connected successfully."); } catch (IOException) { } } Enclosing_Instance.Debug(ThreadClass.Current().Name + " The monitor is shutting down."); }
override public void Run() { Document doc = new Document(); doc.Add(new Field("content1", "aaa bbb ccc ddd", Field.Store.YES, Field.Index.ANALYZED, enclosingInstance.RandomTVSetting(enclosingInstance.random))); doc.Add(new Field("content6", "aaa bbb ccc ddd", Field.Store.NO, Field.Index.ANALYZED, enclosingInstance.RandomTVSetting(enclosingInstance.random))); doc.Add(new Field("content2", "aaa bbb ccc ddd", Field.Store.YES, Field.Index.NOT_ANALYZED, enclosingInstance.RandomTVSetting(enclosingInstance.random))); doc.Add(new Field("content3", "aaa bbb ccc ddd", Field.Store.YES, Field.Index.NO)); doc.Add(new Field("content4", "aaa bbb ccc ddd", Field.Store.NO, Field.Index.ANALYZED, enclosingInstance.RandomTVSetting(enclosingInstance.random))); doc.Add(new Field("content5", "aaa bbb ccc ddd", Field.Store.NO, Field.Index.NOT_ANALYZED, enclosingInstance.RandomTVSetting(enclosingInstance.random))); doc.Add(new Field("content7", "aaa bbb ccc ddd", Field.Store.NO, Field.Index.NOT_ANALYZED, enclosingInstance.RandomTVSetting(enclosingInstance.random))); Field idField = new Field("id", "", Field.Store.YES, Field.Index.NOT_ANALYZED, enclosingInstance.RandomTVSetting(enclosingInstance.random)); doc.Add(idField); long stopTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) + 3000; while ((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) < stopTime) { Enclosing_Instance.doFail.Value = this; System.String id = "" + r.Next(50); idField.SetValue(id); Term idTerm = new Term("id", id); try { writer.UpdateDocument(idTerm, doc, null); } catch (System.SystemException re) { if (Lucene.Net.Index.TestIndexWriterExceptions.DEBUG) { System.Console.Out.WriteLine(ThreadClass.CurrentThread().Name + ": EXC: "); System.Console.Out.WriteLine(re.StackTrace); } try { _TestUtil.CheckIndex(writer.Directory); } catch (System.IO.IOException ioe) { System.Console.Out.WriteLine(ThreadClass.Current().Name + ": unexpected exception1"); System.Console.Out.WriteLine(ioe.StackTrace); failure = ioe; break; } } catch (System.Exception t) { System.Console.Out.WriteLine(ThreadClass.Current().Name + ": unexpected exception2"); System.Console.Out.WriteLine(t.StackTrace); failure = t; break; } Enclosing_Instance.doFail.Value = null; // After a possible exception (above) I should be able // to add a new document without hitting an // exception: try { writer.UpdateDocument(idTerm, doc, null); } catch (System.Exception t) { System.Console.Out.WriteLine(ThreadClass.Current().Name + ": unexpected exception3"); System.Console.Out.WriteLine(t.StackTrace); failure = t; break; } } }
public Randomness(int seed, params ISeedDecorator[] decorators) : this(ThreadClass.Current(), seed, decorators) { }
public virtual bool WriteLoop() { IJob job; try { lock (_jobs) { // check for an unsent job if ((job = OldestUnsentJob()) == null) // automatically marks as sent { // failed -- wait and drop out of the loop and come in again Debug("" + ThreadClass.Current().Name + "Waiting for a job to send"); SlaveMonitor.WaitOnMonitor(_jobs); } } if (job != null) // we got a job inside our synchronized wait { // send the job Debug("" + ThreadClass.Current().Name + "Sending Job"); if (job.Type == SlaveEvaluationType.Simple) { // Tell the server we're evaluating a SimpleProblemForm DataOut.Write((byte)SlaveEvaluationType.Simple); } else { // Tell the server we're evaluating a IGroupedProblem DataOut.Write((byte)SlaveEvaluationType.Grouped); // Tell the server whether to count victories only or not. DataOut.Write(job.CountVictoriesOnly); } // transmit number of individuals DataOut.Write(job.Inds.Length); // Transmit the subpops to the slave foreach (var t in job.Subpops) { DataOut.Write(t); } Debug("Starting to transmit individuals"); // Transmit the individuals to the server for evaluation... for (var i = 0; i < job.Inds.Length; i++) { job.Inds[i].WriteIndividual(State, DataOut); DataOut.Write(job.UpdateFitness[i]); } DataOut.Flush(); } } catch (Exception) { Shutdown(State); return(false); } return(true); }