private void OnListen() { ModuleProc PROC = new ModuleProc(this.DYN_MODULE_NAME, "OnListen"); try { while (!_executorService.WaitForShutdown(100)) { try { IAsyncResult acceptAsync = _socket.BeginAccept(null, null); int waitIndex = _executorService.WaitAny(acceptAsync.AsyncWaitHandle, -1); if (waitIndex == 0) { break; } Socket clientSocket = _socket.EndAccept(acceptAsync); INetSocketHandler client = new TcpSocketServerClient(clientSocket); int hashcode = client.GetHashCode(); if (_hasThreads) { if (_totalThreads != -1) { int threadIndex = (hashcode % _totalThreads); ClientsInfo ci = null; if (_clients.ContainsKey(threadIndex)) { ci = _clients[threadIndex]; } else { ci = new ClientsInfo(threadIndex); _clients.Add(threadIndex, ci); _pool.QueueWorkerItem(ci); } Log.InfoV(PROC, "Client [{0}] was connected at Thread {1:D}", client.ToString(), threadIndex); ci.AddClient(client); } else { } } this.OnClientConnected(client); } catch (Exception ex) { Log.Exception(PROC, ex); } } } catch (Exception ex) { Log.Exception(PROC, ex); } }
internal bool Execute(MonitorExecutionContext context) { using (ILogMethod method = Log.LogMethod("MonitorHandlerFactory", "Execute")) { bool result = default(bool); try { _MonitorHandlerFactory factory = GetFactory(context); if (factory.IsExecuting) { _executorDelayLoading.QueueWorkerItem(context); result = true; } else { result = factory.Execute(context, null); } } catch (Exception ex) { method.Exception(ex); } return(result); } }
public bool Execute(IFreeformEntity_Msg request) { using (ILogMethod method = Log.LogMethod(DYN_MODULE_NAME, "ProcessMessage")) { bool result = default(bool); try { if (request == null || request.IpAddress.IsEmpty()) { return(false); } string key = request.IpAddress; _ExecutionStepFactory factory = GetFactory(request); // new or existing transaction id if (!factory.PersistRequestResponseMapItem(request) && request.TransactionID <= 0) { request.TransactionID = NewTransactionId; } // immediate execution or delayed execution if (factory.IsExecuting) { _executorDelayLoading.QueueWorkerItem(request); result = true; } else { result = factory.Execute(request); } } 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); } }
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 Execute(IFreeformEntity_Msg request) { using (ILogMethod method = Log.LogMethod(DYN_MODULE_NAME, "ProcessMessage")) { bool result = default(bool); try { if (request == null || request.IpAddress.IsEmpty()) { return(false); } string key = request.IpAddress; _FFMsgHandlerFactory factory = GetFactory(request); // immediate execution or delayed execution if (factory.IsExecuting) { _executorDelayLoading.QueueWorkerItem(request); result = true; } else { result = factory.Execute(request); } } catch (Exception ex) { method.Exception(ex); } return(result); } }
public void QueueWorkerItem(T item) { _executor.QueueWorkerItem(item); }
private void ListenMonitorQueues() { ModuleProc PROC = new ModuleProc(DYN_MODULE_NAME, "ListenMonitorQueues"); bool canShutdown = true; // Start the queues try { foreach (WorkerInfo workerInfo in _workerInfos.Values) { workerInfo.Processor.ListenAsync(); this.ExecutorService.WaitForShutdown(); } } catch (Exception ex) { Log.Exception(PROC, ex); } // listen for queues try { int length = _queues.Count; // more queues found if (length > 1) { while (!this.ExecutorService.WaitForShutdown()) { for (int i = 0; i < length; i++) { IThreadSafeQueue <QueueMessageWrapper> queue = _queues[i]; bool hasDataInPriorityQueue = false; while (queue.QueueCount > 0) { for (int j = 0; j < i; j++) { // if any items available in the the previous queue if (_queues[j].QueueCount > 0) { hasDataInPriorityQueue = true; break; } if (this.ExecutorService.WaitForShutdown()) { break; } } if (hasDataInPriorityQueue || this.ExecutorService.IsShutdown) { break; } try { _poolExecutor.QueueWorkerItem(queue.Dequeue()); } catch (Exception ex) { Log.Exception(PROC, ex); } if (hasDataInPriorityQueue || this.ExecutorService.WaitForShutdown()) { break; } } if (hasDataInPriorityQueue || this.ExecutorService.WaitForShutdown()) { break; } } } } else // single queue is enough { if (!this.MQUseWorkerThread) { canShutdown = false; } else { IThreadSafeQueue <QueueMessageWrapper> queue = _queues[0]; while (!this.ExecutorService.WaitForShutdown()) { try { _poolExecutor.QueueWorkerItem(queue.Dequeue()); } catch (Exception ex) { Log.Exception(PROC, ex); } } } } } catch (Exception ex) { Log.Exception(PROC, ex); } finally { if (canShutdown) { this.Shutdown(); } } }