/// <summary> /// Initializes main SP components. /// </summary> public AltiGenSPCore() { // Creating Status object; this.spStatus = SPStatus.DISCONNECTED; // Creating new TCPClient to communicate using AltiLink Plus. this.tcpc = new TcpClient(); // Creating 3 queues for commands, events & responses. this.commandsQueue = new WaitingQueue <Diacom.Cmd.CmdBase>(); this.commandsALPQueue = new WaitingQueue <AltiLinkPlus.ALPCommand>(); this.eventsQueue = new WaitingQueue <Diacom.Ev.EvBase>(); this.waitingCommands = new Hashtable(); // Thread to get messages from SP. this.inThreadHandle = new Thread(new ThreadStart(inThread)); this.inThreadHandle.IsBackground = inThreadLivingStatus = true; this.inThreadHandle.Name = "AltiGenSP: IN"; // Thread to send messages to SP. this.outThreadHandle = new Thread(new ThreadStart(outThread)); this.outThreadHandle.IsBackground = outThreadLivingStatus = true; this.outThreadHandle.Name = "AltiGenSP: OUT"; // Thread to send ALP messages. this.outALPThreadHandle = new Thread(new ThreadStart(outALPThread)); this.outALPThreadHandle.IsBackground = outALPThreadLivingStatus = true; this.outALPThreadHandle.Name = "AltiGenSP: ALP OUT"; }
protected void EnQueueWaiting(DealDataBase data) { if (IsInWaitingList(data)) { return; } WaitingQueue.Enqueue(data); }
public Customer NextCustomer() { if (WaitingQueue.Count == 0) { return(null); } AddStatisticsChangeOfFront(); return(WaitingQueue.Dequeue()); }
public void Release() { List <TaskCompletionSource <bool> > tasksToRelease; lock (_locker) { if (_currentCount <= 0) { throw new InvalidOperationException(); } _currentCount--; if (_currentCount > 0) { return; } _currentKey = null; if (_waitingQueue.Count == 0) { return; } var newWaitingQueue = new WaitingQueue(); tasksToRelease = new List <TaskCompletionSource <bool> >(); foreach (var entry in _waitingQueue) { if (_currentKey == null || entry.Key == _currentKey) { _currentKey = entry.Key; _currentCount++; tasksToRelease.Add(entry.Value); } else { newWaitingQueue.Enqueue(entry); } } _waitingQueue = newWaitingQueue; } foreach (var item in tasksToRelease) { item.TrySetResult(true); } }
//protected void OnDataGreated(object sender,EventArgs e) //{ // try // { // DealDataBase data = LoadData(sender, e); // if(data == null || IsInWaitingList(data)) // { // return; // } // lock(dealingQueueLocker) // { // if(IsOnDealing(data)) // { // return; // } // } // EnQueueWaiting(data); // //if(!data.IS) // } // catch(Exception ex) // { // ILog.log.Error($"扫描文件出错:{ex.ToString()}"); // } //} //protected void FileScan() //{ // do // { // try // { // foreach(KeyValuePair<object,EventArgs> eventHandler in GetDatas()) // { // OnDataGreated(eventHandler.Key, eventHandler.Value); // while (WaitingQueue.Count > 100) // { // Thread.Sleep(1000); // } // } // } // catch(Exception ex) // { // ILog.log.Error($"扫描文件出错:{ex.ToString()}"); // } // finally // { // Thread.Sleep(1000); // } // } while (true); //} #endregion /// <summary> /// 这里在等待队列里面拿出数据 /// </summary> /// <returns></returns> protected DealDataBase DeQueueWaiting() { if (!WaitingQueue.Any()) { return(null); } DealDataBase res = null; int total = 0; while (!WaitingQueue.TryDequeue(out res)) { if (total % (30 * 100) == 0) { ILog.log.Error($"从等待队列拿出数据失败"); } Thread.Sleep(1000); total += 100; } return(res); }
/// <summary> /// 这里是api 处理得线程 /// </summary> protected void DealApi() { int total = 0; while (true) { while (!WaitingQueue.Any()) { Thread.Sleep(1000); DealDataBase data = DeQueueWaiting(); try { if (data == null) { ILog.log.Error($"获取数据失败"); continue; } if (IsOnDealing(data)) { continue; } if (!EnQueueDealing(data)) { continue; } //ILog.log.Debug($"来了一个数据:任务id--{data.Taskinfo.taskid}任务数据{data.Jsdata}准备进行请求api"); } catch (Exception ex) { } } } }
public void AddCustomer(Customer customer) { AddStatisticsChangeOfFront(); WaitingQueue.Enqueue(customer); }
public ConnectionPool(Func<ISocket> socketFactory) { ConnectTimeout = DefaultConnectTimeout; MaxConnections = DefaultMaxConnections; IdleTimeout = DefaultIdleTimeout; CheckInterval = DefaultCheckInterval; _socketFactory = socketFactory; _waitingQueue = new WaitingQueue(_syncroot); _socketCleanupTimer = new Timer(ReapSockets, null, _cleanupInterval, _cleanupInterval); }
protected bool IsInWaitingList(DealDataBase data) { return(WaitingQueue.Any((x) => { return x.TaskInfoFilePath == data.TaskInfoFilePath; })); }
/// <summary> /// 确定等待队列是否有这个元素 /// </summary> /// <param name="data"></param> /// <returns></returns> protected bool IsInWaitingList(DirectoryInfo data) { return(WaitingQueue.Any((x) => { return x.TaskInfoFilePath == data.FullName; })); }