private static bool StartPool(MyCase mc) { uint threads, sessions_per_host; bool ok = false; System.Collections.Generic.List <CConnectionContext> Hosts; CSocketPool <CSql> pool = null; switch (mc) { case MyCase.mcMasterWithClientQueue: Master = new SPA.CMyMaster(Config.Master.DefaultDB, false, Config.Master.RecvTimeout); Master.QueueName = "qmaster"; pool = Master; threads = Config.Master.Threads; sessions_per_host = Config.Master.Sessions_Per_Host; Hosts = Config.Master.Hosts; break; case MyCase.mcSlaveWithClientQueue: Slave = new SPA.CMyMaster.CSlavePool(Config.Slave.DefaultDB, Config.Slave.RecvTimeout); Slave.QueueName = "qslave"; pool = Slave; threads = Config.Slave.Threads; sessions_per_host = Config.Slave.Sessions_Per_Host; Hosts = Config.Slave.Hosts; break; case MyCase.mcMasterWithoutClientQueue: MasterNotQueued = new SPA.CMyMaster.CSlavePool(Config.Master.DefaultDB, Config.Master.RecvTimeout); pool = MasterNotQueued; threads = Config.Master.Threads; sessions_per_host = Config.Master.Sessions_Per_Host; Hosts = Config.Master.Hosts; break; default: throw new System.NotImplementedException("Not implemented"); } pool.DoSslServerAuthentication += (sender, cs) => { int errCode; string res = cs.UCert.Verify(out errCode); return(errCode == 0); //true -- user id and password will be sent to server }; uint sockets_per_thread = sessions_per_host * (uint)Hosts.Count; if (sockets_per_thread > 0 && threads > 0) { CConnectionContext[,] ppCC = new CConnectionContext[threads, sockets_per_thread]; for (uint i = 0; i < threads; ++i) { for (uint j = 0; j < (uint)Hosts.Count; ++j) { for (uint n = 0; n < sessions_per_host; ++n) { ppCC[i, j *sessions_per_host + n] = Hosts[(int)j]; } } } ok = pool.StartSocketPool(ppCC); //not automatcally merge requests saved in local/client message queue files in case there is one host only if (Hosts.Count < 2) { pool.QueueAutoMerge = false; } } return(ok); }
private static bool StartPool(bool master) { uint threads, sessions_per_host; bool ok = false; List <CConnectionContext> Hosts; CSocketPool <CSql> pool; if (master) { Master = new SPA.CMyMaster(Config.Master.DefaultDB, false, Config.Master.RecvTimeout); Master.QueueName = "qmaster"; pool = Master; threads = Config.Master.Threads; sessions_per_host = Config.Master.Sessions_Per_Host; Hosts = Config.Master.Hosts; } else { Slave = new SPA.CMySlave(Config.Slave.DefaultDB, Config.Slave.RecvTimeout); Slave.QueueName = "qslave"; pool = Slave; threads = Config.Slave.Threads; sessions_per_host = Config.Slave.Sessions_Per_Host; Hosts = Config.Slave.Hosts; } pool.DoSslServerAuthentication += (sender, cs) => { int errCode; string res = cs.UCert.Verify(out errCode); return(errCode == 0); //true -- user id and password will be sent to server }; uint sockets_per_thread = sessions_per_host * (uint)Hosts.Count; if (sockets_per_thread > 0 && threads > 0) { CConnectionContext[,] ppCC = new CConnectionContext[threads, sockets_per_thread]; for (uint i = 0; i < threads; ++i) { for (uint j = 0; j < (uint)Hosts.Count; ++j) { for (uint n = 0; n < sessions_per_host; ++n) { ppCC[i, j *sessions_per_host + n] = Hosts[(int)j]; } } } ok = pool.StartSocketPool(ppCC); //no automatcally merging requests saved in local/client message queue files in case master or one host if (Hosts.Count < 2 || master) { pool.QueueAutoMerge = false; } } return(ok); }