@@ -7,44 +7,43 @@ use typed_builder::TypedBuilder;
7
7
use crate :: {
8
8
bson_util,
9
9
client:: { auth:: Credential , options:: ServerApi } ,
10
- event:: cmap:: CmapEventHandler ,
10
+ event:: cmap:: { CmapEventHandler , ConnectionPoolOptions as EventOptions } ,
11
11
options:: { ClientOptions , DriverInfo , StreamAddress , TlsOptions } ,
12
12
} ;
13
13
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.
16
15
#[ derive( Clone , Default , Deserialize , TypedBuilder , Derivative ) ]
17
16
#[ derivative( Debug , PartialEq ) ]
18
17
#[ builder( field_defaults( default , setter( strip_option) ) ) ]
19
18
#[ serde( rename_all = "camelCase" ) ]
20
- pub struct ConnectionPoolOptions {
19
+ pub ( crate ) struct ConnectionPoolOptions {
21
20
/// The application name specified by the user. This is sent to the server as part of the
22
21
/// handshake that each connection makes when it's created.
23
- pub app_name : Option < String > ,
22
+ pub ( crate ) app_name : Option < String > ,
24
23
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
26
25
/// server.
27
26
#[ serde( skip) ]
28
- pub connect_timeout : Option < Duration > ,
27
+ pub ( crate ) connect_timeout : Option < Duration > ,
29
28
30
29
/// The credential to use for authenticating connections in this pool.
31
30
#[ serde( skip) ]
32
- pub credential : Option < Credential > ,
31
+ pub ( crate ) credential : Option < Credential > ,
33
32
34
33
/// Extra information to append to the driver version in the metadata of the handshake with the
35
34
/// server. This should be used by libraries wrapping the driver, e.g. ODMs.
36
35
#[ serde( skip) ]
37
- pub driver_info : Option < DriverInfo > ,
36
+ pub ( crate ) driver_info : Option < DriverInfo > ,
38
37
39
38
/// Processes all events generated by the pool.
40
39
#[ derivative( Debug = "ignore" , PartialEq = "ignore" ) ]
41
40
#[ serde( skip) ]
42
- pub event_handler : Option < Arc < dyn CmapEventHandler > > ,
41
+ pub ( crate ) event_handler : Option < Arc < dyn CmapEventHandler > > ,
43
42
44
43
/// How often the background thread performs its maintenance (e.g. ensure minPoolSize).
45
44
#[ cfg( test) ]
46
45
#[ serde( skip) ]
47
- pub maintenance_frequency : Option < Duration > ,
46
+ pub ( crate ) maintenance_frequency : Option < Duration > ,
48
47
49
48
/// Connections that have been ready for usage in the pool for longer than `max_idle_time` will
50
49
/// not be used.
@@ -53,20 +52,20 @@ pub struct ConnectionPoolOptions {
53
52
#[ serde( rename = "maxIdleTimeMS" ) ]
54
53
#[ serde( default ) ]
55
54
#[ 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 > ,
57
56
58
57
/// The maximum number of connections that the pool can have at a given time. This includes
59
58
/// connections which are currently checked out of the pool.
60
59
///
61
60
/// The default is 100.
62
- pub max_pool_size : Option < u32 > ,
61
+ pub ( crate ) max_pool_size : Option < u32 > ,
63
62
64
63
/// The minimum number of connections that the pool can have at a given time. This includes
65
64
/// connections which are currently checked out of the pool. If fewer than `min_pool_size`
66
65
/// connections are in the pool, connections will be added to the pool in the background.
67
66
///
68
67
/// The default is that no minimum is enforced
69
- pub min_pool_size : Option < u32 > ,
68
+ pub ( crate ) min_pool_size : Option < u32 > ,
70
69
71
70
/// Whether to start the pool as "ready" or not.
72
71
/// For tests only.
@@ -85,7 +84,7 @@ pub struct ConnectionPoolOptions {
85
84
///
86
85
/// The default is not to use TLS for connections.
87
86
#[ serde( skip) ]
88
- pub tls_options : Option < TlsOptions > ,
87
+ pub ( crate ) tls_options : Option < TlsOptions > ,
89
88
90
89
/// Rather than wait indefinitely for a connection to become available, instead return an error
91
90
/// after the given duration.
@@ -94,23 +93,42 @@ pub struct ConnectionPoolOptions {
94
93
#[ serde( rename = "waitQueueTimeoutMS" ) ]
95
94
#[ serde( default ) ]
96
95
#[ 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 > ,
98
97
}
99
98
100
99
impl ConnectionPoolOptions {
101
100
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
+ }
114
132
}
115
133
}
116
134
0 commit comments