/// <summary> /// Closes the specified connection. /// </summary> /// <param name="connection">The connection.</param> public abstract void Close(RawConnection connection);
/// <summary> /// Closes the specified connection. /// </summary> /// <param name="connection">The connection.</param> public override void Close(RawConnection connection){ if(connection == null) throw new ArgumentNullException("connection"); connection.Dispose(); }
/// <summary> /// Returns the connection. /// </summary> /// <param name = "connection">The connection.</param> public override void Close(RawConnection connection) { if(connection == null) throw new ArgumentNullException("connection"); if(!IsAlive(connection)) { lock(_syncObject) { _usedConnections.Remove(connection); _invalidConnections.Add(connection); } return; } lock(_syncObject) { _usedConnections.Remove(connection); _freeConnections.Enqueue(connection); Monitor.Pulse(_syncObject); } }
/// <summary> /// Determines whether the specified connection is alive. /// </summary> /// <param name="connection">The connection.</param> /// <returns> /// <c>true</c> if the specified connection is alive; otherwise, <c>false</c>. /// </returns> private bool IsAlive(RawConnection connection) { if(connection == null) throw new ArgumentNullException("connection"); if(Builder.ConnectionLifetime!=TimeSpan.Zero) if(connection.CreationTime.Add(Builder.ConnectionLifetime) < DateTime.Now) return false; if(!connection.IsConnected) return false; return !connection.IsInvalid; }
/// <summary> /// Replaces the invalid connection. /// </summary> private void ReplaceInvalidConnection() { if (_connection == null) return; _connection.MarkAsInvalid(); _factory.Close(_connection); _connection = _factory.Open(); }
/// <summary> /// Closes this instance. /// </summary> public void Close() { if (_connection == null) return; _factory.Close(_connection); _connection = null; }
/// <summary> /// Opens this instance. /// </summary> public void Open() { _connection = _factory.Open(); }