|
15 | 15 | */ |
16 | 16 | package org.springframework.data.mongodb.core; |
17 | 17 |
|
18 | | -import java.lang.reflect.Method; |
19 | 18 | import java.security.NoSuchAlgorithmException; |
20 | 19 | import java.util.Arrays; |
21 | 20 | import java.util.Collections; |
|
24 | 23 |
|
25 | 24 | import javax.net.ssl.SSLContext; |
26 | 25 |
|
27 | | -import org.apache.commons.logging.Log; |
28 | | -import org.apache.commons.logging.LogFactory; |
29 | 26 | import org.bson.UuidRepresentation; |
30 | 27 | import org.bson.codecs.configuration.CodecRegistry; |
| 28 | + |
31 | 29 | import org.springframework.beans.factory.config.AbstractFactoryBean; |
32 | | -import org.springframework.data.mongodb.MongoCompatibilityAdapter; |
33 | | -import org.springframework.data.mongodb.util.MongoClientVersion; |
| 30 | +import org.springframework.data.mongodb.util.MongoCompatibilityAdapter; |
34 | 31 | import org.springframework.lang.Nullable; |
35 | | -import org.springframework.util.ClassUtils; |
36 | 32 | import org.springframework.util.CollectionUtils; |
37 | | -import org.springframework.util.ReflectionUtils; |
38 | 33 | import org.springframework.util.StringUtils; |
39 | 34 |
|
40 | 35 | import com.mongodb.AutoEncryptionSettings; |
@@ -62,7 +57,8 @@ public class MongoClientSettingsFactoryBean extends AbstractFactoryBean<MongoCli |
62 | 57 |
|
63 | 58 | private CodecRegistry codecRegistry = DEFAULT_MONGO_SETTINGS.getCodecRegistry(); |
64 | 59 |
|
65 | | - @Nullable private Object streamFactoryFactory; |
| 60 | + @Nullable private Object streamFactoryFactory = MongoCompatibilityAdapter |
| 61 | + .clientSettingsAdapter(DEFAULT_MONGO_SETTINGS).getStreamFactoryFactory(); |
66 | 62 | @Nullable private TransportSettings transportSettings; |
67 | 63 |
|
68 | 64 | private ReadPreference readPreference = DEFAULT_MONGO_SETTINGS.getReadPreference(); |
@@ -125,21 +121,17 @@ public class MongoClientSettingsFactoryBean extends AbstractFactoryBean<MongoCli |
125 | 121 | private @Nullable AutoEncryptionSettings autoEncryptionSettings; |
126 | 122 | private @Nullable ServerApi serverApi; |
127 | 123 |
|
128 | | - { |
129 | | - streamFactoryFactory = MongoCompatibilityAdapter.clientSettingsAdapter(DEFAULT_MONGO_SETTINGS).getStreamFactoryFactory(); |
130 | | - } |
131 | | - |
132 | 124 | /** |
133 | 125 | * @param socketConnectTimeoutMS in msec |
134 | | - * @see com.mongodb.connection.SocketSettings.Builder#connectTimeout(int, TimeUnit) |
| 126 | + * @see com.mongodb.connection.SocketSettings.Builder#connectTimeout(long, TimeUnit) |
135 | 127 | */ |
136 | 128 | public void setSocketConnectTimeoutMS(int socketConnectTimeoutMS) { |
137 | 129 | this.socketConnectTimeoutMS = socketConnectTimeoutMS; |
138 | 130 | } |
139 | 131 |
|
140 | 132 | /** |
141 | 133 | * @param socketReadTimeoutMS in msec |
142 | | - * @see com.mongodb.connection.SocketSettings.Builder#readTimeout(int, TimeUnit) |
| 134 | + * @see com.mongodb.connection.SocketSettings.Builder#readTimeout(long, TimeUnit) |
143 | 135 | */ |
144 | 136 | public void setSocketReadTimeoutMS(int socketReadTimeoutMS) { |
145 | 137 | this.socketReadTimeoutMS = socketReadTimeoutMS; |
@@ -380,8 +372,11 @@ public void setReadPreference(ReadPreference readPreference) { |
380 | 372 | } |
381 | 373 |
|
382 | 374 | /** |
383 | | - * @param streamFactoryFactory // * @see MongoClientSettings.Builder#streamFactoryFactory(StreamFactoryFactory) |
| 375 | + * @param streamFactoryFactory |
| 376 | + * @deprecated since 4.3, will be removed in the MongoDB 5.0 driver in favor of |
| 377 | + * {@code com.mongodb.connection.TransportSettings}. |
384 | 378 | */ |
| 379 | + @Deprecated(since = "4.3") |
385 | 380 | public void setStreamFactoryFactory(Object streamFactoryFactory) { |
386 | 381 | this.streamFactoryFactory = streamFactoryFactory; |
387 | 382 | } |
@@ -449,7 +444,6 @@ protected MongoClientSettings createInstance() { |
449 | 444 | settings.hosts(clusterHosts); |
450 | 445 | } |
451 | 446 | settings.localThreshold(clusterLocalThresholdMS, TimeUnit.MILLISECONDS); |
452 | | - // settings.maxWaitQueueSize(clusterMaxWaitQueueSize); |
453 | 447 | settings.requiredClusterType(custerRequiredClusterType); |
454 | 448 |
|
455 | 449 | if (StringUtils.hasText(clusterSrvHost)) { |
@@ -518,59 +512,4 @@ protected MongoClientSettings createInstance() { |
518 | 512 |
|
519 | 513 | return builder.build(); |
520 | 514 | } |
521 | | - |
522 | | - static class MongoStreamFactoryFactorySettingsConfigurer { |
523 | | - |
524 | | - private static final Log logger = LogFactory.getLog(MongoClientSettingsFactoryBean.class); |
525 | | - |
526 | | - private static final String STREAM_FACTORY_NAME = "com.mongodb.connection.StreamFactoryFactory"; |
527 | | - private static final boolean STREAM_FACTORY_PRESENT = ClassUtils.isPresent(STREAM_FACTORY_NAME, |
528 | | - MongoStreamFactoryFactorySettingsConfigurer.class.getClassLoader()); |
529 | | - private final MongoClientSettings.Builder settingsBuilder; |
530 | | - |
531 | | - static boolean isStreamFactoryPresent() { |
532 | | - return STREAM_FACTORY_PRESENT; |
533 | | - } |
534 | | - |
535 | | - static Object getDefaultStreamFactoryFactory() { |
536 | | - |
537 | | - if (MongoClientVersion.is5PlusClient()) { |
538 | | - return null; |
539 | | - } |
540 | | - |
541 | | - Method getStreamFactoryFactory = ReflectionUtils.findMethod(MongoClientSettings.class, "getStreamFactoryFactory"); |
542 | | - return getStreamFactoryFactory != null |
543 | | - ? ReflectionUtils.invokeMethod(getStreamFactoryFactory, DEFAULT_MONGO_SETTINGS) |
544 | | - : null; |
545 | | - } |
546 | | - |
547 | | - public MongoStreamFactoryFactorySettingsConfigurer(Builder settingsBuilder) { |
548 | | - this.settingsBuilder = settingsBuilder; |
549 | | - } |
550 | | - |
551 | | - void setStreamFactory(Object streamFactory) { |
552 | | - |
553 | | - if (MongoClientVersion.is5PlusClient()) { |
554 | | - logger.warn("StreamFactoryFactory is no longer available. Use TransportSettings instead."); |
555 | | - } |
556 | | - |
557 | | - if (isStreamFactoryPresent()) { // |
558 | | - try { |
559 | | - Class<?> streamFactoryType = ClassUtils.forName(STREAM_FACTORY_NAME, |
560 | | - streamFactory.getClass().getClassLoader()); |
561 | | - if (!ClassUtils.isAssignable(streamFactoryType, streamFactory.getClass())) { |
562 | | - throw new IllegalArgumentException("Expected %s but found %s".formatted(streamFactoryType, streamFactory)); |
563 | | - } |
564 | | - |
565 | | - Method setter = ReflectionUtils.findMethod(settingsBuilder.getClass(), "streamFactoryFactory", |
566 | | - streamFactoryType); |
567 | | - if (setter != null) { |
568 | | - ReflectionUtils.invokeMethod(setter, settingsBuilder, streamFactoryType.cast(streamFactory)); |
569 | | - } |
570 | | - } catch (ClassNotFoundException e) { |
571 | | - throw new IllegalArgumentException("Cannot set StreamFactoryFactory for %s".formatted(settingsBuilder), e); |
572 | | - } |
573 | | - } |
574 | | - } |
575 | | - } |
576 | 515 | } |
0 commit comments