コード例 #1
0
        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);
        }
コード例 #2
0
 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;
 }
コード例 #3
0
 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;
 }
コード例 #4
0
        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;
        }
コード例 #5
0
        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();
                }
            }
        }
コード例 #6
0
        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;
        }