protected SubSinkInlet <TOut> CreateSubInlet(Outlet <TOut> outlet) { var sinkIn = new SubSinkInlet <TOut>(this, $"RestartWithBackoff{_name}.subIn"); sinkIn.SetHandler(new LambdaInHandler( onPush: () => Push(Out, sinkIn.Grab()), onUpstreamFinish: () => { if (_finishing || MaxRestartsReached() || _onlyOnFailures) { Complete(Out); } else { Log.Debug("Restarting graph due to finished upstream"); ScheduleRestartTimer(); } }, onUpstreamFailure: ex => { if (_finishing || MaxRestartsReached()) { Fail(Out, ex); } else { Log.Warning($"Restarting graph due to failure. Stacktrace: {ex.StackTrace}"); ScheduleRestartTimer(); } })); SetHandler(Out, onPull: () => sinkIn.Pull(), onDownstreamFinish: () => { _finishing = true; sinkIn.Cancel(); }); return(sinkIn); }
protected SubSinkInlet <TOut> CreateSubInlet(Outlet <TOut> outlet) { var sinkIn = new SubSinkInlet <TOut>(this, $"RestartWithBackoff{_name}.subIn"); sinkIn.SetHandler(new LambdaInHandler( onPush: () => Push(Out, sinkIn.Grab()), onUpstreamFinish: () => { if (_finishing) { Complete(Out); } else { Log.Debug("Graph out finished"); OnCompleteOrFailure(); } }, onUpstreamFailure: ex => { if (_finishing) { Fail(Out, ex); } else { Log.Error(ex, "Restarting graph due to failure"); OnCompleteOrFailure(); } })); SetHandler(Out, onPull: () => sinkIn.Pull(), onDownstreamFinish: () => { _finishing = true; sinkIn.Cancel(); }); return(sinkIn); }
private void OnTaskSourceCompleted(Task <Source <T, M> > t) { try { var runnable = Source.FromGraph(t.Result).ToMaterialized(_sinkIn.Sink, Keep.Left); var materializedValue = Interpreter.SubFusingMaterializer.Materialize(runnable, _stage.InitialAttributes); _materialized.TrySetResult(materializedValue); SetHandler(_stage.Outlet, this); _sinkIn.SetHandler(this); if (IsAvailable(_stage.Outlet)) { _sinkIn.Pull(); } } catch (Exception ex) { _sinkIn.Cancel(); _materialized.TrySetException(ex); FailStage(ex); } }