Esempio n. 1
0
        //internal static List<MongodbServerStateInfo> GetState()
        //{
        //    lock (submitDataMemoryQueueServices)
        //    {
        //        var state = new List<MongodbServerStateInfo>()
        //        {
        //            new MongodbServerStateInfo
        //            {
        //                MemoryQueueServiceStates = submitDataMemoryQueueServices.ToDictionary(s=>s.Key, s=>s.Value.GetState()),
        //            }
        //        };
        //        return state;
        //    }
        //}

        private static MongoServer CreateMasterMongoServer(string typeName)
        {
            if (!masterServerCache.ContainsKey(typeName))
            {
                lock (masterServerCache)
                {
                    if (!masterServerCache.ContainsKey(typeName))
                    {
                        var config = MongodbServerConfiguration.GetMongodbServerConfigurationItem(typeName);
                        if (config == null)
                        {
                            LocalLoggingService.Warning("{0} {1} {2} {3}", MongodbServerConfiguration.ModuleName, "MongodbServer_Master", "CreateMasterMongoServer",
                                                        string.Format("没取到服务器配置项,参数:{0}", typeName));
                            return(null);
                        }
                        var server = MongodbServerConfiguration.GetMongodbServerUrl(config.MongodbServerUrlName);
                        if (server == null)
                        {
                            LocalLoggingService.Warning("{0} {1} {2} {3}", MongodbServerConfiguration.ModuleName, "MongodbServer_Master", "CreateMasterMongoServer",
                                                        string.Format("没取到服务器地址,参数:{0}", config.MongodbServerUrlName));
                            return(null);
                        }
                        masterServerCache.Add(typeName, MongoServer.Create(server.Master));
                    }
                }
            }
            return(masterServerCache[typeName]);
        }
Esempio n. 2
0
        public void SubmitData(IList <MongodbData> dataList, MongodbDatabaseDescription databaseDescription)
        {
            if (dataList == null || dataList.Count == 0)
            {
                return;
            }

            var typeFullName = dataList.First().TypeFullName;

            try
            {
                var config = MongodbServerConfiguration.GetMongodbServerConfigurationItem(typeFullName);
                if (config == null)
                {
                    LocalLoggingService.Warning("{0} {1} {2} {3}", MongodbServerConfiguration.ModuleName, "MongodbServer_Master", "SubmitData",
                                                string.Format("没取到服务器配置项,参数:{0}", typeFullName));
                    return;
                }

                if (!submitDataMemoryQueueServices.ContainsKey(typeFullName))
                {
                    lock (submitDataMemoryQueueServices)
                    {
                        if (!submitDataMemoryQueueServices.ContainsKey(typeFullName))
                        {
                            var memoryQueueService = LocalServiceLocator.GetService <IMemoryQueueService>();
                            memoryQueueService.Init(new MemoryQueueServiceConfiguration(string.Format("{0}_{1}", ServiceName, typeFullName), InternalSubmitData)
                            {
                                ConsumeErrorAction                   = config.ConsumeErrorAction,
                                ConsumeIntervalMilliseconds          = config.ConsumeIntervalMilliseconds,
                                ConsumeIntervalWhenErrorMilliseconds = config.ConsumeIntervalWhenErrorMilliseconds,
                                ConsumeItemCountInOneBatch           = config.ConsumeItemCountInOneBatch,
                                ConsumeThreadCount                   = config.ConsumeThreadCount,
                                MaxItemCount = config.MaxItemCount,
                                NotReachBatchCountConsumeAction = config.NotReachBatchCountConsumeAction,
                                ReachMaxItemCountAction         = config.ReachMaxItemCountAction,
                            });
                            submitDataMemoryQueueServices.Add(typeFullName, memoryQueueService);
                        }
                    }
                }

                if (databaseDescription != null)
                {
                    InitMongodbDatabaseDescription(typeFullName, databaseDescription);
                }

                if (config.SubmitToDatabase)
                {
                    submitDataMemoryQueueServices[typeFullName].EnqueueBatch(dataList);
                }
            }
            catch (Exception ex)
            {
                LocalLoggingService.Error("{0} {1} {2} {3}", MongodbServerConfiguration.ModuleName, "MongodbServer_Master", "SubmitData", ex.Message);
                throw;
            }
        }
Esempio n. 3
0
        private static MongodbServerUrl GetMongodbServerUrl(string typeName)
        {
            var config = MongodbServerConfiguration.GetMongodbServerConfigurationItem(typeName);

            if (config == null)
            {
                return(null);
            }
            var server = MongodbServerConfiguration.GetMongodbServerUrl(config.MongodbServerUrlName);

            if (server == null)
            {
                return(null);
            }
            return(server);
        }
Esempio n. 4
0
 private static MongoServer CreateSlaveMongoServer(string typeName)
 {
     try
     {
         if (!slaveServerCache.ContainsKey(typeName))
         {
             lock (slaveServerCache)
             {
                 if (!slaveServerCache.ContainsKey(typeName))
                 {
                     var config = MongodbServerConfiguration.GetMongodbServerConfigurationItem(typeName);
                     if (config == null)
                     {
                         LocalLoggingService.Warning("{0} {1} {2} {3}", MongodbServerConfiguration.ModuleName, "MongodbServer_Slave", "CreateSlaveMongoServer",
                                                     string.Format("没取到服务器配置项,参数:{0}", typeName));
                         return(null);
                     }
                     var server = MongodbServerConfiguration.GetMongodbServerUrl(config.MongodbServerUrlName);
                     if (server == null)
                     {
                         LocalLoggingService.Warning("{0} {1} {2} {3}", MongodbServerConfiguration.ModuleName, "MongodbServer_Slave", "CreateSlaveMongoServer",
                                                     string.Format("没取到服务器地址,参数:{0}", config.MongodbServerUrlName));
                         return(null);
                     }
                     slaveServerCache.Add(typeName, MongoServer.Create(server.Slave));
                 }
             }
         }
         return(slaveServerCache[typeName]);
     }
     catch (Exception ex)
     {
         LocalLoggingService.Error("{0} {1} {2} {3} {4}", MongodbServerConfiguration.ModuleName, "MongodbServer_Slave", "CreateSlaveMongoServer",
                                   string.Format("创建服务器链接出错,参数:{0}", typeName), ex.Message);
         throw;
     }
 }