예제 #1
0
        private static long InnerReadCacheNotifyData(long lastTicks, MemoryMappedViewAccessor accessor, CacheNotifyDataMapInfo mapInfo, List <CacheNotifyData> result)
        {
            int  itemSize    = Marshal.SizeOf(typeof(CacheNotifyDataMapItem));
            long returnTicks = lastTicks;

            long startPointer = Marshal.SizeOf(typeof(CacheNotifyDataMapInfo));

            for (int i = 0; i < CacheNotifyDataMapInfo.CacheDataItemCount; i++)
            {
                CacheNotifyDataMapItem item;

                accessor.Read(startPointer, out item);

                if (item.Ticks > lastTicks)
                {
                    if (item.Ticks > returnTicks)
                    {
                        returnTicks = item.Ticks;
                    }

                    byte[] data = new byte[item.Size];

                    accessor.ReadArray(startPointer + itemSize, data, 0, (int)item.Size);

                    CacheNotifyData cnd = CacheNotifyData.FromBuffer(data);

                    result.Add(cnd);
                }

                startPointer += itemSize + CacheNotifyDataMapInfo.CacheDataBlockSize;
            }

            return(returnTicks);
        }
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <returns></returns>
        public override CacheNotifyData[] GetData()
        {
            CacheNotifyData[] result = CacheNotifyData.EmptyData;

            try
            {
                byte[]          recBuffer = udp.Receive(ref bindedEndPoint);
                CacheNotifyData data      = CacheNotifyData.FromBuffer(recBuffer);
                result = new CacheNotifyData[] { data };

                UdpCacheNotifier.TotalCounters.UdpReceivedItemsCounter.Increment();
                UdpCacheNotifier.TotalCounters.UdpReceivedCountPerSecond.Increment();

                UdpCacheNotifier.AppInstanceCounters.UdpReceivedItemsCounter.Increment();
                UdpCacheNotifier.AppInstanceCounters.UdpReceivedCountPerSecond.Increment();

                CacheNotifierSettings settings = CacheNotifierSettings.GetConfig();

                if (settings.ForwardUdpToMmf && settings.EnableMmfNotifier)
                {
                    CacheNotifyDataMap.WriteNotExistCacheNotifyData(DateTime.Now.Ticks, result);

                    UdpCacheNotifier.TotalCounters.ForwardedUdpToMmfItems.Increment();
                    UdpCacheNotifier.TotalCounters.ForwardUdpToMmfCountPerSecond.Increment();

                    UdpCacheNotifier.AppInstanceCounters.ForwardedUdpToMmfItems.Increment();
                    UdpCacheNotifier.AppInstanceCounters.ForwardUdpToMmfCountPerSecond.Increment();
                }
            }
            catch (SocketException ex)
            {
                if (ex.SocketErrorCode != SocketError.TimedOut)
                {
                    throw;
                }
            }

            return(result);
        }