|
13 | 13 | namespace Microsoft.Data.SqlClient.ConnectionPool
|
14 | 14 | {
|
15 | 15 | /// <summary>
|
16 |
| - /// A base class for implementing database connection pools. |
17 |
| - /// Responsible for managing the lifecycle of connections and providing access to database connections. |
| 16 | + /// A base interface for implementing database connection pools. |
| 17 | + /// Derived classes are responsible for managing the lifecycle |
| 18 | + /// of connections and providing access to database connections. |
18 | 19 | /// </summary>
|
19 | 20 | internal interface IDbConnectionPool
|
20 | 21 | {
|
21 | 22 | #region Properties
|
| 23 | + /// <summary> |
| 24 | + /// An id that uniqely identifies this connection pool. |
| 25 | + /// </summary> |
22 | 26 | int ObjectId { get; }
|
23 | 27 |
|
| 28 | + /// <summary> |
| 29 | + /// The current state of the connection pool. |
| 30 | + /// </summary> |
24 | 31 | DbConnectionPoolState State { get; set; }
|
25 | 32 |
|
| 33 | + /// <summary> |
| 34 | + /// The number of connections currently managed by the pool. |
| 35 | + /// May be larger than the number of connections currently sitting idle in the pool. |
| 36 | + /// </summary> |
26 | 37 | int Count { get; }
|
27 | 38 |
|
| 39 | + /// <summary> |
| 40 | + /// Gets the factory used to create database connections. |
| 41 | + /// </summary> |
28 | 42 | DbConnectionFactory ConnectionFactory { get; }
|
29 | 43 |
|
| 44 | + /// <summary> |
| 45 | + /// Indicates whether an error has occurred in the pool. |
| 46 | + /// Primarily used to support the pool blocking period feature. |
| 47 | + /// </summary> |
30 | 48 | bool ErrorOccurred { get; }
|
31 | 49 |
|
| 50 | + /// <summary> |
| 51 | + /// Gets the duration of time to wait before reassigning a connection to a different server in a load-balanced |
| 52 | + /// environment. |
| 53 | + /// </summary> |
32 | 54 | TimeSpan LoadBalanceTimeout { get; }
|
33 | 55 |
|
| 56 | + /// <summary> |
| 57 | + /// Gets the identity used by the connection pool when establishing connections. |
| 58 | + /// </summary> |
34 | 59 | DbConnectionPoolIdentity Identity { get; }
|
35 | 60 |
|
| 61 | + /// <summary> |
| 62 | + /// Indicates whether the connection pool is currently running. |
| 63 | + /// </summary> |
36 | 64 | bool IsRunning { get; }
|
37 | 65 |
|
| 66 | + /// <summary> |
| 67 | + /// Gets a reference to the connection pool group that this pool belongs to. |
| 68 | + /// </summary> |
38 | 69 | DbConnectionPoolGroup PoolGroup { get; }
|
39 | 70 |
|
| 71 | + /// <summary> |
| 72 | + /// Gets the options for the connection pool group. |
| 73 | + /// </summary> |
40 | 74 | DbConnectionPoolGroupOptions PoolGroupOptions { get; }
|
41 | 75 |
|
| 76 | + /// <summary> |
| 77 | + /// Gets the provider information for the connection pool. |
| 78 | + /// </summary> |
42 | 79 | DbConnectionPoolProviderInfo ProviderInfo { get; }
|
43 | 80 |
|
| 81 | + /// <summary> |
| 82 | + /// Gets the authentication contexts cached by the pool. |
| 83 | + /// </summary> |
44 | 84 | ConcurrentDictionary<DbConnectionPoolAuthenticationContextKey, DbConnectionPoolAuthenticationContext> AuthenticationContexts { get; }
|
45 | 85 |
|
| 86 | + /// <summary> |
| 87 | + /// Indicates whether the connection pool is using load balancing. |
| 88 | + /// </summary> |
46 | 89 | bool UseLoadBalancing { get; }
|
47 | 90 | #endregion
|
48 | 91 |
|
49 | 92 | #region Methods
|
| 93 | + /// <summary> |
| 94 | + /// Clears the connection pool, releasing all connections and resetting the state. |
| 95 | + /// </summary> |
50 | 96 | void Clear();
|
51 | 97 |
|
52 |
| - bool TryGetConnection(DbConnection owningObject, TaskCompletionSource<DbConnectionInternal> retry, DbConnectionOptions userOptions, out DbConnectionInternal connection); |
53 |
| - |
| 98 | + /// <summary> |
| 99 | + /// Attempts to get a connection from the pool. |
| 100 | + /// </summary> |
| 101 | + /// <param name="owningObject">The SqlConnection that will own this internal connection.</param> |
| 102 | + /// <param name="taskCompletionSource">Used when calling this method in an async context. |
| 103 | + /// The internal connection will be set on completion source rather than passed out via the out parameter.</param> |
| 104 | + /// <param name="userOptions">The user options to use if a new connection must be opened.</param> |
| 105 | + /// <param name="connection">The retrieved connection will be passed out via this parameter.</param> |
| 106 | + /// <returns>Returns true if a connection was set in the out parameter, otherwise returns false.</returns> |
| 107 | + bool TryGetConnection(DbConnection owningObject, TaskCompletionSource<DbConnectionInternal> taskCompletionSource, DbConnectionOptions userOptions, out DbConnectionInternal connection); |
| 108 | + |
| 109 | + /// <summary> |
| 110 | + /// Replaces the internal connection currently associated with owningObject with a new internal connection from the pool. |
| 111 | + /// </summary> |
| 112 | + /// <param name="owningObject">The connection whos internal connection should be replaced.</param> |
| 113 | + /// <param name="userOptions">The user options to use if a new connection must be opened.</param> |
| 114 | + /// <param name="oldConnection">The internal connection currently associated with the owning object.</param> |
| 115 | + /// <returns></returns> |
54 | 116 | DbConnectionInternal ReplaceConnection(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection);
|
55 | 117 |
|
| 118 | + /// <summary> |
| 119 | + /// Returns an internal connection to the pool. |
| 120 | + /// </summary> |
| 121 | + /// <param name="obj">The internal connection to return to the pool.</param> |
| 122 | + /// <param name="owningObject">The connection that currently owns this internal connection. Used to verify ownership.</param> |
56 | 123 | void ReturnInternalConnection(DbConnectionInternal obj, object owningObject);
|
57 | 124 |
|
| 125 | + /// <summary> |
| 126 | + /// Puts an internal connection from a transacted pool back into the general pool. |
| 127 | + /// </summary> |
| 128 | + /// <param name="obj">The internal connection to return to the pool.</param> |
58 | 129 | void PutObjectFromTransactedPool(DbConnectionInternal obj);
|
59 | 130 |
|
| 131 | + /// <summary> |
| 132 | + /// Initializes and starts the connection pool. Should be called once when the pool is created. |
| 133 | + /// </summary> |
60 | 134 | void Startup();
|
61 | 135 |
|
| 136 | + /// <summary> |
| 137 | + /// Shuts down the connection pool releasing any resources. Should be called once when the pool is no longer needed. |
| 138 | + /// </summary> |
62 | 139 | void Shutdown();
|
63 | 140 |
|
| 141 | + /// <summary> |
| 142 | + /// Informs the pool that a transaction has ended. The pool will commit and reset any internal |
| 143 | + /// the transacted object associated with this transaction. |
| 144 | + /// </summary> |
| 145 | + /// <param name="transaction">The transaction that has ended.</param> |
| 146 | + /// <param name="transactedObject">The internal connection that should be committed and reset.</param> |
64 | 147 | void TransactionEnded(Transaction transaction, DbConnectionInternal transactedObject);
|
65 | 148 | #endregion
|
66 | 149 | }
|
|
0 commit comments