static MonetDbConnectionFactory() { _maintenanceTimer.Elapsed += delegate(object sender, ElapsedEventArgs e) { _maintenanceTimer.Stop(); ICollection <ConnectionInformation> _connections = new List <ConnectionInformation>(); lock (_connectionInfo) { _connections = _connectionInfo.Values; } foreach (ConnectionInformation ci in _connections) { lock (ci) { for (int i = 0; i < ci.Active.Count + ci.Busy.Count - ci.Min && ci.Active.Count > 0; i++) { MapiSocket socket = ci.Active.Peek(); if (socket.Created > DateTime.Now.AddMinutes(5)) { socket.Close(); } } } } _maintenanceTimer.Start(); }; _maintenanceTimer.Start(); AppDomain.CurrentDomain.DomainUnload += delegate(object sender, EventArgs e) { ICollection <ConnectionInformation> _connections = new List <ConnectionInformation>(); lock (_connectionInfo) { _connections = _connectionInfo.Values; } foreach (ConnectionInformation ci in _connections) { lock (ci) { for (int i = 0; i < ci.Active.Count + ci.Busy.Count; i++) { ci.Active.Dequeue(60000).Close(); } } } }; }
public static void CloseConnection(MapiSocket socket, string database) { string key = GetConnectionPoolKey(socket.Host, socket.Port, socket.Username, database); ConnectionInformation info; lock (_connectionInfo) { info = _connectionInfo[key]; } lock (info) { info.Busy.Remove(socket); info.Active.Enqueue(socket); } }
private static void SetupConnections(string host, int port, string username, string password, string database, bool useSsl, int minConn, int maxConn) { string key = GetConnectionPoolKey(host, port, username, database); ConnectionInformation info; lock (_connectionInfo) { if (!_connectionInfo.TryGetValue(key, out info)) { info = _connectionInfo[key] = new ConnectionInformation(minConn, maxConn); } } if (useSsl) { throw new MonetDbException("SSL Connections not supported by this client library."); } lock (info) { for (int i = info.Active.Count + info.Busy.Count; i < info.Min || (info.Active.Count == 0 && i < info.Max); i++) { try { MapiSocket socket = new MapiSocket(); socket.Connect(host, port, username, password, database); info.Active.Enqueue(socket); } catch (IOException ex) { throw new MonetDbException(ex, "Problem connecting to the MonetDB server."); } } } }