public LocalServerChannel() { _inboundBuffer = PlatformDependent.NewMpscQueue <object>(); _shutdownHook = () => Unsafe.Close(Unsafe.VoidPromise()); var config = new DefaultChannelConfiguration(this); config.Allocator = new PreferHeapByteBufAllocator(config.Allocator); Configuration = config; }
/// <summary> /// Creates a new <see cref="FixedChannelPool"/> instance. /// </summary> /// <param name="bootstrap">The <see cref="Bootstrap"/> that is used for connections.</param> /// <param name="handler"> /// The <see cref="IChannelPoolHandler"/> that will be notified for the different pool actions. /// </param> /// <param name="healthChecker"> /// The <see cref="IChannelHealthChecker"/> that will be used to check if a <see cref="IChannel"/> is still /// healthy when obtained from the <see cref="IChannelPool"/>. /// </param> /// <param name="action"> /// The <see cref="AcquireTimeoutAction"/> to use or <c>null</c> if none should be used. In this case, /// <paramref name="acquireTimeout"/> must also be <c>null</c>. /// </param> /// <param name="acquireTimeout"> /// A <see cref="TimeSpan"/> after which an pending acquire must complete, or the /// <see cref="AcquireTimeoutAction"/> takes place. /// </param> /// <param name="maxConnections"> /// The number of maximal active connections. Once this is reached, new attempts to acquire an /// <see cref="IChannel"/> will be delayed until a connection is returned to the pool again. /// </param> /// <param name="maxPendingAcquires"> /// The maximum number of pending acquires. Once this is exceeded, acquire attempts will be failed. /// </param> /// <param name="releaseHealthCheck">If <c>true</c>, will check channel health before offering it back.</param> /// <param name="lastRecentUsed"> /// If <c>true</c>, <see cref="IChannel"/> selection will be LIFO. If <c>false</c>, it will be FIFO. /// </param> public FixedChannelPool(Bootstrap bootstrap, IChannelPoolHandler handler, IChannelHealthChecker healthChecker, AcquireTimeoutAction action, TimeSpan acquireTimeout, int maxConnections, int maxPendingAcquires, bool releaseHealthCheck, bool lastRecentUsed) : base(bootstrap, handler, healthChecker, releaseHealthCheck, lastRecentUsed) { if ((uint)(maxConnections - 1) > SharedConstants.TooBigOrNegative) { ThrowHelper.ThrowArgumentException_MaxConnections(maxConnections); } if ((uint)(maxPendingAcquires - 1) > SharedConstants.TooBigOrNegative) { ThrowHelper.ThrowArgumentException_MaxPendingAcquires(maxPendingAcquires); } _acquireTimeout = acquireTimeout; if (action == AcquireTimeoutAction.None && acquireTimeout == Timeout.InfiniteTimeSpan) { _timeoutTask = null; } else if (action == AcquireTimeoutAction.None && acquireTimeout != Timeout.InfiniteTimeSpan) { ThrowHelper.ThrowArgumentException_Action(); } else if (action != AcquireTimeoutAction.None && acquireTimeout < TimeSpan.Zero) { ThrowHelper.ThrowArgumentException_AcquireTimeoutMillis(acquireTimeout); } else { switch (action) { case AcquireTimeoutAction.Fail: _timeoutTask = new TimeoutTask(this, OnTimeoutFail); break; case AcquireTimeoutAction.New: _timeoutTask = new TimeoutTask(this, OnTimeoutNew); break; default: ThrowHelper.ThrowArgumentException_Action(); break; } } _executor = bootstrap.Group().GetNext(); _maxConnections = maxConnections; _maxPendingAcquires = maxPendingAcquires; _pendingAcquireQueue = PlatformDependent.NewMpscQueue <AcquireTask>(); }
internal LocalChannel(LocalServerChannel parent, LocalChannel peer) : base(parent) { _inboundBuffer = PlatformDependent.NewMpscQueue <object>(); v_peer = peer; if (parent is object) { v_localAddress = parent.LocalAddress; } if (peer is object) { v_remoteAddress = peer.LocalAddress; } var config = new DefaultChannelConfiguration(this); config.Allocator = new PreferHeapByteBufAllocator(config.Allocator); Configuration = config; shutdownHook = () => Unsafe.Close(Unsafe.VoidPromise()); }
public LoopExecutor(IEventLoopGroup parent, string threadName, TimeSpan breakoutInterval) : base(parent) { this.preciseBreakoutInterval = (long)breakoutInterval.TotalMilliseconds; this.terminationCompletionSource = new TaskCompletionSource(); this.taskQueue = PlatformDependent.NewMpscQueue <IRunnable>(); this.scheduler = new ExecutorTaskScheduler(this); this.loop = new Loop(); this.asyncHandle = new Async(this.loop, OnCallback, this); this.timerHandle = new Timer(this.loop, OnCallback, this); string name = $"{this.GetType().Name}:{this.loop.Handle}"; if (!string.IsNullOrEmpty(threadName)) { name = $"{name}({threadName})"; } this.thread = new XThread(Run) { Name = name }; this.loopRunStart = new ManualResetEventSlim(false, 1); }
public LoopExecutor(IEventLoopGroup parent, string threadName, TimeSpan breakoutInterval) : base(parent) { this.preciseBreakoutInterval = PreciseTimeSpan.FromTimeSpan(breakoutInterval); this.preciseTimerInterval = PreciseTimeSpan.FromTimeSpan(TimeSpan.FromTicks(breakoutInterval.Ticks * 2)); this.terminationCompletionSource = new TaskCompletionSource(); this.taskQueue = PlatformDependent.NewMpscQueue <IRunnable>(); this.scheduler = new ExecutorTaskScheduler(this); this.loop = new Loop(); this.asyncHandle = new Async(this.loop, RunAllTasksCallback, this); this.timerHandle = new Timer(this.loop, RunAllTasksCallback, this); string name = string.Format(DefaultWorkerThreadName, this.loop.Handle); if (!string.IsNullOrEmpty(threadName)) { name = $"{name} ({threadName})"; } this.thread = new XThread(RunLoop) { Name = name }; }