You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.9 KiB
104 lines
2.9 KiB
using FileTransDataObject;
|
|
using Google.Protobuf.WellKnownTypes;
|
|
using Sog;
|
|
|
|
namespace SMAgent
|
|
{
|
|
class AgentFileRecvMng : Singleton<AgentFileRecvMng>
|
|
{
|
|
private FileRecvMgr recvMgr;
|
|
|
|
private bool isFinish;
|
|
|
|
private long lastTickTime;
|
|
|
|
public AgentFileRecvMng()
|
|
{
|
|
recvMgr = new FileRecvMgr();
|
|
recvMgr._SendFileContentReq = SendFileContentReq;
|
|
recvMgr._SendFileRecvStateReq = SendFileRecvStateReq;
|
|
|
|
isFinish = true;
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
TraceLog.Debug("AgentFileRecvMng.Clear");
|
|
|
|
isFinish = true;
|
|
recvMgr.Clear();
|
|
}
|
|
|
|
public void Tick(long nowMs)
|
|
{
|
|
if (nowMs < lastTickTime + 1000)
|
|
{
|
|
return;
|
|
}
|
|
|
|
lastTickTime = nowMs;
|
|
|
|
recvMgr.Tick(nowMs);
|
|
|
|
// agent同一时间只会从一个center拉取数据, 接收完成并上报结果后释放资源
|
|
if (! isFinish && recvMgr.IsFinish())
|
|
{
|
|
isFinish = true;
|
|
Clear();
|
|
}
|
|
}
|
|
|
|
public void OnTransFileNotify(SMTransFileNotify notify)
|
|
{
|
|
// agent同一时间只会从一个center拉取数据, 所以收到传送通知时直接开始新一轮接收
|
|
Clear();
|
|
isFinish = false;
|
|
|
|
recvMgr.OnTransFileNotify(notify);
|
|
}
|
|
|
|
public void OnFileContentRes(SMFileContentRes res)
|
|
{
|
|
recvMgr.OnFileContentRes(res);
|
|
}
|
|
|
|
public void OnFileRecvStateRes(SMFileRecvStateRes res)
|
|
{
|
|
recvMgr.OnFileRecvStateRes(res);
|
|
}
|
|
|
|
public void OnCancelTransNotify(SMCancelTransNotify notify)
|
|
{
|
|
recvMgr.CancelTrans(notify.HostName);
|
|
}
|
|
|
|
public void SendFileContentReq(FileRecvNode recvNode, FileRecvData fileData)
|
|
{
|
|
var req = new SMFileContentReq
|
|
{
|
|
FileName = fileData.fileName,
|
|
FileMd5 = fileData.fileMd5,
|
|
HostName = SMAgentUtils.HostName,
|
|
ContentOffset = fileData.ReqFileOffset,
|
|
TransSeq = recvNode.transSeq
|
|
};
|
|
SMAgentNet.Instance.SendMsgToCenter(req, SMMsgID.FileContentReq);
|
|
}
|
|
|
|
public void SendFileRecvStateReq(FileRecvNode recvNode)
|
|
{
|
|
SMFileRecvStateReq req = new SMFileRecvStateReq();
|
|
req.TransSeq = recvNode.transSeq;
|
|
req.HostName = SMAgentUtils.HostName;
|
|
foreach (FileRecvData fileData in recvNode.fileList)
|
|
{
|
|
req.FileList.Add(new FileRecvState
|
|
{
|
|
FileName = fileData.fileName, FileMd5 = fileData.fileMd5, RecvState = fileData.recvState,
|
|
});
|
|
}
|
|
|
|
SMAgentNet.Instance.SendMsgToCenter(req, SMMsgID.FileRecvStateReq);
|
|
}
|
|
}
|
|
}
|