private void DoUploadBiz() { long uploadTime = TopUtils.GetCurrentTimeMillis() + FlushInterval; while (true) { try { Thread.Sleep(SleepTime); IDictionary <string, Counter> appUserCounterMap = SecurityCounter.GetUserCounter(topClient.appKey); if (TopUtils.GetCurrentTimeMillis() >= uploadTime || (appUserCounterMap.Count * 4 > 65536)) { StringBuilder counterBuilder = new StringBuilder(); IDictionary <string, Counter> cloneAppUserCounter = SecurityCounter.CloneUserCounter(topClient.appKey); SecurityCounter.CleanUserCounter(topClient.appKey); int count = 0; foreach (KeyValuePair <string, Counter> currentPair in cloneAppUserCounter) { Counter counter = currentPair.Value; if (counterBuilder.Length > 0) { counterBuilder.Append(";"); } counterBuilder.Append(currentPair.Key); GenerateCounter(counterBuilder, counter); if ((++count) % 100 == 0) { DoUpload(counterBuilder.ToString(), AppUserSecretType); counterBuilder = new StringBuilder(); } } if (counterBuilder.Length > 0) { DoUpload(counterBuilder.ToString(), AppUserSecretType); counterBuilder = new StringBuilder(); } Counter appCounter = SecurityCounter.GetAppCounter(topClient.appKey); counterBuilder.Append(SecurityCore.GetAppUserSecretCache().Count); GenerateCounter(counterBuilder, appCounter); appCounter.Reset(); long uploadInterval = DoUpload(counterBuilder.ToString(), AppSecretType); uploadTime = TopUtils.GetCurrentTimeMillis() + uploadInterval; } } catch (Exception e) { Log.Error(string.Format("flushSecretApiReporter error: {0}", e.Message)); } } }
private void InitSecretThread() { Thread uploadThread = new Thread(o => { int uploadInterval = FlushInterval; while (true) { try { Thread.Sleep(uploadInterval); IDictionary <string, object> jsonMap = new Dictionary <string, object>(); jsonMap.Add("sessionNum", SecurityCore.GetAppUserSecretCache().Count); jsonMap.Add("encryptPhoneNum", SecurityCounter.GetEncryptPhoneNum()); jsonMap.Add("encryptNickNum", SecurityCounter.GetEncryptNickNum()); jsonMap.Add("encryptReceiverNameNum", SecurityCounter.GetEncryptReceiverNameNum()); jsonMap.Add("decryptPhoneNum", SecurityCounter.GetDecryptPhoneNum()); jsonMap.Add("decryptNickNum", SecurityCounter.GetDecryptNickNum()); jsonMap.Add("decryptReceiverNameNum", SecurityCounter.GetDecryptReceiverNameNum()); jsonMap.Add("searchPhoneNum", SecurityCounter.GetSearchPhoneNum()); jsonMap.Add("searchNickNum", SecurityCounter.GetSearchNickNum()); jsonMap.Add("searchReceiverNameNum", SecurityCounter.GetSearchReceiverNameNum()); SecurityCounter.Reset(); String contentJson = TopUtils.ObjectToJson(jsonMap); uploadInterval = DoUpload(contentJson, SecretType); } catch (Exception e) { Log.Error(string.Format("flushSecretApiReporter error: {0}", e.Message)); } } }); uploadThread.IsBackground = true; uploadThread.Name = "flushSecretApiReporter-thread"; uploadThread.Start(); }