protected override bool BindInternal() { if (_handler == null) { _executorService = ExecutorServiceFactory.CreateExecutorService(); if (_hasThreads) { _pool = ThreadPoolExecutorFactory.CreateThreadPool <ClientsInfo>( new ThreadPoolExecutorArg() { ExecutorService = _executorService, PoolType = (_totalThreads == -1 ? ThreadPoolType.NonBlockDynamic : ThreadPoolType.AsyncTaskQueue), ThreadCount = _totalThreads, }); _pool.ProcessItem += new ExecutorProcessItemHandler <ClientsInfo>(OnPool_ProcessItem); } _handler = new TcpListener(_localEndPoint as IPEndPoint); _socket = _handler.Server; _handler.Start(); if (Extensions.UseTaskInsteadOfThread) { Extensions.CreateLongRunningTask(this.OnListen); } else { Extensions.CreateThreadAndStart(new System.Threading.ThreadStart(this.OnListen)); } } return(_handler != null); }
public ExecutorThreadPoolManager(IExecutorService executorService, ThreadPoolType poolType, int threads, int capacity, ExecutorProcessItemHandler <T> handler) : base(executorService) { _handler = handler; _executor = ThreadPoolExecutorFactory.CreateThreadPool <T>(executorService, poolType, threads, -1); _executor.ProcessItem += OnExecutor_ProcessItem; }
protected override bool StopInternal() { if (_executorService != null) { _executorService.AwaitTermination(new TimeSpan(0, 5, 0)); _executorService = null; if (_hasThreads) { _pool.Dispose(); _pool = null; } } return(true); }
internal ExecutionStepFactory(IExecutorService executorService) : base(executorService) { _executorDelayLoading = ThreadPoolExecutorFactory.CreateThreadPool <IFreeformEntity_Msg>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 5, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _executorDelayLoading.ProcessItem += OnExecutorDelayLoading_ProcessItem; }
internal FFMsgHandlerFactory(IExecutorService executorService, Func <IFFMsgTransmitter> createMessageHandler) : base(executorService) { _createMessageHandler = createMessageHandler; _executorDelayLoading = ThreadPoolExecutorFactory.CreateThreadPool <IFreeformEntity_Msg>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 5, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _executorDelayLoading.ProcessItem += OnExecutorDelayLoading_ProcessItem; }
/// <summary> /// /// </summary> /// <param name="pool"></param> /// <param name="threadName"></param> /// <param name="breakoutInterval"></param> /// <param name="taskQueue"></param> protected SingleThreadEventExecutor(IThreadPoolExecutor pool, string threadName, TimeSpan breakoutInterval, IQueue <IRunnable> taskQueue) : base(pool) { 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(); }
public virtual bool ProcessMessage(FFMsg_G2H request) { using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "ProcessG2HMessage")) { bool result = false; try { // find the queue executor by session id IThreadPoolExecutor <FFMsg_G2H> executor = this.GetExecutorG2H(request); executor.QueueWorkerItem(request); result = true; } catch (Exception ex) { method.Exception(ex); } return(result); } }
public bool ProcessH2GMessage(MonMsg_H2G request) { using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "ProcessH2GMessage")) { bool result = false; try { // find the queue executor by fault source and type IThreadPoolExecutor <MonMsg_H2G> executor = this.GetExecutorH2G(request); executor.QueueWorkerItem(request); result = true; } catch (Exception ex) { method.Exception(ex); } return(result); } }
internal FFMsgHandlerFactory(IExecutorService executorService, Func<IFFMsgTransmitter> createMessageHandler) : base(executorService) { _createMessageHandler = createMessageHandler; _executorDelayLoading = ThreadPoolExecutorFactory.CreateThreadPool<IFreeformEntity_Msg>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 5, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _executorDelayLoading.ProcessItem += OnExecutorDelayLoading_ProcessItem; }
/// <summary>Creates an instance of <see cref="AbstractEventExecutor"/>.</summary> protected AbstractEventExecutor(IThreadPoolExecutor pool) { this.Pool = pool; }
/// <summary>Creates a new instance of <see cref="SingleThreadEventLoop"/>.</summary> public SingleThreadEventExecutor(IThreadPoolExecutor pool, string threadName) : this(pool, threadName, DefaultBreakoutInterval) { }
internal FFExecutorBase(IExecutorService executorService) : base(executorService) { // GIM (G2H) _g2hExecutor_GIM = ThreadPoolExecutorFactory.CreateThreadPool<FFMsg_G2H>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 1, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _g2hExecutor_GIM.ProcessItem += OnProcessG2HMessageFromWorker; // GIM (H2G) _h2gExecutor_GIM = ThreadPoolExecutorFactory.CreateThreadPool<FFMsg_H2G>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 1, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _h2gExecutor_GIM.ProcessItem += OnProcessH2GMessageFromWorker; // Non Priority (G2H) _g2hExecutor_NonPrio = ThreadPoolExecutorFactory.CreateThreadPool<FFMsg_G2H>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 20, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _g2hExecutor_NonPrio.ProcessItem += OnProcessG2HMessageFromWorker; // Non Priority (H2G) _h2gExecutor_NonPrio = ThreadPoolExecutorFactory.CreateThreadPool<FFMsg_H2G>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 5, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _h2gExecutor_NonPrio.ProcessItem += OnProcessH2GMessageFromWorker; // Priority (G2H) _g2hExecutor_Prio = ThreadPoolExecutorFactory.CreateThreadPool<FFMsg_G2H>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 20, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _g2hExecutor_Prio.ProcessItem += OnProcessG2HMessageFromWorker; // Priority (H2G) _h2gExecutor_Prio = ThreadPoolExecutorFactory.CreateThreadPool<FFMsg_H2G>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 5, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _h2gExecutor_Prio.ProcessItem += OnProcessH2GMessageFromWorker; }
/// <summary>Creates a new instance of <see cref="SingleThreadEventExecutor"/>.</summary> public SingleThreadEventExecutor(IThreadPoolExecutor pool, string threadName, TimeSpan breakoutInterval) : this(pool, threadName, breakoutInterval, new CompatibleConcurrentQueue <IRunnable>()) { }
protected AbstractScheduledEventExecutor(IThreadPoolExecutor pool) : base(pool) { }
/// <summary>Creates a new instance of <see cref="SingleThreadEventLoop"/>.</summary> public SingleThreadEventExecutor(IThreadPoolExecutor pool) : this(pool, null, DefaultBreakoutInterval) { }
protected override bool BindInternal() { if (_handler == null) { _executorService = ExecutorServiceFactory.CreateExecutorService(); if (_hasThreads) { _pool = ThreadPoolExecutorFactory.CreateThreadPool<ClientsInfo>( new ThreadPoolExecutorArg() { ExecutorService = _executorService, PoolType = (_totalThreads == -1 ? ThreadPoolType.NonBlockDynamic : ThreadPoolType.AsyncTaskQueue), ThreadCount = _totalThreads, }); _pool.ProcessItem += new ExecutorProcessItemHandler<ClientsInfo>(OnPool_ProcessItem); } _handler = new TcpListener(_localEndPoint as IPEndPoint); _socket = _handler.Server; _handler.Start(); if (Extensions.UseTaskInsteadOfThread) Extensions.CreateLongRunningTask(this.OnListen); else Extensions.CreateThreadAndStart(new System.Threading.ThreadStart(this.OnListen)); } return (_handler != null); }
internal ExMonitorTransceiverBase(IExecutorService executorService, ExMonitorServerImpl monitorServer) : base(executorService) { _monitorServer = monitorServer; _isMonProcessorStandalone = _monitorServer._isMonProcessorStandalone; // GIM (G2H) _g2hExecutor_GIM = ThreadPoolExecutorFactory.CreateThreadPool <MonMsg_G2H>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 1, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _g2hExecutor_GIM.ProcessItem += OnProcessG2HMessageFromWorker; // GIM (H2G) _h2gExecutor_GIM = ThreadPoolExecutorFactory.CreateThreadPool <MonMsg_H2G>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 1, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _h2gExecutor_GIM.ProcessItem += OnProcessH2GMessageFromWorker; // Non Priority (G2H) _g2hExecutor_NonPrio = ThreadPoolExecutorFactory.CreateThreadPool <MonMsg_G2H>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 20, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _g2hExecutor_NonPrio.ProcessItem += OnProcessG2HMessageFromWorker; // Non Priority (H2G) _h2gExecutor_NonPrio = ThreadPoolExecutorFactory.CreateThreadPool <MonMsg_H2G>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 5, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _h2gExecutor_NonPrio.ProcessItem += OnProcessH2GMessageFromWorker; // Priority (G2H) _g2hExecutor_Prio = ThreadPoolExecutorFactory.CreateThreadPool <MonMsg_G2H>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 20, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _g2hExecutor_Prio.ProcessItem += OnProcessG2HMessageFromWorker; // Priority (H2G) _h2gExecutor_Prio = ThreadPoolExecutorFactory.CreateThreadPool <MonMsg_H2G>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 5, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _h2gExecutor_Prio.ProcessItem += OnProcessH2GMessageFromWorker; }
internal FFExecutorBase(IExecutorService executorService) : base(executorService) { // GIM (G2H) _g2hExecutor_GIM = ThreadPoolExecutorFactory.CreateThreadPool <FFMsg_G2H>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 1, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _g2hExecutor_GIM.ProcessItem += OnProcessG2HMessageFromWorker; // GIM (H2G) _h2gExecutor_GIM = ThreadPoolExecutorFactory.CreateThreadPool <FFMsg_H2G>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 1, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _h2gExecutor_GIM.ProcessItem += OnProcessH2GMessageFromWorker; // Non Priority (G2H) _g2hExecutor_NonPrio = ThreadPoolExecutorFactory.CreateThreadPool <FFMsg_G2H>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 20, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _g2hExecutor_NonPrio.ProcessItem += OnProcessG2HMessageFromWorker; // Non Priority (H2G) _h2gExecutor_NonPrio = ThreadPoolExecutorFactory.CreateThreadPool <FFMsg_H2G>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 5, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _h2gExecutor_NonPrio.ProcessItem += OnProcessH2GMessageFromWorker; // Priority (G2H) _g2hExecutor_Prio = ThreadPoolExecutorFactory.CreateThreadPool <FFMsg_G2H>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 20, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _g2hExecutor_Prio.ProcessItem += OnProcessG2HMessageFromWorker; // Priority (H2G) _h2gExecutor_Prio = ThreadPoolExecutorFactory.CreateThreadPool <FFMsg_H2G>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 5, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _h2gExecutor_Prio.ProcessItem += OnProcessH2GMessageFromWorker; }
protected override bool StopInternal() { if (_executorService != null) { _executorService.AwaitTermination(new TimeSpan(0, 5, 0)); _executorService = null; if (_hasThreads) { _pool.Dispose(); _pool = null; } } return true; }
private void Initialize(MessageQueueWorkerInfo workerInfo, KeyValuePair <string, CreateQueueMessageWrapperHandler>[] createMessageWrappers) { ModuleProc PROC = new ModuleProc(DYN_MODULE_NAME, "Initialize"); try { _uniqueKey = KEY_PREFIX + Guid.NewGuid().ToString(); this.ExecutorService.AddExecutor(this); _workerInfos = new SortedDictionary <string, WorkerInfo>(StringComparer.InvariantCultureIgnoreCase); _createMessageWrappers = new SortedDictionary <string, CreateQueueMessageWrapperHandler>(StringComparer.InvariantCultureIgnoreCase); _queues = new List <IThreadSafeQueue <QueueMessageWrapper> >(); if (createMessageWrappers != null) { foreach (KeyValuePair <string, CreateQueueMessageWrapperHandler> createWrapper in createMessageWrappers) { if (!_createMessageWrappers.ContainsKey(createWrapper.Key)) { _createMessageWrappers.Add(createWrapper); Log.InfoV(PROC, "Message Wrapper Handler for : {0}", createWrapper.Key); } } } if (workerInfo.QueueInfos != null) { foreach (MessageQueueInfo queueInfo in workerInfo.QueueInfos) { if (!_workerInfos.ContainsKey(queueInfo.ServicePath)) { WorkerInfo wi = new WorkerInfo() { QueueInfo = queueInfo, Queue = new BlockingBoundQueueUser <QueueMessageWrapper>(this.ExecutorService, 1) }; try { MessageQueueProcessorInternal processor = new MessageQueueProcessorInternal(this.ExecutorService, queueInfo.ServicePath, queueInfo.IsTransactional, queueInfo.Formatter, queueInfo.QueueTimeout, queueInfo.MessageFormatters); processor.ProcessMessageInternal += new ProcessMessageInternalHandler(OnMessageProcessor_ProcessMessage); wi.Processor = processor; _defaultQueueProcessor = processor; } catch (Exception ex) { Log.Exception(PROC, ex); } _workerInfos.Add(queueInfo.ServicePath, wi); _queues.Add(wi.Queue); } } } // executors _sharedQueues = (_queues.Count > 1); this.MQUseExecutor = (_sharedQueues || (this.MessageThreshold > 1)); if (this.MQUseExecutor) { _poolExecutor = ThreadPoolExecutorFactory.CreateThreadPool <QueueMessageWrapper>(this.ExecutorService, _poolType, this.MessageThreshold, this.QueueThreshold, false, workerInfo.FlushItemsBeforeClose); _poolExecutor.TrackItems = workerInfo.TrackItems; _poolExecutor.ProcessItem += new ExecutorProcessItemHandler <QueueMessageWrapper>(OnThreadPoolExecutor_ProcessItem); } workerInfo.WorkerKey = _uniqueKey; } catch (Exception ex) { Log.Exception(PROC, ex); } finally { if (!this.MQUseWorkerThread) { this.RegisterForShutdown(); } } }
internal ExecutionStepFactory(IExecutorService executorService) : base(executorService) { _executorDelayLoading = ThreadPoolExecutorFactory.CreateThreadPool<IFreeformEntity_Msg>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 5, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _executorDelayLoading.ProcessItem += OnExecutorDelayLoading_ProcessItem; }
internal ExMonitorTransceiverBase(IExecutorService executorService, ExMonitorServerImpl monitorServer) : base(executorService) { _monitorServer = monitorServer; _isMonProcessorStandalone = _monitorServer._isMonProcessorStandalone; // GIM (G2H) _g2hExecutor_GIM = ThreadPoolExecutorFactory.CreateThreadPool<MonMsg_G2H>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 1, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _g2hExecutor_GIM.ProcessItem += OnProcessG2HMessageFromWorker; // GIM (H2G) _h2gExecutor_GIM = ThreadPoolExecutorFactory.CreateThreadPool<MonMsg_H2G>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 1, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _h2gExecutor_GIM.ProcessItem += OnProcessH2GMessageFromWorker; // Non Priority (G2H) _g2hExecutor_NonPrio = ThreadPoolExecutorFactory.CreateThreadPool<MonMsg_G2H>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 20, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _g2hExecutor_NonPrio.ProcessItem += OnProcessG2HMessageFromWorker; // Non Priority (H2G) _h2gExecutor_NonPrio = ThreadPoolExecutorFactory.CreateThreadPool<MonMsg_H2G>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 5, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _h2gExecutor_NonPrio.ProcessItem += OnProcessH2GMessageFromWorker; // Priority (G2H) _g2hExecutor_Prio = ThreadPoolExecutorFactory.CreateThreadPool<MonMsg_G2H>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 20, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _g2hExecutor_Prio.ProcessItem += OnProcessG2HMessageFromWorker; // Priority (H2G) _h2gExecutor_Prio = ThreadPoolExecutorFactory.CreateThreadPool<MonMsg_H2G>( new ThreadPoolExecutorArg() { ExecutorService = executorService, KernelModeQueue = false, PoolType = ThreadPoolType.AsyncTaskQueue, ThreadCount = 5, // Configurable FlushItemsBeforeClose = true, ThreadQueueCount = -1, }); _h2gExecutor_Prio.ProcessItem += OnProcessH2GMessageFromWorker; }