namespace AsiaINFO.SMS.APPCMPP2.MyThread.DataThread
|
{
|
using AsiaINFO.SMS.APPCMPP2;
|
using AsiaINFO.SMS.APPCMPP2.MyThread;
|
using AsiaINFO.SMS.BusinessFactory;
|
using AsiaINFO.SMS.CMPP2;
|
using AsiaINFO.SMS.Entity;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
public class GetMTWaitThread : ThreadBase
|
{
|
private string _out_gateway_id;
|
private SyncEvents _submitEvents;
|
private Queue<SubmitInfo> _submitQueue;
|
private readonly int _waitlong;
|
private readonly int _waitshort;
|
|
public GetMTWaitThread(SyncEvents syncEvents, Queue<SubmitInfo> submitQueue, SyncEvents submitEvents, string out_gateway_id) : base(syncEvents)
|
{
|
//this._waitlong = 5;
|
this._waitlong = 10;
|
if ((submitQueue == null) || (submitEvents == null))
|
{
|
throw new Exception("GetMTWaitThread参数不能为空!");
|
}
|
this._submitQueue = submitQueue;
|
this._submitEvents = submitEvents;
|
this._out_gateway_id = out_gateway_id;
|
}
|
|
protected void CheckFull()
|
{
|
do
|
{
|
if (this._submitCount < 0x1388)
|
{
|
return;
|
}
|
}
|
while (!base._syncEvents.ExitThreadEvent.WaitOne((int)(0x3e8 * this._waitlong), false));
|
}
|
|
private List<MTWaitInfo> GetMTWaitList()
|
{
|
List<MTWaitInfo> list = new List<MTWaitInfo>();
|
try
|
{
|
list = MTBusiness.GetMTWaitList(100, ShareData.CurrentISMG, this._out_gateway_id);
|
}
|
catch (Exception exception)
|
{
|
base.OnMsg("[GetMTWaitList] " + exception.Message, MsgLevel.Err);
|
}
|
return list;
|
}
|
|
private bool checkFull()
|
{
|
return this._submitCount >= 100;
|
}
|
|
protected override void Run()
|
{
|
List<MTWaitInfo> mTWaitList = null;
|
int num = this._waitlong;
|
do
|
{
|
lock (base._syncSuspendLogLockObject)
|
{
|
//this.CheckFull();
|
|
if (this.checkFull())
|
{
|
base.OnMsg("【待发送】队列已满...等待数:" + this._submitCount,MsgLevel.Msg);
|
//this._submitEvents.NewItemEvent.Set();
|
//base.OnMsg($"【待发送】开始,唤醒...",MsgLevel.Debug);
|
|
|
System.Threading.Thread.Sleep(500);
|
continue;
|
}
|
|
base.OnMsg("【待发送】执行检查...", MsgLevel.Msg);
|
MTBusiness.UpdateUnSendMsg();
|
|
mTWaitList = this.GetMTWaitList();
|
base.OnMsg($"【待发送】已经获取待发送数据,结果:"+mTWaitList.Count,MsgLevel.Msg);
|
if ((mTWaitList != null) && (mTWaitList.Count > 0))
|
{
|
num = this._waitshort;
|
foreach (MTWaitInfo info in mTWaitList)
|
{
|
//检查是否重复
|
if (!DetectionBusiness.Instance.checkMessageId(info.Guid))
|
{
|
DBFactory.log4netService.Debug("[待发送]添加 guid=" + info.Guid + ",手机号码:" + info.MOBILE_NO);
|
DetectionBusiness.Instance.addSubmitMessageToCache(info.Guid);
|
}
|
else
|
{
|
try
|
{
|
DBFactory.log4netService.Debug("[待发送][已存在不处理]-guid=" + info.Guid + ",手机号码:" + info.MOBILE_NO);
|
//SubmitInfo info3 = new SubmitInfo(info, ShareData.SeqID, 1);
|
//MTBusiness.UpdateMTInfo(info3);
|
|
MTBusiness.DeleteMTWait(info, ShareData.CurrentISMG);
|
}
|
catch (Exception ex)
|
{
|
base.OnMsg("[检测重复的异常]- " + ex.Message, MsgLevel.Err);
|
}
|
continue;
|
}
|
|
SubmitInfo info2 = new SubmitInfo(info, ShareData.SeqID, 1);
|
this._submitData = info2;
|
}
|
this._submitEvents.NewItemEvent.Set();
|
}
|
else
|
{
|
num = this._waitlong;
|
}
|
}
|
}
|
while (!base._syncEvents.ExitThreadEvent.WaitOne((int) (0x3e8 * num), false));
|
base.Stop();
|
}
|
|
private int _submitCount
|
{
|
get
|
{
|
lock (((ICollection) this._submitQueue).SyncRoot)
|
{
|
return this._submitQueue.Count;
|
}
|
}
|
}
|
|
private SubmitInfo _submitData
|
{
|
get
|
{
|
lock (((ICollection) this._submitQueue).SyncRoot)
|
{
|
if (this._submitQueue.Count > 0)
|
{
|
return this._submitQueue.Dequeue();
|
}
|
}
|
return null;
|
}
|
set
|
{
|
lock (((ICollection) this._submitQueue).SyncRoot)
|
{
|
this._submitQueue.Enqueue(value);
|
}
|
}
|
}
|
}
|
}
|