@@ -7,44 +7,43 @@ use typed_builder::TypedBuilder;
77use crate :: {
88 bson_util,
99 client:: { auth:: Credential , options:: ServerApi } ,
10- event:: cmap:: CmapEventHandler ,
10+ event:: cmap:: { CmapEventHandler , ConnectionPoolOptions as EventOptions } ,
1111 options:: { ClientOptions , DriverInfo , StreamAddress , TlsOptions } ,
1212} ;
1313
14- /// Contains the options for creating a connection pool. While these options are specified at the
15- /// client-level, `ConnectionPoolOptions` is exposed for the purpose of CMAP event handling.
14+ /// Contains the options for creating a connection pool.
1615#[ derive( Clone , Default , Deserialize , TypedBuilder , Derivative ) ]
1716#[ derivative( Debug , PartialEq ) ]
1817#[ builder( field_defaults( default , setter( strip_option) ) ) ]
1918#[ serde( rename_all = "camelCase" ) ]
20- pub struct ConnectionPoolOptions {
19+ pub ( crate ) struct ConnectionPoolOptions {
2120 /// The application name specified by the user. This is sent to the server as part of the
2221 /// handshake that each connection makes when it's created.
23- pub app_name : Option < String > ,
22+ pub ( crate ) app_name : Option < String > ,
2423
25- /// The connect timeout passed to each underlying TcpStream when attemtping to connect to the
24+ /// The connect timeout passed to each underlying TcpStream when attempting to connect to the
2625 /// server.
2726 #[ serde( skip) ]
28- pub connect_timeout : Option < Duration > ,
27+ pub ( crate ) connect_timeout : Option < Duration > ,
2928
3029 /// The credential to use for authenticating connections in this pool.
3130 #[ serde( skip) ]
32- pub credential : Option < Credential > ,
31+ pub ( crate ) credential : Option < Credential > ,
3332
3433 /// Extra information to append to the driver version in the metadata of the handshake with the
3534 /// server. This should be used by libraries wrapping the driver, e.g. ODMs.
3635 #[ serde( skip) ]
37- pub driver_info : Option < DriverInfo > ,
36+ pub ( crate ) driver_info : Option < DriverInfo > ,
3837
3938 /// Processes all events generated by the pool.
4039 #[ derivative( Debug = "ignore" , PartialEq = "ignore" ) ]
4140 #[ serde( skip) ]
42- pub event_handler : Option < Arc < dyn CmapEventHandler > > ,
41+ pub ( crate ) event_handler : Option < Arc < dyn CmapEventHandler > > ,
4342
4443 /// How often the background thread performs its maintenance (e.g. ensure minPoolSize).
4544 #[ cfg( test) ]
4645 #[ serde( skip) ]
47- pub maintenance_frequency : Option < Duration > ,
46+ pub ( crate ) maintenance_frequency : Option < Duration > ,
4847
4948 /// Connections that have been ready for usage in the pool for longer than `max_idle_time` will
5049 /// not be used.
@@ -53,20 +52,20 @@ pub struct ConnectionPoolOptions {
5352 #[ serde( rename = "maxIdleTimeMS" ) ]
5453 #[ serde( default ) ]
5554 #[ serde( deserialize_with = "bson_util::deserialize_duration_from_u64_millis" ) ]
56- pub max_idle_time : Option < Duration > ,
55+ pub ( crate ) max_idle_time : Option < Duration > ,
5756
5857 /// The maximum number of connections that the pool can have at a given time. This includes
5958 /// connections which are currently checked out of the pool.
6059 ///
6160 /// The default is 100.
62- pub max_pool_size : Option < u32 > ,
61+ pub ( crate ) max_pool_size : Option < u32 > ,
6362
6463 /// The minimum number of connections that the pool can have at a given time. This includes
6564 /// connections which are currently checked out of the pool. If fewer than `min_pool_size`
6665 /// connections are in the pool, connections will be added to the pool in the background.
6766 ///
6867 /// The default is that no minimum is enforced
69- pub min_pool_size : Option < u32 > ,
68+ pub ( crate ) min_pool_size : Option < u32 > ,
7069
7170 /// Whether to start the pool as "ready" or not.
7271 /// For tests only.
@@ -85,7 +84,7 @@ pub struct ConnectionPoolOptions {
8584 ///
8685 /// The default is not to use TLS for connections.
8786 #[ serde( skip) ]
88- pub tls_options : Option < TlsOptions > ,
87+ pub ( crate ) tls_options : Option < TlsOptions > ,
8988
9089 /// Rather than wait indefinitely for a connection to become available, instead return an error
9190 /// after the given duration.
@@ -94,23 +93,42 @@ pub struct ConnectionPoolOptions {
9493 #[ serde( rename = "waitQueueTimeoutMS" ) ]
9594 #[ serde( default ) ]
9695 #[ serde( deserialize_with = "bson_util::deserialize_duration_from_u64_millis" ) ]
97- pub wait_queue_timeout : Option < Duration > ,
96+ pub ( crate ) wait_queue_timeout : Option < Duration > ,
9897}
9998
10099impl ConnectionPoolOptions {
101100 pub ( crate ) fn from_client_options ( options : & ClientOptions ) -> Self {
102- let mut pool_options = Self :: builder ( ) . build ( ) ;
103- pool_options. app_name = options. app_name . clone ( ) ;
104- pool_options. connect_timeout = options. connect_timeout ;
105- pool_options. credential = options. credential . clone ( ) ;
106- pool_options. driver_info = options. driver_info . clone ( ) ;
107- pool_options. event_handler = options. cmap_event_handler . clone ( ) ;
108- pool_options. max_idle_time = options. max_idle_time ;
109- pool_options. min_pool_size = options. min_pool_size ;
110- pool_options. tls_options = options. tls_options ( ) ;
111- pool_options. wait_queue_timeout = options. wait_queue_timeout ;
112-
113- pool_options
101+ Self {
102+ app_name : options. app_name . clone ( ) ,
103+ connect_timeout : options. connect_timeout ,
104+ driver_info : options. driver_info . clone ( ) ,
105+ max_idle_time : options. max_idle_time ,
106+ min_pool_size : options. min_pool_size ,
107+ max_pool_size : options. max_pool_size ,
108+ server_api : options. server_api . clone ( ) ,
109+ tls_options : options. tls_options ( ) ,
110+ wait_queue_timeout : options. wait_queue_timeout ,
111+ credential : options. credential . clone ( ) ,
112+ event_handler : options. cmap_event_handler . clone ( ) ,
113+ #[ cfg( test) ]
114+ maintenance_frequency : None ,
115+ #[ cfg( test) ]
116+ ready : None ,
117+ }
118+ }
119+
120+ pub ( crate ) fn to_event_options ( & self ) -> EventOptions {
121+ EventOptions {
122+ app_name : self . app_name . clone ( ) ,
123+ connect_timeout : self . connect_timeout ,
124+ driver_info : self . driver_info . clone ( ) ,
125+ max_idle_time : self . max_idle_time ,
126+ min_pool_size : self . min_pool_size ,
127+ max_pool_size : self . max_pool_size ,
128+ server_api : self . server_api . clone ( ) ,
129+ tls_options : self . tls_options . clone ( ) ,
130+ wait_queue_timeout : self . wait_queue_timeout ,
131+ }
114132 }
115133}
116134
0 commit comments