/// <summary> /// Creates an instance of EventPipeline. /// </summary> /// <param name="settings">The configuration settings for event pipeline.</param> public OneDSEventPipeline(OneDSEventPipelineSettings settings, ILogger logger) { if (settings == null) { #if TPL_35 throw new ArgumentNullException("settings"); #else throw new ArgumentNullException(nameof(settings)); #endif } this.settings = settings; if (logger == null) { #if TPL_35 throw new ArgumentNullException("logger"); #else throw new ArgumentNullException(nameof(logger)); #endif } this.logger = logger; this.batchingStage = new EventBatchingStage(this.settings.BatchSize, this.settings.BatchFillTimeout, logger); this.sendingStage = new EventSendingStage(logger); }
/// <summary> /// Creates a new <see cref="ReactionPipelineStage"/> with the specified reaction to the specified inputs. /// </summary> /// <param name="reaction">The reaction delegate.</param> /// <param name="input1">Input number 1.</param> /// <param name="input2">Input number 2.</param> public ReactionPipelineStage( Action <TInput1, TInput2> reaction, IPipelineStage <TInput1> input1, IPipelineStage <TInput2> input2) : this(GetDefaultName(input1, input2), reaction, input1, input2) { }
/// <summary> /// Performs stage specific processing on the compiler context. /// </summary> public void Run() { // Previous stage IPipelineStage prevStage = MethodCompiler.GetPreviousStage(typeof(IMethodCompilerStage)); // Line number int index = 1; Debug.WriteLine(String.Format("IR representation of method {0} after stage {1}", MethodCompiler.Method, prevStage.Name)); foreach (BasicBlock block in BasicBlocks) { Debug.WriteLine(String.Format("Block #{0} - label L_{1:X4}", index, block.Label)); foreach (BasicBlock prev in block.PreviousBlocks) { Debug.WriteLine(String.Format(" Prev: L_{0:X4}", prev.Label)); } Debug.Indent(); LogInstructions(new Context(InstructionSet, block)); Debug.Unindent(); foreach (BasicBlock next in block.NextBlocks) { Debug.WriteLine(String.Format(" Next: L_{0:X4}", next.Label)); } index++; } }
public void GarbageCollectionDoNotDisposeStagesReferencedByAlivePipelineStage() { var source = 1.AsPipelineConstant(); var fork = source.WithCache().AsEager().AsThreadSafe(); var aliveObject = fork.AsThreadSafe().AsPassive(); var deadObject = fork.AsAsync().AsDetachable(); deadObject = null; // --- needed for release test to correctly remove the dead object. Not always released in debug configuration. for (int i = 0; i < 100; ++i) { CreateMemoryPressure(1024 * 1024); } GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true); IPipelineStage cursor = source; for (int i = 0; i < 5; ++i) { var dependentStages = cursor.GetAllDependentStages().ToList(); Assert.AreEqual(1, dependentStages.Count); cursor = dependentStages.Single(); } Assert.IsFalse(cursor.GetAllDependentStages().Any()); GC.KeepAlive(aliveObject); }
/// <summary> /// Creates a new <see cref="ReactionPipelineStage"/> with the specified reaction to the specified inputs. /// </summary> /// <param name="reaction">The reaction delegate.</param> /// <param name="input1">Input number 1.</param> /// <param name="reactImmediately">Denotes if the reaction should fire immediately upon construction.</param> public ReactionPipelineStage( Action <TInput1> reaction, IPipelineStage <TInput1> input1, bool reactImmediately) : this(GetDefaultName(input1), reaction, input1, reactImmediately) { }
public static IPipelineStage Create<TInput1, TInput2>( Action<TInput1, TInput2> reaction, IPipelineStage<TInput1> input1, IPipelineStage<TInput2> input2) => new ReactionPipelineStage<TInput1, TInput2>( reaction, input1, input2);
/// <summary> HACK хаменяет стейдж который уже есть в системе, в том числе уже может выполняться, на другой стейдж. </summary> public void ReplaceStage(IPipelineStage targetToRemove, IPipelineStage newStage) { if (newStage.State != PipelineStates.Ready) { Debug.LogError("ReplaceStage(" + targetToRemove + "," + newStage + ") // Новый стейдж находится в неподходящем состоянии для этой и так кривой операции"); return; } // Все, кто был за этим элементом в очереди больше не помеха. foreach (var stage in Stages.Where(stage => stage.Previous.Contains(newStage))) { stage.RemovePreviouse(newStage); } // И самому ему никаких предыдущих больше не надо. while (newStage.Previous.Any()) { newStage.RemovePreviouse(newStage.Previous.First()); } // Теперь его предыдущие это предыдущие тех, кого он заменяет. foreach (var stage in targetToRemove.Previous) { newStage.AddPreviouse(stage); } // И сам он предыдущий тем, кому раньше был предыдущим заменяемый. foreach (var stage in Stages.Where(stage => stage.Previous.Contains(targetToRemove))) { stage.AddPreviouse(newStage); } }
public void AddCreatedStage(IPipelineStage stage) { stage.CompleteEvent += OnCompleteStage; stage.Log += AddLogString; stage.LogStages = _prefix != null || _logInstant; Stages.Add(stage); }
private bool Visit(IPipelineStage stage, List <PipelineStagePropagation> result) { var mark = GetMark(stage); if (mark == Mark.TemporaryMark) { return(true); } if (mark == Mark.PermanentMark) { return(false); } SetMark(stage, Mark.TemporaryMark); var dependents = new List <IPipelineStage>(); foreach (var wr in GetDependentStages(stage)) { if (!wr.TryGetTarget(out var dependent)) { continue; } dependents.Add(dependent); if (Visit(dependent, result)) { return(true); } } SetMark(stage, Mark.PermanentMark); result.Add(new PipelineStagePropagation(stage, dependents)); return(false); }
public bool Contains(Vector3Int chunkID) { var thinkWeContain = chunkStageMap.ContainsKey(chunkID); var actuallyContain = false; IPipelineStage containingStage = null; foreach (var stage in stages) { if (stage.Contains(chunkID)) { actuallyContain = true; containingStage = stage; break; } } if (!thinkWeContain && actuallyContain) { ///Wait for job stages may still contain items when the stage map does not. ///No other stage is allowed to do this though. Assert.IsTrue(containingStage is IWaitForJobStage, $"Chunk stage map contains id {chunkID} = {thinkWeContain}, any of the stages contain the id = {actuallyContain}." + $" Containing stage name if applicable = {containingStage.Name}"); } return(thinkWeContain); }
/// <summary> /// Removes the specified dependencies from this stage. /// </summary> /// <param name="dependee">The stage to remove dependencies for.</param> /// <param name="dependencies">The dependencies to remove.</param> public static void RemoveDependencies(this IPipelineStage dependee, params IPipelineStage[] dependencies) { lock (Dependencies) { foreach (var dependency in dependencies) { if (dependency == null) { IncrementOperation(); MarkPipelineAsUpdated(); throw new ArgumentNullException("Entry in dependency list", "One or more entries in the given dependency list was null."); } var strong = new AmbivalentPipelineReference(dependency, true); if (!Dependencies.TryGetValue(strong, out var deps)) { continue; } TotalWeakKeys -= deps.RemoveAll(r => !r.TryGetTarget(out var reference) || reference == dependee); GC.KeepAlive(dependency); } IncrementOperation(); // TODO: remove this? Removed dependencies should never affect the propagation of the pipeline graph in any way. MarkPipelineAsUpdated(); } }
/// <summary> /// Creates a new OperationPipelineStage with the specified name, operation and inputs. /// </summary> /// <param name="name">The name of the operation.</param> /// <param name="operation">The operation.</param> /// <param name="input1">Input number 1.</param> /// <param name="input2">Input number 2.</param> /// <param name="input3">Input number 3.</param> public OperationPipelineStage( string name, Func <TInput1, TInput2, TInput3, TOutput> operation, IPipelineStage <TInput1> input1, IPipelineStage <TInput2> input2, IPipelineStage <TInput3> input3) : this(name, operation?.AsPipelineConstant() !, input1, input2, input3)
/// <summary> /// Add dependencies for this pipeline stage, propagation on their invalidation. /// </summary> /// <param name="dependee">The stage to add dependencies for.</param> /// <param name="dependencies">The dependencies to add.</param> public static void AddDependencies(this IPipelineStage dependee, params IPipelineStage[] dependencies) { lock (Dependencies) { foreach (var dependency in dependencies) { if (dependency == null) { IncrementOperation(); MarkPipelineAsUpdated(); throw new ArgumentNullException("Entry in dependency list", "One or more entries in the given dependency list was null."); } var weak = new AmbivalentPipelineReference(dependency, false); if (!Dependencies.TryGetValue(weak, out var deps)) { deps = new List <WeakReference <IPipelineStage> >(); Dependencies.Add(weak, deps); } deps.Add(new WeakReference <IPipelineStage>(dependee)); ++TotalWeakKeys; GC.KeepAlive(dependency); //keep the reference alive at least until it can be added in the dictionary } IncrementOperation(); MarkPipelineAsUpdated(); } }
/// <summary> /// Creates a new <see cref="ReactionPipelineStage"/> with the specified name and reaction to the specified inputs. /// </summary> /// <param name="name">The name of the new reaction.</param> /// <param name="reaction">The reaction delegate.</param> /// <param name="input1">Input number 1.</param> /// <param name="input2">Input number 2.</param> /// <param name="input3">Input number 3.</param> /// <param name="input4">Input number 4.</param> /// <param name="input5">Input number 5.</param> /// <param name="input6">Input number 6.</param> /// <param name="input7">Input number 7.</param> /// <param name="reactImmediately">Denotes if the reaction should fire immediately upon construction.</param> public ReactionPipelineStage( string name, Action <TInput1, TInput2, TInput3, TInput4, TInput5, TInput6, TInput7> reaction, IPipelineStage <TInput1> input1, IPipelineStage <TInput2> input2, IPipelineStage <TInput3> input3, IPipelineStage <TInput4> input4, IPipelineStage <TInput5> input5, IPipelineStage <TInput6> input6, IPipelineStage <TInput7> input7, bool reactImmediately) { Name = name ?? throw new ArgumentNullException(nameof(name)); Reaction = reaction ?? throw new ArgumentNullException(nameof(reaction)); Input1 = input1 ?? throw new ArgumentNullException(nameof(input1)); Input2 = input2 ?? throw new ArgumentNullException(nameof(input2)); Input3 = input3 ?? throw new ArgumentNullException(nameof(input3)); Input4 = input4 ?? throw new ArgumentNullException(nameof(input4)); Input5 = input5 ?? throw new ArgumentNullException(nameof(input5)); Input6 = input6 ?? throw new ArgumentNullException(nameof(input6)); Input7 = input7 ?? throw new ArgumentNullException(nameof(input7)); this.AddDependencies(input1, input2, input3, input4, input5, input6, input7); if (reactImmediately) { Reaction(Input1.GetValue(), Input2.GetValue(), Input3.GetValue(), Input4.GetValue(), Input5.GetValue(), Input6.GetValue(), Input7.GetValue()); } }
public RegisterEventAfter(IPipelineStage pipelineStage, List <IPipelineEvent> eventsToExecute, IPipelineEvent pipelineEvent) { _pipelineStage = pipelineStage; _eventsToExecute = eventsToExecute; _pipelineEvent = pipelineEvent; }
/// <summary> /// Creates a new <see cref="MultiplexingPipelineStage{TSelect, TOutput}"/> with the given select signal, inputs and select signal comparer. /// </summary> /// <param name="name">The name of this pipeline stage.</param> /// <param name="select">The select signal.</param> /// <param name="inputs">The input stages.</param> public MultiplexingPipelineStage( string name, IPipelineStage <TSelect> select, IDictionary <TSelect, IPipelineStage <TOutput> > inputs) : this(name, select, inputs, EqualityComparer <TSelect> .Default) { }
internal void AddEdge(IPipelineStage from, IPipelineStage to) { var fn = AddNode(from, false); var tn = AddNode(to, false); fn.AddDependentNode(tn); }
/// <summary> Добавлять в хранилища предыдущих только через этот метод. </summary> public IPipelineStage AddPreviouse(IPipelineStage stage) { if (stage == null) { return(this); } if (State < PipelineStates.Execution) { #if UNITY_EDITOR if (!_previouse.Contains(stage)) { #endif _previouse.Add(stage); stage.CompleteEvent += OnPreviouseComplete; #if UNITY_EDITOR } else { UnityEngine.Debug.LogWarning( $"К стадии {this} повторно добавляется один и тот же предыдущий {stage}. Это крайне подозрительно и, вероятно, ошибка."); } #endif } else { UnityEngine.Debug.LogWarning( $"К стадии {this} добавляется предыдущий, хотя стадия уже неподходит для этого. Это крайне подозрительно и, вероятно, ошибка."); } return(this); }
/// <summary> /// Creates a new <see cref="ReactionPipelineStage"/> with the specified name and reaction to the specified inputs. /// </summary> /// <param name="name">The name of the new reaction.</param> /// <param name="reaction">The reaction delegate.</param> /// <param name="input1">Input number 1.</param> public ReactionPipelineStage( string name, Action <TInput1> reaction, IPipelineStage <TInput1> input1) : this(name, reaction, input1, true) { }
public DispatcherReactionPipelineStage( string name, Action <TInput1, TInput2, TInput3, TInput4, TInput5> reaction, Dispatcher dispatcher, IPipelineStage <TInput1> input1, IPipelineStage <TInput2> input2, IPipelineStage <TInput3> input3, IPipelineStage <TInput4> input4, IPipelineStage <TInput5> input5, bool reactImmediately) { Name = name ?? throw new ArgumentNullException(nameof(name)); Reaction = reaction ?? throw new ArgumentNullException(nameof(reaction)); Dispatcher = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher)); Input1 = input1 ?? throw new ArgumentNullException(nameof(input1)); Input2 = input2 ?? throw new ArgumentNullException(nameof(input2)); Input3 = input3 ?? throw new ArgumentNullException(nameof(input3)); Input4 = input4 ?? throw new ArgumentNullException(nameof(input4)); Input5 = input5 ?? throw new ArgumentNullException(nameof(input5)); this.AddDependencies(input1, input2, input3, input4, input5); if (reactImmediately) { InvokeReaction(Input1.GetValue(), Input2.GetValue(), Input3.GetValue(), Input4.GetValue(), Input5.GetValue()); } }
public DispatcherReactionPipelineStage( Action<TInput1, TInput2> reaction, IPipelineStage<TInput1> input1, IPipelineStage<TInput2> input2, bool reactImmediately) : this(GetDefaultName(input1, input2), reaction, DispatcherUtilities.DefaultDispatcher, input1, input2, reactImmediately) { }
public void InvalidateAllDependentStages(IPipelineStage stage) { foreach (var dependent in DependentStages) { Invalidate(dependent); } }
/// <summary> /// Creates a new <see cref="SuspendingPipelineStage{TValue}"/> with the specified input and suspension input. /// </summary> /// <param name="input">The input to suspend.</param> /// <param name="suspend">The stage providing the current suspension state.</param> public SuspendingPipelineStage(IPipelineStage <TValue> input, IPipelineStage <PipelineSuspensionState> suspend) { Input = input ?? throw new ArgumentNullException(nameof(input)); Suspend = suspend ?? throw new ArgumentNullException(nameof(suspend)); Name = "Suspender for: " + input.Name; this.AddDependencies(input, suspend); }
public DispatcherReactionPipelineStage( string name, Action<TInput1, TInput2> reaction, IPipelineStage<TInput1> input1, IPipelineStage<TInput2> input2) : this(name, reaction, DispatcherUtilities.DefaultDispatcher, input1, input2, true) { }
public static IPipelineStage Create <TInput1>( Action <TInput1> reaction, IPipelineStage <TInput1> input1, bool reactImmediately) => new ReactionPipelineStage <TInput1>( reaction, input1, reactImmediately);
public DispatcherReactionPipelineStage( Action <TInput1, TInput2, TInput3> reaction, IPipelineStage <TInput1> input1, IPipelineStage <TInput2> input2, IPipelineStage <TInput3> input3) : this(GetDefaultName(input1, input2, input3), reaction, input1, input2, input3) { }
public FilterContentStage(IContentFilterFactory contentFilterFactory, IPipelineStage nextStage) { _contentFilterFactory = contentFilterFactory; _nextStage = nextStage; _contentFilters = _contentFilterFactory.GenerateFilters(); }
/// <summary> /// Creates a new <see cref="MutuallyExclusivePipelineStage{TValue}"/> with the specified input and mutually exclusive stages. /// </summary> /// <param name="input">The input stage.</param> /// <param name="mutuallyExclusiveWith">The stages which, if invalidated at the time of propagation, will cause this stage to stop propagation.</param> /// <exception cref="ArgumentNullException">If <paramref name="input"/> or <paramref name="mutuallyExclusiveWith"/> is null.</exception> public MutuallyExclusivePipelineStage(IPipelineStage <TValue> input, params IPipelineStage[] mutuallyExclusiveWith) { Input = input ?? throw new ArgumentNullException(nameof(input)); MutuallyExclusiveWith = mutuallyExclusiveWith ?? throw new ArgumentNullException(nameof(mutuallyExclusiveWith)); this.AddDependencies(input); this.AddDependencies(mutuallyExclusiveWith); Name = $"'{Input}' mutually exclusive with {{{string.Join(", ", MutuallyExclusiveWith.Select(stage => $"'{stage.Name}'"))}}}"; }
public ParseErrorStage(IErrorParser errorParser, IEventDiscarder eventDiscarder, IPipelineStage nextStage) { _errorParser = errorParser; _eventDiscarder = eventDiscarder; _nextStage = nextStage; }
public static IPipelineStage Create <TInput1>( string name, Action <TInput1> reaction, IPipelineStage <TInput1> input1) => new ReactionPipelineStage <TInput1>( name, reaction, input1);
/// <summary> Сахарок для добавления нескольких элементов. </summary> public IPipelineStage AddPreviouse(IPipelineStage stage, params IPipelineStage[] others) { AddPreviouse(stage); foreach (var prev in others) { AddPreviouse(prev); } return(this); }
public bool Invalidate(IPipelineStage stage) { if (Invalidated.Add(stage)) { InvalidatedByThisStep.Add(stage); return(true); } return(false); }
public static void Run(BaseMethodCompiler methodCompiler, IPipelineStage stage) { Run( methodCompiler.Trace, methodCompiler.FormatStageName(stage), methodCompiler.Method, methodCompiler.BasicBlocks ); }
public static void Run(BaseMethodCompiler methodCompiler, IPipelineStage stage) { Run( methodCompiler.InternalTrace, methodCompiler.FormatStageName(stage), methodCompiler.Method, methodCompiler.InstructionSet, methodCompiler.BasicBlocks ); }
public static void Run(IMethodCompiler methodCompiler, IPipelineStage stage) { Run( methodCompiler.InternalTrace, stage, methodCompiler.Method, methodCompiler.InstructionSet, methodCompiler.BasicBlocks ); }
public EventFilterStage(IEventFilterFactory eventFilterFactory, IEventRejecter eventRejecter, IPipelineStage nextStage) { _eventFilterFactory = eventFilterFactory; _eventRejecter = eventRejecter; _nextStage = nextStage; _eventFilters = _eventFilterFactory.GenerateFilters(); }
public BatchLogIngestor(IEventFilterFactory eventFilterFactory = null, IErrorParser errorParser = null, IContentFilterFactory contentFilterFactory = null, IEventDiscarder eventDiscarder = null, IEventPersister eventPersister = null, IEventRejecter eventRejecter = null) { _eventPersister = eventPersister; _eventFilterFactory = eventFilterFactory; _eventDiscarder = eventDiscarder; _errorParser = errorParser; _contentFilterFactory = contentFilterFactory; _eventRejecter = eventRejecter; _firstPipelineStage = BuildPipeline(); }
public static void Run(IInternalTrace internalLog, IPipelineStage stage, RuntimeMethod method, InstructionSet instructionSet, BasicBlocks basicBlocks) { if (internalLog == null) return; if (internalLog.TraceListener == null) return; if (!internalLog.TraceFilter.IsMatch(method, stage.Name)) return; StringBuilder text = new StringBuilder(); // Line number int index = 1; text.AppendLine(String.Format("IR representation of method {0} after stage {1}:", method, stage.Name)); text.AppendLine(); if (basicBlocks.Count > 0) { foreach (BasicBlock block in basicBlocks) { text.AppendFormat("Block #{0} - Label L_{1:X4}", index, block.Label); if (basicBlocks.IsHeaderBlock(block)) text.Append(" [Header]"); text.AppendLine(); text.AppendFormat(" Prev: "); text.AppendLine(ListBlocks(block.PreviousBlocks)); LogInstructions(text, new Context(instructionSet, block)); text.AppendFormat(" Next: "); text.AppendLine(ListBlocks(block.NextBlocks)); text.AppendLine(); index++; } } else { LogInstructions(text, new Context(instructionSet, 0)); } internalLog.TraceListener.SubmitInstructionTraceInformation(method, stage.Name, text.ToString()); }
public StreamLogIngestor(IEventFilterFactory eventFilterFactory, IErrorParser errorParser, IContentFilterFactory contentFilterFactory, IEventDiscarder eventDiscarder, IPersisterDaemon persisterDaemon, IEventRejecter eventRejecter) { _eventFilterFactory = eventFilterFactory; _eventDiscarder = eventDiscarder; _errorParser = errorParser; _contentFilterFactory = contentFilterFactory; _persisterDaemon = persisterDaemon; _eventRejecter = eventRejecter; _firstPipelineStage = BuildPipeline(); _cancellationTokenSource = new CancellationTokenSource(); _persisterDaemon.Start(_cancellationTokenSource.Token); }
/// <summary> /// Gets the previous stage. /// </summary> /// <param name="stage">The stage.</param> /// <returns> /// The previous compilation stage supporting the requested type or null. /// </returns> public IPipelineStage GetPreviousStage(IPipelineStage stage) { return GetPreviousStage(typeof(IPipelineStage)); }
public FingerprintStage(IPipelineStage nextStage) { _nextStage = nextStage; }
public string FormatStageName(IPipelineStage stage) { return "[" + Pipeline.GetPosition(stage).ToString("00") + "] " + stage.Name; }
/// <summary> /// Initializes a new instance of the <see cref="InstructionLogger"/> class. /// </summary> /// <param name="after">The after.</param> /// <param name="before">The before.</param> public InstructionLogger(IPipelineStage after, IPipelineStage before) { _pipelineOrder = PipelineStageOrder.CreatePipelineOrder(after.GetType(), before.GetType()); }