private static async Task DispatchAsync <T>(DispatchEventHandler <T> handler, T message) { using (var operation = new DisposableOperation(() => handler.OnNext(message))) { await operation.Run(); } }
private DriverBridge( // Runtime events [Parameter(Value = typeof(DriverApplicationParameters.DriverStartedHandlers))] ISet <IObserver <IDriverStarted> > driverStartHandlers, [Parameter(Value = typeof(DriverApplicationParameters.DriverStopHandlers))] ISet <IObserver <IDriverStopped> > driverStopHandlers, // Evaluator events [Parameter(Value = typeof(DriverApplicationParameters.AllocatedEvaluatorHandlers))] ISet <IObserver <IAllocatedEvaluator> > allocatedEvaluatorHandlers, [Parameter(Value = typeof(DriverApplicationParameters.FailedEvaluatorHandlers))] ISet <IObserver <IFailedEvaluator> > failedEvaluatorHandlers, [Parameter(Value = typeof(DriverApplicationParameters.CompletedEvaluatorHandlers))] ISet <IObserver <ICompletedEvaluator> > completedEvaluatorHandlers, // Context events [Parameter(Value = typeof(DriverApplicationParameters.ActiveContextHandlers))] ISet <IObserver <IActiveContext> > activeContextHandlers, [Parameter(Value = typeof(DriverApplicationParameters.ClosedContextHandlers))] ISet <IObserver <IClosedContext> > closedContextHandlers, [Parameter(Value = typeof(DriverApplicationParameters.FailedContextHandlers))] ISet <IObserver <IFailedContext> > failedContextHandlers, [Parameter(Value = typeof(DriverApplicationParameters.ContextMessageHandlers))] ISet <IObserver <IContextMessage> > contextMessageHandlers, // Task events [Parameter(Value = typeof(DriverApplicationParameters.TaskMessageHandlers))] ISet <IObserver <ITaskMessage> > taskMessageHandlers, [Parameter(Value = typeof(DriverApplicationParameters.FailedTaskHandlers))] ISet <IObserver <IFailedTask> > failedTaskHandlers, [Parameter(Value = typeof(DriverApplicationParameters.RunningTaskHandlers))] ISet <IObserver <IRunningTask> > runningTaskHandlers, [Parameter(Value = typeof(DriverApplicationParameters.CompletedTaskHandlers))] ISet <IObserver <ICompletedTask> > completedTaskHandlers, [Parameter(Value = typeof(DriverApplicationParameters.SuspendedTaskHandlers))] ISet <IObserver <ISuspendedTask> > suspendedTaskHandlers, // Driver restart events [Parameter(Value = typeof(DriverApplicationParameters.DriverRestartedHandlers))] ISet <IObserver <IDriverRestarted> > driverRestartedHandlers, [Parameter(Value = typeof(DriverApplicationParameters.DriverRestartActiveContextHandlers))] ISet <IObserver <IActiveContext> > driverRestartActiveContextHandlers, [Parameter(Value = typeof(DriverApplicationParameters.DriverRestartRunningTaskHandlers))] ISet <IObserver <IRunningTask> > driverRestartRunningTaskHandlers, [Parameter(Value = typeof(DriverApplicationParameters.DriverRestartCompletedHandlers))] ISet <IObserver <IDriverRestartCompleted> > driverRestartCompletedHandlers, [Parameter(Value = typeof(DriverApplicationParameters.DriverRestartFailedEvaluatorHandlers))] ISet <IObserver <IFailedEvaluator> > driverRestartFailedEvaluatorHandlers, // Client event [Parameter(Value = typeof(DriverApplicationParameters.ClientCloseWithMessageHandlers))] ISet <IObserver <byte[]> > clientCloseWithMessageHandlers, [Parameter(Value = typeof(DriverApplicationParameters.ClientCloseHandlers))] ISet <IObserver <byte[]> > clientCloseHandlers, [Parameter(Value = typeof(DriverApplicationParameters.ClientMessageHandlers))] ISet <IObserver <byte[]> > clientMessageHandlers, // Misc. [Parameter(Value = typeof(DriverApplicationParameters.TraceListeners))] ISet <TraceListener> traceListeners, [Parameter(Value = typeof(DriverApplicationParameters.TraceLevel))] string traceLevel) { _driverStartedDispatcher = new DispatchEventHandler <IDriverStarted>(driverStartHandlers); _driverStoppedDispatcher = new DispatchEventHandler <IDriverStopped>(driverStopHandlers); _allocatedEvaluatorDispatcher = new DispatchEventHandler <IAllocatedEvaluator>(allocatedEvaluatorHandlers); _failedEvaluatorDispatcher = new DispatchEventHandler <IFailedEvaluator>(failedEvaluatorHandlers); _completedEvaluatorDispatcher = new DispatchEventHandler <ICompletedEvaluator>(completedEvaluatorHandlers); _activeContextDispatcher = new DispatchEventHandler <IActiveContext>(activeContextHandlers); _closedContextDispatcher = new DispatchEventHandler <IClosedContext>(closedContextHandlers); _failedContextDispatcher = new DispatchEventHandler <IFailedContext>(failedContextHandlers); _contextMessageDispatcher = new DispatchEventHandler <IContextMessage>(contextMessageHandlers); _taskMessageDispatcher = new DispatchEventHandler <ITaskMessage>(taskMessageHandlers); _failedTaskDispatcher = new DispatchEventHandler <IFailedTask>(failedTaskHandlers); _runningTaskDispatcher = new DispatchEventHandler <IRunningTask>(runningTaskHandlers); _completedTaskDispatcher = new DispatchEventHandler <ICompletedTask>(completedTaskHandlers); _suspendedTaskDispatcher = new DispatchEventHandler <ISuspendedTask>(suspendedTaskHandlers); _driverRestartedDispatcher = new DispatchEventHandler <IDriverRestarted>(driverRestartedHandlers); _driverRestartActiveContextDispatcher = new DispatchEventHandler <IActiveContext>(driverRestartActiveContextHandlers); _driverRestartRunningTaskDispatcher = new DispatchEventHandler <IRunningTask>(driverRestartRunningTaskHandlers); _driverRestartCompletedDispatcher = new DispatchEventHandler <IDriverRestartCompleted>(driverRestartCompletedHandlers); _driverRestartFailedEvaluatorDispatcher = new DispatchEventHandler <IFailedEvaluator>(driverRestartFailedEvaluatorHandlers); _clientCloseDispatcher = new DispatchEventHandler <byte[]>(clientCloseHandlers); _clientCloseWithMessageDispatcher = new DispatchEventHandler <byte[]>(clientCloseWithMessageHandlers); _clientMessageDispatcher = new DispatchEventHandler <byte[]>(clientMessageHandlers); foreach (var listener in traceListeners) { Logger.AddTraceListener(listener); } Log.Log(Level.Info, "Constructing DriverBridge"); if (Enum.TryParse(traceLevel.ToString(CultureInfo.InvariantCulture), out Level level)) { Logger.SetCustomLevel(level); } else { Log.Log(Level.Warning, "Invalid trace level {0} provided, will by default use verbose level", traceLevel); } s_activeDispatchCounter = 0; }