예제 #1
0
        private void SendTransferCompletedAckEventhandleNotify(int rid)
        {
            var             id          = CacheKeyGenerator.GenerateWaitTransferCompletedAckMessageEventWaitHandleId(rid);
            EventWaitHandle eventHandle = AutoEventWaitHandleManager.GetEventWaitHandle(rid);

            if (eventHandle != null)
            {
                try
                {
                    eventHandle.Set();
                }
                catch (ObjectDisposedException)
                { }
            }
        }
예제 #2
0
        private void SendTransferCompletedMessage(SendDataNotifyMessage notifyMessage)
        {
            var transferCompletedMessage = new TransferCompletedMessage(notifyMessage);
            var buffer          = transferCompletedMessage.GenerateBuffer();
            var id              = CacheKeyGenerator.GenerateWaitTransferCompletedAckMessageEventWaitHandleId(notifyMessage.Header.Rid);
            var eventHandleInfo = AutoEventWaitHandleManager.CreateEventWaitHandle(id);

            try
            {
                long beginTs = TimeEx.GetTimestamp();
                long endTs   = beginTs;

                while (!notifyMessage.IsTimeout(beginTs, endTs))
                {
                    try
                    {
                        int rto = TransferParaManager.GetRto(notifyMessage.SrcEndPoint);
                        this._net.Send(buffer, notifyMessage.SrcEndPoint);
                        if (eventHandleInfo.EventWaitHandle.WaitOne(rto))
                        {
                            break;
                        }
                        else
                        {
                            TransferParaManager.AdjustUpRto(notifyMessage.SrcEndPoint);
                        }
                    }
                    catch (SendDataException)
                    {
                        break;
                    }
                    catch (Exception ex)
                    {
                        Loger.Error(ex, "发送传输完成消息异常");
                    }

                    endTs = TimeEx.GetTimestamp();
                }
            }
            finally
            {
                AutoEventWaitHandleManager.RemoveEventWaitHandle(id);
                eventHandleInfo.EventWaitHandle.Dispose();
            }

            //注:如果一直都没有收到确认消息,则超时线程处理
        }
예제 #3
0
        private void RevTimeoutCheckThreadMethod(ThreadExPara para)
        {
            const int defaultTimeoutCheckInveral = 100;
            int       timeoutCheckInveral        = defaultTimeoutCheckInveral;

            ReceiveDataItem[]     revItems;
            SendDataNotifyMessage notifyMessage;

            while (!para.Token.IsCancellationRequested)
            {
                try
                {
                    revItems = this._revItemDic.Values.ToArray();
                    if (revItems.Length == 0)
                    {
                        try
                        {
                            this._revNewDataNoyifyEventHandle.WaitOne(30000);
                        }
                        catch (ObjectDisposedException)
                        { }

                        continue;
                    }

                    timeoutCheckInveral = defaultTimeoutCheckInveral;
                    foreach (var revItem in revItems)
                    {
                        try
                        {
                            notifyMessage = revItem.NotifyMessage;
                            if (revItem.IsTimeout())
                            {
                                //Loger.Warn($"RID:[{notifyMessage.Header.Rid}]传输超时,最后一次收到数据时间[{TimeEx.TimestampToDateTime(revItem.LastAccessTimestamp).AddHours(8).ToString("HH:mm:ss.fffffff")}]从传输列表中移除该项");
                                MemoryCacheEx.Set(CacheKeyGenerator.GenerateRevTimeoutKey(notifyMessage.Header.Rid), notifyMessage.Header.Rid, revItem.MillisecondsTimeout);
                                this.RemoveTransferItem(notifyMessage.Header.Rid, false);
                            }
                            else
                            {
                                if (timeoutCheckInveral > notifyMessage.Timeout)
                                {
                                    timeoutCheckInveral = notifyMessage.Timeout;
                                }
                            }
                        }
                        catch (Exception exi)
                        {
                            Loger.Error(exi);
                        }
                    }

                    notifyMessage = null;
                }
                catch (ObjectDisposedException)
                { }
                catch (Exception ex)
                {
                    Loger.Error(ex, "RevTimeoutCheckThreadMethod异常");
                }

                try
                {
                    this._revTimeoutCheckEventHandle.WaitOne(timeoutCheckInveral);
                }
                catch (ObjectDisposedException)
                { }
            }
        }
예제 #4
0
        private bool ProResourceMode(SendDataNotifyMessage message)
        {
            lock (this._revItemDicLock)
            {
                var             rid = message.Header.Rid;
                ReceiveDataItem receiveDataItem;
                if (this._revItemDic.TryGetValue(rid, out receiveDataItem))
                {
                    receiveDataItem.UpdateLastAccessTimestamp();
                    //Loger.Warn($"[RID:{rid}]的接收项已存在,忽略");
                    return(false);
                }

                if (MemoryCacheEx.Get(CacheKeyGenerator.GenerateRevTimeoutKey(rid)) != null)
                {
                    //Loger.Warn($"[RID:{rid}]接收已超时,忽略");
                    return(false);
                }

                //Loger.Warn($"处理RID[{rid}]发送通知");
                receiveDataItem = new ReceiveDataItem(message, this._config.LocalFileDirectory, this._config.TransferThreadCount);
                if (!this._revItemDic.TryAdd(rid, receiveDataItem))
                {
                    receiveDataItem.Close(true);
                    Loger.Error("this._revItemDic.TryAdd失败,原因未知");
                    return(false);
                }

                int millisecondsTimeout;
                var revItemCount = this._revItemDic.Count;
                if (revItemCount < 1)
                {
                    millisecondsTimeout = message.Timeout / this._config.TimeoutHeartMul;
                }
                else
                {
                    millisecondsTimeout = message.Timeout / (revItemCount * this._config.TimeoutHeartMul);
                }

                var reqDataSchduleInfoManager = new TransferReqDataSchduleInfoManager(message, this._reqDataThreads, millisecondsTimeout);
                TransferResourceManager resourceTransferManager;
                var priority = message.Priority;
                if (this._priorityResourceTransferManagerSortedList.ContainsKey(priority))
                {
                    resourceTransferManager = this._priorityResourceTransferManagerSortedList[priority];
                }
                else
                {
                    lock (this._priorityResourceTransferManagerSortedListLock)
                    {
                        if (this._priorityResourceTransferManagerSortedList.ContainsKey(priority))
                        {
                            resourceTransferManager = this._priorityResourceTransferManagerSortedList[priority];
                        }
                        else
                        {
                            resourceTransferManager = new TransferResourceManager();
                            this._priorityResourceTransferManagerSortedList.Add(priority, resourceTransferManager);
                        }
                    }
                }

                if (resourceTransferManager.AddReqDataSchduleInfoManager(reqDataSchduleInfoManager))
                {
                    this.SendReqDataThreadsEventHandleNotify();
                    return(true);
                }
                else
                {
                    Loger.Error("AddReqDataSchduleInfoManager失败,原因未知");
                    if (!this._revItemDic.TryRemove(rid, out receiveDataItem))
                    {
                        receiveDataItem.Close(true);
                    }

                    return(false);
                }
            }
        }