/// <summary> /// 异步发送Cache通知 /// </summary> /// <param name="notifyDataArray">Cache通知数据</param> public void SendNotifyAsync(params CacheNotifyData[] notifyDataArray) { SendDataWrapper sdWrapper = new SendDataWrapper( notifyDataArray, GetSerializedCacheData(notifyDataArray), UdpCacheNotifierSettings.GetConfig().EndPoints); ThreadPool.QueueUserWorkItem(new WaitCallback(SendNotifyThreadCallBack), sdWrapper); }
/// <summary> /// 发送Cache通知 /// </summary> /// <param name="notifyDataArray">Cache通知数据</param> public void SendNotify(params CacheNotifyData[] notifyDataArray) { ExceptionHelper.FalseThrow <ArgumentNullException>(notifyDataArray != null, "notifyDataArray"); UdpCacheNotifierSettings settings = UdpCacheNotifierSettings.GetConfig(); List <byte[]> dataList = GetSerializedCacheData(notifyDataArray); SendSerializedData(notifyDataArray, dataList, settings.EndPoints); }
/// <summary> /// 获取udpCacheNotifierSettings的配置信息 /// </summary> /// <returns>UdpCacheNotifierSettings实例</returns> public static UdpCacheNotifierSettings GetConfig() { UdpCacheNotifierSettings result = (UdpCacheNotifierSettings)ConfigurationBroker.GetSection("udpCacheNotifierSettings"); if (result == null) { result = new UdpCacheNotifierSettings(); result.EndPoints.InitDefaultData(); } return(result); }
private static List <byte[]> GetSerializedCacheData(CacheNotifyData[] notifyDataArray) { ExceptionHelper.FalseThrow <ArgumentNullException>(notifyDataArray != null, "notifyDataArray"); UdpCacheNotifierSettings settings = UdpCacheNotifierSettings.GetConfig(); List <byte[]> dataList = new List <byte[]>(); foreach (CacheNotifyData notifyData in notifyDataArray) { byte[] data = notifyData.ToBytes(); ExceptionHelper.FalseThrow(data.Length <= settings.PackageSize, "Cache Key{0}的通知数据包大小为{1}字节, 必须小于等于{2}字节,可以调整udpCacheNotifierSettings配置节的packageSize属性来解决此问题", notifyData.CacheKey, data.Length, settings.PackageSize); dataList.Add(data); } return(dataList); }