Beispiel #1
0
 internal MessageQueueWorker(MessageQueueManager parent, IExecutorService executorService,
                             ThreadPoolType poolType, MessageQueueWorkerInfo workerInfo,
                             KeyValuePair <string, CreateQueueMessageWrapperHandler>[] createMessageWrappers)
     : base(executorService)
 {
     Debug.Assert(workerInfo.QueueInfos.Count != 0);
     _parent                   = parent;
     _poolType                 = poolType;
     this.MessageThreshold     = workerInfo.MessageThreshold;
     this.QueueThreshold       = workerInfo.QueueThreshold;
     this.MQUseWorkerThread    = workerInfo.MQUseWorkerThread;
     this.MQCheckMessageResult = workerInfo.MQCheckMessageResult;
     this.Initialize(workerInfo, createMessageWrappers);
 }
        private void Initialize(MessageQueueWorkerInfo[] workerInfos,
            KeyValuePair<string, CreateQueueMessageWrapperHandler>[] createMessageWrappers)
        {
            ModuleProc PROC = new ModuleProc(DYN_MODULE_NAME, "Initialize");

            try
            {
                _uniqueKey = KEY_PREFIX + Guid.NewGuid().ToString();
                this.ExecutorService.AddExecutor(this);
                this.RegisterForShutdown();

                _queueWorkers = new SortedDictionary<string, MessageQueueWorker>(StringComparer.InvariantCultureIgnoreCase);
                foreach (MessageQueueWorkerInfo workerInfo in workerInfos)
                {
                    MessageQueueWorker worker = new MessageQueueWorker(this, this.ExecutorService, _poolType, workerInfo, createMessageWrappers);
                    string key = worker.UniqueKey;
                    _queueWorkers.Add(key, worker);

                    if (workerInfo.DependencyWorker != null)
                    {
                        string workerKey = workerInfo.DependencyWorker.WorkerKey;
                        if (_queueWorkers.ContainsKey(workerKey))
                        {
                            worker.DependencyWorker = _queueWorkers[workerKey];
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }
        }
 public MessageQueueManager(IExecutorService executorService, ThreadPoolType poolType,
     MessageQueueWorkerInfo[] workerInfos,
     KeyValuePair<string, CreateQueueMessageWrapperHandler>[] createMessageWrappers)
     : base(executorService)
 {
     Debug.Assert(workerInfos != null);
     _poolType = poolType;
     this.Initialize(workerInfos, createMessageWrappers);
 }
Beispiel #4
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();
                }
            }
        }