public WorkerEventLoopGroup(DispatcherEventLoopGroup eventLoopGroup, int eventLoopCount) { if (eventLoopGroup is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.eventLoopGroup); } _dispatcherLoop = eventLoopGroup.Dispatcher; PipeName = _dispatcherLoop.PipeName; // Wait until the pipe is listening to connect _dispatcherLoop.WaitForLoopRun(StartTimeout); _eventLoops = new WorkerEventLoop[eventLoopCount]; var terminationTasks = new Task[eventLoopCount]; for (int i = 0; i < eventLoopCount; i++) { WorkerEventLoop eventLoop = null; bool success = false; try { eventLoop = new WorkerEventLoop(this); success = eventLoop.ConnectTask.Wait(StartTimeout); if (!success) { ThrowHelper.ThrowTimeoutException(PipeName); } } catch (Exception ex) { ThrowHelper.ThrowInvalidOperationException_CreateChild(ex); } finally { if (!success) { Task.WhenAll(_eventLoops.Take(i).Select(loop => loop.ShutdownGracefullyAsync())).Wait(); } } _eventLoops[i] = eventLoop; terminationTasks[i] = eventLoop.TerminationCompletion; } TerminationCompletion = Task.WhenAll(terminationTasks); }
public WorkerEventLoopGroup(DispatcherEventLoopGroup eventLoopGroup, int eventLoopCount) { Contract.Requires(eventLoopGroup != null); this.dispatcherLoop = eventLoopGroup.Dispatcher; this.PipeName = this.dispatcherLoop.PipeName; // Wait until the pipe is listening to connect this.dispatcherLoop.WaitForLoopRun(StartTimeout); this.eventLoops = new WorkerEventLoop[eventLoopCount]; var terminationTasks = new Task[eventLoopCount]; for (int i = 0; i < eventLoopCount; i++) { WorkerEventLoop eventLoop; bool success = false; try { eventLoop = new WorkerEventLoop(this); success = eventLoop.ConnectTask.Wait(StartTimeout); if (!success) { throw new TimeoutException($"Connect to dispatcher pipe {this.PipeName} timed out."); } } catch (Exception ex) { throw new InvalidOperationException($"Failed to create a child {nameof(WorkerEventLoop)}.", ex.Unwrap()); } finally { if (!success) { Task.WhenAll(this.eventLoops.Take(i).Select(loop => loop.ShutdownGracefullyAsync())).Wait(); } } this.eventLoops[i] = eventLoop; terminationTasks[i] = eventLoop.TerminationCompletion; } this.TerminationCompletion = Task.WhenAll(terminationTasks); }
public WorkerEventLoopGroup(DispatcherEventLoopGroup eventLoopGroup) : this(eventLoopGroup, DefaultEventLoopThreadCount) { }
public WorkerEventLoopGroup(DispatcherEventLoopGroup eventLoopGroup, int nThreads, IEventExecutorChooserFactory <WorkerEventLoop> chooserFactory) : this(eventLoopGroup, nThreads, chooserFactory, RejectedExecutionHandlers.Reject()) { }
public WorkerEventLoopGroup(DispatcherEventLoopGroup eventLoopGroup, int nThreads, IRejectedExecutionHandler rejectedHandler) : this(eventLoopGroup, nThreads, DefaultThreadFactory <WorkerEventLoopGroup> .Instance, rejectedHandler) { }
public WorkerEventLoopGroup(DispatcherEventLoopGroup eventLoopGroup, int nThreads, IThreadFactory threadFactory, IRejectedExecutionHandler rejectedHandler, TimeSpan breakoutInterval) : this(eventLoopGroup, nThreads, threadFactory, DefaultEventExecutorChooserFactory <WorkerEventLoop> .Instance, rejectedHandler, breakoutInterval) { }
public WorkerEventLoopGroup(DispatcherEventLoopGroup eventLoopGroup, int nThreads, IThreadFactory threadFactory, IRejectedExecutionHandler rejectedHandler) : this(eventLoopGroup, nThreads, threadFactory, rejectedHandler, LoopExecutor.DefaultBreakoutInterval) { }
public WorkerEventLoopGroup(DispatcherEventLoopGroup eventLoopGroup, int nThreads, IThreadFactory threadFactory) : this(eventLoopGroup, nThreads, threadFactory, RejectedExecutionHandlers.Reject()) { }
public WorkerEventLoopGroup(DispatcherEventLoopGroup eventLoopGroup, int nThreads) : this(eventLoopGroup, nThreads, DefaultThreadFactory <WorkerEventLoopGroup> .Instance) { }