39
39
40
40
import org .springframework .beans .factory .ObjectProvider ;
41
41
import org .springframework .boot .autoconfigure .EnableAutoConfiguration ;
42
+ import org .springframework .boot .autoconfigure .cassandra .CassandraProperties .Connection ;
43
+ import org .springframework .boot .autoconfigure .cassandra .CassandraProperties .Request ;
42
44
import org .springframework .boot .autoconfigure .cassandra .CassandraProperties .Throttler ;
43
45
import org .springframework .boot .autoconfigure .cassandra .CassandraProperties .ThrottlerType ;
44
46
import org .springframework .boot .autoconfigure .condition .ConditionalOnClass ;
@@ -115,10 +117,9 @@ private Config cassandraConfiguration(CassandraProperties properties) {
115
117
.add (DefaultDriverOption .AUTH_PROVIDER_PASSWORD , properties .getPassword ()));
116
118
map .from (properties ::getCompression ).whenNonNull ()
117
119
.to ((compression ) -> options .add (DefaultDriverOption .PROTOCOL_COMPRESSION , compression ));
118
- mapQueryOptions (properties , options );
119
- mapSocketOptions (properties , options );
120
+ mapConnectionOptions (properties , options );
120
121
mapPoolingOptions (properties , options );
121
- mapThrottlingOptions (properties , options );
122
+ mapRequestOptions (properties , options );
122
123
map .from (mapContactPoints (properties ))
123
124
.to ((contactPoints ) -> options .add (DefaultDriverOption .CONTACT_POINTS , contactPoints ));
124
125
map .from (properties .getLocalDatacenter ()).to (
@@ -128,22 +129,13 @@ private Config cassandraConfiguration(CassandraProperties properties) {
128
129
.withFallback (ConfigFactory .defaultReference ()).resolve ();
129
130
}
130
131
131
- private void mapQueryOptions (CassandraProperties properties , CassandraDriverOptions options ) {
132
- PropertyMapper map = PropertyMapper .get ();
133
- map .from (properties ::getConsistencyLevel ).whenNonNull ()
134
- .to (((consistency ) -> options .add (DefaultDriverOption .REQUEST_CONSISTENCY , consistency )));
135
- map .from (properties ::getSerialConsistencyLevel ).whenNonNull ().to (
136
- (serialConsistency ) -> options .add (DefaultDriverOption .REQUEST_SERIAL_CONSISTENCY , serialConsistency ));
137
- map .from (properties ::getPageSize )
138
- .to ((pageSize ) -> options .add (DefaultDriverOption .REQUEST_PAGE_SIZE , pageSize ));
139
- }
140
-
141
- private void mapSocketOptions (CassandraProperties properties , CassandraDriverOptions options ) {
142
- PropertyMapper map = PropertyMapper .get ();
143
- map .from (properties ::getConnectTimeout ).whenNonNull ().asInt (Duration ::toMillis )
144
- .to ((connectTimeout ) -> options .add (DefaultDriverOption .CONNECTION_INIT_QUERY_TIMEOUT , connectTimeout ));
145
- map .from (properties ::getReadTimeout ).whenNonNull ().asInt (Duration ::toMillis )
146
- .to ((readTimeout ) -> options .add (DefaultDriverOption .REQUEST_TIMEOUT , readTimeout ));
132
+ private void mapConnectionOptions (CassandraProperties properties , CassandraDriverOptions options ) {
133
+ PropertyMapper map = PropertyMapper .get ().alwaysApplyingWhenNonNull ();
134
+ Connection connectionProperties = properties .getConnection ();
135
+ map .from (connectionProperties ::getConnectTimeout ).asInt (Duration ::toMillis )
136
+ .to ((connectTimeout ) -> options .add (DefaultDriverOption .CONNECTION_CONNECT_TIMEOUT , connectTimeout ));
137
+ map .from (connectionProperties ::getInitQueryTimeout ).asInt (Duration ::toMillis ).to (
138
+ (initQueryTimeout ) -> options .add (DefaultDriverOption .CONNECTION_INIT_QUERY_TIMEOUT , initQueryTimeout ));
147
139
}
148
140
149
141
private void mapPoolingOptions (CassandraProperties properties , CassandraDriverOptions options ) {
@@ -155,9 +147,18 @@ private void mapPoolingOptions(CassandraProperties properties, CassandraDriverOp
155
147
.to ((heartBeatInterval ) -> options .add (DefaultDriverOption .HEARTBEAT_INTERVAL , heartBeatInterval ));
156
148
}
157
149
158
- private void mapThrottlingOptions (CassandraProperties properties , CassandraDriverOptions options ) {
150
+ private void mapRequestOptions (CassandraProperties properties , CassandraDriverOptions options ) {
159
151
PropertyMapper map = PropertyMapper .get ().alwaysApplyingWhenNonNull ();
160
- Throttler throttlerProperties = properties .getThrottler ();
152
+ Request requestProperties = properties .getRequest ();
153
+ map .from (requestProperties ::getTimeout ).asInt (Duration ::toMillis )
154
+ .to (((timeout ) -> options .add (DefaultDriverOption .REQUEST_TIMEOUT , timeout )));
155
+ map .from (requestProperties ::getConsistency )
156
+ .to (((consistency ) -> options .add (DefaultDriverOption .REQUEST_CONSISTENCY , consistency )));
157
+ map .from (requestProperties ::getSerialConsistency ).to (
158
+ (serialConsistency ) -> options .add (DefaultDriverOption .REQUEST_SERIAL_CONSISTENCY , serialConsistency ));
159
+ map .from (requestProperties ::getPageSize )
160
+ .to ((pageSize ) -> options .add (DefaultDriverOption .REQUEST_PAGE_SIZE , pageSize ));
161
+ Throttler throttlerProperties = requestProperties .getThrottler ();
161
162
map .from (throttlerProperties ::getType ).as (ThrottlerType ::type )
162
163
.to ((type ) -> options .add (DefaultDriverOption .REQUEST_THROTTLER_CLASS , type ));
163
164
map .from (throttlerProperties ::getMaxQueueSize )
@@ -168,7 +169,6 @@ private void mapThrottlingOptions(CassandraProperties properties, CassandraDrive
168
169
.add (DefaultDriverOption .REQUEST_THROTTLER_MAX_REQUESTS_PER_SECOND , maxRequestsPerSecond ));
169
170
map .from (throttlerProperties ::getDrainInterval ).asInt (Duration ::toMillis ).to (
170
171
(drainInterval ) -> options .add (DefaultDriverOption .REQUEST_THROTTLER_DRAIN_INTERVAL , drainInterval ));
171
-
172
172
}
173
173
174
174
private List <String > mapContactPoints (CassandraProperties properties ) {
0 commit comments