public int Call(AbstractDBOperater query, DBCallback callback = null) { int dbIndex = GetDBIndex(); _dbManagerList[dbIndex].Call(query, callback); return(dbIndex); }
public void Add(AbstractDBOperater query) { query.Init(this); lock (_saveQueue) { _saveQueue.Enqueue(query); } }
public void Call(AbstractDBOperater query, int index, string table_name = DBProxyDefault.DefaultTableName, DBOperateType type = DBProxyDefault.DefaultOperateType, DBCallback callback = null) { DBWorkPool dbPool = GetDbByTable(table_name, type); if (dbPool == null) { Log.Error("db call {0} failed: can not find table {1} type {2} db", query.GetCmd(), table_name, type.ToString()); return; } dbPool.Call(query, index, callback); }
public Queue <AbstractDBOperater> GetPostUpdateQueue() { Queue <AbstractDBOperater> ret = new Queue <AbstractDBOperater>(); lock (_postUpdateQueue) { while (_postUpdateQueue.Count > 0) { AbstractDBOperater query = _postUpdateQueue.Dequeue(); ret.Enqueue(query); } } return(ret); }
public int Call(AbstractDBOperater query, int force_index, DBCallback callback = null) { int dbIndex = 0; if (force_index > 0 && force_index < _dbManagerList.Count) { _dbManagerList[force_index].Call(query, callback); DBCallCountList[force_index]++; } else { _dbManagerList[0].Call(query, callback); DBCallCountList[0]++; } if (DBCallNameList.ContainsKey(query.ToString()) == false) { DBCallNameList.Add(query.ToString(), 1); } else { DBCallNameList[query.ToString()]++; } return(dbIndex); }
public void Run() { var tempPostUpdateQueue = new Queue <AbstractDBOperater>(); var time = new TimeUtil(); time.Init(); while (true) { var dt = time.Update(); _lasttime = dt.TotalMilliseconds; if (_lasttime > 1) { } else { Thread.Sleep(1); } if (_totaltime > 10000) { _totaltime = 0; } else { _totaltime += _lasttime; } lock (ReconnectInfo) { if (ReconnectInfo.NeedReconnect) { Opened = false; string log = String.Format("disconnect from db {0}, esplased {1} ms", _database, ReconnectInfo.TryConnectTime); AddExceptionLog(log); ReconnectInfo.TryConnectTime += _lasttime; MySqlConnection conn = new MySqlConnection(ConnStr); try { conn.Open(); Opened = true; ReconnectInfo.Reset(); } catch (MySqlException e) { Console.WriteLine(e.ToString()); AddExceptionLog(e.ToString()); } finally { conn.Close(); } } else { try { lock (_saveQueue) { if (_saveQueue.Count == 0) { continue; } while (_saveQueue.Count > 0) { AbstractDBOperater query = _saveQueue.Dequeue(); _executionQueue.Enqueue(query); } } while (_executionQueue.Count != 0) { var query = _executionQueue.Dequeue(); bool success = query.Execute(); if (success == false) { if (query.ErrorText != null) { AddExceptionLog(query.ErrorText); } tempPostUpdateQueue.Enqueue(query); } else { tempPostUpdateQueue.Enqueue(query); } } lock (_postUpdateQueue) { while (tempPostUpdateQueue.Count != 0) { _postUpdateQueue.Enqueue(tempPostUpdateQueue.Dequeue()); } } tempPostUpdateQueue.Clear(); } catch (Exception e) { Console.WriteLine(e.ToString()); } } } } }
public void Call(AbstractDBOperater query, DBCallback callback = null) { query.OnCall(callback); Add(query); }