protected SingleThreadEventExecutorOld(IEventExecutorGroup parent, string threadName, TimeSpan breakoutInterval, IQueue <IRunnable> taskQueue) : base(parent) { _firstTask = true; _emptyEvent = new ManualResetEventSlim(false, 1); _shutdownHooks = new HashSet <Action>(); _loopAction = Loop; _loopCoreAciton = LoopCore; _terminationCompletionSource = NewPromise(); _taskQueue = taskQueue; _preciseBreakoutInterval = PreciseTimeSpan.FromTimeSpan(breakoutInterval); _scheduler = new ExecutorTaskScheduler(this); _thread = new Thread(_loopAction); if (string.IsNullOrEmpty(threadName)) { _thread.Name = DefaultWorkerThreadName; } else { _thread.Name = threadName; } _thread.Start(); }
public IChannelPipeline AddAfter(IEventExecutorGroup group, string baseName, string name, IChannelHandler handler) { Contract.Requires(handler != null); AbstractChannelHandlerContext newCtx; lock (this) { CheckMultiplicity(handler); AbstractChannelHandlerContext ctx = this.GetContextOrThrow(baseName); newCtx = this.NewContext(group, this.FilterName(name, handler), handler); IEventExecutor executor = this.ExecutorSafe(newCtx.executor); AddAfter0(ctx, newCtx); // If the executor is null it means that the channel was not registered on an eventloop yet. // In this case we remove the context from the pipeline and add a task that will call // ChannelHandler.handlerRemoved(...) once the channel is registered. if (executor == null) { this.CallHandlerCallbackLater(newCtx, true); return(this); } if (!executor.InEventLoop) { executor.Execute(CallHandlerAddedAction, this, newCtx); return(this); } } this.CallHandlerAdded0(newCtx); return(this); }
public RlpxPeer(IMessageSerializationService serializationService, PublicKey localNodeId, int localPort, IHandshakeService handshakeService, ISessionMonitor sessionMonitor, IDisconnectsAnalyzer disconnectsAnalyzer, ILogManager logManager) { // .NET Core definitely got the easy logging setup right :D // ResourceLeakDetector.Level = ResourceLeakDetector.DetectionLevel.Paranoid; // ConfigureNamedOptions<ConsoleLoggerOptions> configureNamedOptions = new("", null); // OptionsFactory<ConsoleLoggerOptions> optionsFactory = new( // new []{ configureNamedOptions }, // Enumerable.Empty<IPostConfigureOptions<ConsoleLoggerOptions>>()); // OptionsMonitor<ConsoleLoggerOptions> optionsMonitor = new( // optionsFactory, // Enumerable.Empty<IOptionsChangeTokenSource<ConsoleLoggerOptions>>(), // new OptionsCache<ConsoleLoggerOptions>()); // LoggerFactory loggerFactory = new( // new[] { new ConsoleLoggerProvider(optionsMonitor) }, // new LoggerFilterOptions { MinLevel = Microsoft.Extensions.Logging.LogLevel.Warning }); // InternalLoggerFactory.DefaultFactory = loggerFactory; _group = new SingleThreadEventLoop(); _serializationService = serializationService ?? throw new ArgumentNullException(nameof(serializationService)); _logManager = logManager ?? throw new ArgumentNullException(nameof(logManager)); _logger = logManager.GetClassLogger(); _sessionMonitor = sessionMonitor ?? throw new ArgumentNullException(nameof(sessionMonitor)); _disconnectsAnalyzer = disconnectsAnalyzer ?? throw new ArgumentNullException(nameof(disconnectsAnalyzer)); _handshakeService = handshakeService ?? throw new ArgumentNullException(nameof(handshakeService)); LocalNodeId = localNodeId ?? throw new ArgumentNullException(nameof(localNodeId)); LocalPort = localPort; }
public static Task ShutdownChannelAsync( IEventExecutorGroup bossExecutor, IEventExecutorGroup workerExecutor, IChannelGroup allChannels, TimeSpan timeSpan) { timeSpan = timeSpan.TotalSeconds <= 2 ? TimeSpan.FromSeconds(3) : timeSpan; List <Task> tasks = new List <Task>(); // Close all channels if (allChannels != null) { tasks.Add(allChannels.CloseAsync()); } // Stop boss threads if (bossExecutor != null) { tasks.Add(bossExecutor.ShutdownGracefullyAsync(TimeSpan.FromSeconds(2), timeSpan)); } // Finally stop I/O workers if (workerExecutor != null) { tasks.Add(workerExecutor.ShutdownGracefullyAsync(TimeSpan.FromSeconds(2), timeSpan)); } return(Task.WhenAll(tasks.ToArray())); }
public IChannelPipeline AddLast(IEventExecutorGroup group, params IChannelHandler[] handlers) { foreach (IChannelHandler h in handlers) { this.AddLast(group, (string)null, h); } return(this); }
public IChannelPipeline AddFirst(IEventExecutorGroup group, params IChannelHandler[] handlers) { Contract.Requires(handlers != null); for (int i = handlers.Length - 1; i >= 0; i--) { IChannelHandler h = handlers[i]; this.AddFirst(group, (string)null, h); } return(this); }
public Bootstrap Group(IEventExecutorGroup group) { if (group == null) { throw new ArgumentNullException("group can not be null."); } if (this.group != null) { throw new InvalidOperationException("group has already been set."); } this.group = group; return(this); }
/// <summary>Creates a new instance of <see cref="SingleThreadEventExecutor"/>.</summary> /// <param name="parent">the <see cref="IEventExecutorGroup"/> which is the parent of this instance and belongs to it.</param> /// <param name="threadFactory">the <see cref="IThreadFactory"/> which will be used for the used <see cref="Thread"/>.</param> /// <param name="addTaskWakesUp"><c>true</c> if and only if invocation of <see cref="AddTask(IRunnable)"/> will wake up the executor thread.</param> /// <param name="maxPendingTasks">the maximum number of pending tasks before new tasks will be rejected.</param> /// <param name="rejectedHandler">the <see cref="IRejectedExecutionHandler"/> to use.</param> protected SingleThreadEventExecutor(IEventExecutorGroup parent, IThreadFactory threadFactory, bool addTaskWakesUp, int maxPendingTasks, IRejectedExecutionHandler rejectedHandler) : this(parent, addTaskWakesUp, rejectedHandler) { if (threadFactory is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.threadFactory); } _maxPendingTasks = Math.Max(16, maxPendingTasks); _taskQueue = NewTaskQueue(_maxPendingTasks); _blockingTaskQueue = _taskQueue as IBlockingQueue <IRunnable>; _thread = NewThread(threadFactory); }
public NettyHandshakeHandler( IEncryptionHandshakeService service, ISession session, HandshakeRole role, ILogManager logManager, IEventExecutorGroup group) { _role = role; _logManager = logManager ?? throw new ArgumentNullException(nameof(NettyHandshakeHandler)); _group = @group; _logger = logManager.GetClassLogger <NettyHandshakeHandler>(); _service = service; _session = session; _initCompletionSource = new TaskCompletionSource <object>(); }
public RlpxPeer( PublicKey localNodeId, int localPort, IEncryptionHandshakeService encryptionHandshakeService, ILogManager logManager, ISessionMonitor sessionMonitor) { _group = new SingleThreadEventLoop(); _logManager = logManager ?? throw new ArgumentNullException(nameof(logManager)); _logger = logManager.GetClassLogger(); _sessionMonitor = sessionMonitor ?? throw new ArgumentNullException(nameof(sessionMonitor)); _encryptionHandshakeService = encryptionHandshakeService ?? throw new ArgumentNullException(nameof(encryptionHandshakeService)); LocalNodeId = localNodeId ?? throw new ArgumentNullException(nameof(localNodeId)); LocalPort = localPort; }
public NettyHandshakeHandler( IMessageSerializationService serializationService, IHandshakeService handshakeService, ISession session, HandshakeRole role, ILogManager logManager, IEventExecutorGroup group) { _serializationService = serializationService ?? throw new ArgumentNullException(nameof(serializationService)); _logManager = logManager ?? throw new ArgumentNullException(nameof(logManager)); _logger = logManager.GetClassLogger <NettyHandshakeHandler>(); _role = role; _group = group; _service = handshakeService ?? throw new ArgumentNullException(nameof(handshakeService)); _session = session ?? throw new ArgumentNullException(nameof(session)); _initCompletionSource = new TaskCompletionSource <object>(); }
protected SingleThreadEventExecutor(IEventExecutorGroup parent, string threadName, TimeSpan breakoutInterval, IQueue <IRunnable> taskQueue) : base(parent) { this.terminationCompletionSource = new TaskCompletionSource(); this.taskQueue = taskQueue; this.preciseBreakoutInterval = PreciseTimeSpan.FromTimeSpan(breakoutInterval); this.scheduler = new ExecutorTaskScheduler(this); this.thread = new Thread(this.Loop); if (string.IsNullOrEmpty(threadName)) { this.thread.Name = DefaultWorkerThreadName; } else { this.thread.Name = threadName; } this.thread.Start(); }
IEventExecutor GetChildExecutor(IEventExecutorGroup group) { if (group == null) { return(null); } // Use size of 4 as most people only use one extra EventExecutor. Dictionary <IEventExecutorGroup, IEventExecutor> executorMap = this.childExecutors ?? (this.childExecutors = new Dictionary <IEventExecutorGroup, IEventExecutor>(4, ReferenceEqualityComparer.Default)); // Pin one of the child executors once and remember it so that the same child executor // is used to fire events for the same channel. if (!executorMap.TryGetValue(group, out IEventExecutor childExecutor)) { childExecutor = group.GetNext(); executorMap[group] = childExecutor; } return(childExecutor); }
public RlpxPeer( IMessageSerializationService serializationService, PublicKey localNodeId, int localPort, IHandshakeService handshakeService, ILogManager logManager, ISessionMonitor sessionMonitor) { // InternalLoggerFactory.DefaultFactory.AddProvider(new ConsoleLoggerProvider((s, level) => level > LogLevel.Warning, false)); // ResourceLeakDetector.Level = ResourceLeakDetector.DetectionLevel.Paranoid; _group = new SingleThreadEventLoop(); _serializationService = serializationService ?? throw new ArgumentNullException(nameof(serializationService)); _logManager = logManager ?? throw new ArgumentNullException(nameof(logManager)); _logger = logManager.GetClassLogger(); _sessionMonitor = sessionMonitor ?? throw new ArgumentNullException(nameof(sessionMonitor)); _handshakeService = handshakeService ?? throw new ArgumentNullException(nameof(handshakeService)); LocalNodeId = localNodeId ?? throw new ArgumentNullException(nameof(localNodeId)); LocalPort = localPort; }
/// <summary>Creates a new instance of <see cref="SingleThreadEventExecutor"/>.</summary> /// <param name="parent">the <see cref="IEventExecutorGroup"/> which is the parent of this instance and belongs to it.</param> /// <param name="threadFactory">the <see cref="IThreadFactory"/> which will be used for the used <see cref="Thread"/>.</param> /// <param name="addTaskWakesUp"><c>true</c> if and only if invocation of <see cref="AddTask(IRunnable)"/> will wake up the executor thread.</param> /// <param name="taskQueue">The pending task queue.</param> /// <param name="rejectedHandler">the <see cref="IRejectedExecutionHandler"/> to use.</param> protected SingleThreadEventExecutor(IEventExecutorGroup parent, IThreadFactory threadFactory, bool addTaskWakesUp, IQueue <IRunnable> taskQueue, IRejectedExecutionHandler rejectedHandler) : this(parent, addTaskWakesUp, rejectedHandler) { if (threadFactory is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.threadFactory); } if (taskQueue is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.taskQueue); } _maxPendingTasks = DefaultMaxPendingExecutorTasks; _taskQueue = taskQueue; _blockingTaskQueue = taskQueue as IBlockingQueue <IRunnable>; _thread = NewThread(threadFactory); }
protected SingleThreadEventExecutor(IEventExecutorGroup parent, string threadName, TimeSpan breakoutInterval, IQueue <IRunnable> taskQueue) : base(parent) { _loopAction = Loop; _loopCoreAciton = LoopCore; _terminationCompletionSource = NewPromise(); _taskQueue = taskQueue; _preciseBreakoutInterval = PreciseTimeSpan.FromTimeSpan(breakoutInterval); _scheduler = new ExecutorTaskScheduler(this); _thread = new Thread(_loopAction); if (string.IsNullOrEmpty(threadName)) { _thread.Name = DefaultWorkerThreadName; } else { _thread.Name = threadName; } _thread.Start(); }
public CmppClient( CmppClientConfig config, BaseCmppSmsHandler smsHandler, ClientLoggerFactory loggerFactory) { this.loggerFactory = loggerFactory; this.logger = loggerFactory.CreateLogger <CmppClient>(); config.ClientStatus = ClientStatus.WAITING_CONNECT; config.Version = CmppVersion.CMPP20; Config = config; smsHandler.client = this; this.smsHandler = smsHandler; matchQueue = new SubmitSmsMatchPool <MsgEx>(32, 60 * 1000); if (smsHandler != null) { matchQueue.timeOutHandle = smsHandler.SubmitTimeOutHandle; } eventExecutorGroup = new MultithreadEventLoopGroup(); group = new MultithreadEventLoopGroup(); dbContext = new SqliteContext(Config.ClientId); InitClient(); }
private SingleThreadEventExecutor(IEventExecutorGroup parent, bool addTaskWakesUp, IRejectedExecutionHandler rejectedHandler) : base(parent) { if (rejectedHandler is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.rejectedHandler); } _firstTask = true; _loopAction = Loop; _loopCoreAciton = LoopCore; _addTaskWakesUp = addTaskWakesUp; _rejectedExecutionHandler = rejectedHandler; _shutdownHooks = new HashSet <Action>(); _terminationCompletionSource = NewPromise(); _threadLock = new CountdownEvent(1); _taskScheduler = new ExecutorTaskScheduler(this); }
/// <summary>Creates a new instance of <see cref="SingleThreadEventExecutor"/>.</summary> public SingleThreadEventExecutor(IEventExecutorGroup parent, string threadName, TimeSpan breakoutInterval) : this(parent, threadName, breakoutInterval, new CompatibleConcurrentQueue <IRunnable>()) { }
/// <summary>Creates an instance of <see cref="AbstractEventExecutor"/>.</summary> protected AbstractEventExecutor(IEventExecutorGroup parent) { Parent = parent; }
AbstractChannelHandlerContext NewContext(IEventExecutorGroup group, string name, IChannelHandler handler) => new DefaultChannelHandlerContext(this, this.GetChildExecutor(group), name, handler);
public DefaultEventExecutor(IEventExecutorGroup parent, int maxPendingTasks) : this(parent, RejectedExecutionHandlers.Reject(), maxPendingTasks) { }
protected AbstractScheduledEventExecutor(IEventExecutorGroup parent) : base(parent) { ScheduledTaskQueue = new DefaultPriorityQueue <IScheduledRunnable>(); }
public DefaultEventExecutor(IEventExecutorGroup parent) : this(parent, DefaultMaxPendingExecutorTasks) { }
protected AbstractScheduledEventExecutor(IEventExecutorGroup parent) : base(parent) { }
public DefaultEventExecutor(IEventExecutorGroup parent) : base(parent) { }
public DefaultEventExecutor(IEventExecutorGroup parent, IRejectedExecutionHandler rejectedHandler, IEventExecutorTaskQueueFactory queueFactory) : this(parent, DefaultThreadFactory <DefaultEventExecutor> .Instance, rejectedHandler, queueFactory) { }
public DefaultEventExecutor(IEventExecutorGroup parent, IThreadFactory threadFactory, IEventExecutorTaskQueueFactory queueFactory) : this(parent, threadFactory, RejectedExecutionHandlers.Reject(), queueFactory) { }
public SingleThreadEventExecutor(IEventExecutorGroup parent) : base(parent) { taskQueue = new SynchronizedQueue <IRunnable>(); thread = new Thread(Loop); thread.Start(); }
public DefaultEventExecutor(IEventExecutorGroup parent, IThreadFactory threadFactory, IRejectedExecutionHandler rejectedHandler, IEventExecutorTaskQueueFactory queueFactory) : base(parent, threadFactory, true, NewBlockingTaskQueue(queueFactory), rejectedHandler) { Start(); }