Skip to content

Commit 2ed89c9

Browse files
authored
Deprecate Stream-related API (#1195)
* Deprecate Stream-related API Adds: * TransportSettings abstract class * NettyTransportSettings subclass of TransportSettings * A new method on MongoClientSettings to configure TransportSettings Deprecates: * MongoClientSettings.Builder#streamFactoryFactory * MongoClientSettings.getStreamFactoryFactory * NettyStreamFactoryFactory * NettyStreamFactory * AsynchronousSocketChannelStreamFactory * AsynchronousSocketChannelStreamFactoryFactory * BufferProvider * SocketStreamFactory * Stream * StreamFactory * StreamFactoryFactory * TlsChannelStreamFactoryFactory JAVA-5051
1 parent deed10b commit 2ed89c9

File tree

52 files changed

+732
-29
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+732
-29
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ configure(javaMainProjects) {
186186
options.encoding = 'ISO-8859-1'
187187
options.fork = true
188188
options.debug = true
189-
options.compilerArgs = ['-Xlint:all']
189+
options.compilerArgs = ['-Xlint:all', '-Xlint:-deprecation']
190190
}
191191
}
192192

driver-core/src/main/com/mongodb/MongoClientSettings.java

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.mongodb.connection.SocketSettings;
2828
import com.mongodb.connection.SslSettings;
2929
import com.mongodb.connection.StreamFactoryFactory;
30+
import com.mongodb.connection.TransportSettings;
3031
import com.mongodb.event.CommandListener;
3132
import com.mongodb.lang.Nullable;
3233
import com.mongodb.spi.dns.DnsClient;
@@ -62,6 +63,7 @@
6263
*
6364
* @since 3.7
6465
*/
66+
@SuppressWarnings("deprecation")
6567
@Immutable
6668
public final class MongoClientSettings {
6769
private static final CodecRegistry DEFAULT_CODEC_REGISTRY =
@@ -89,6 +91,7 @@ public final class MongoClientSettings {
8991
private final boolean retryReads;
9092
private final ReadConcern readConcern;
9193
private final MongoCredential credential;
94+
private final TransportSettings transportSettings;
9295
private final StreamFactoryFactory streamFactoryFactory;
9396
private final List<CommandListener> commandListeners;
9497
private final CodecRegistry codecRegistry;
@@ -209,6 +212,7 @@ public static final class Builder {
209212
private boolean retryReads = true;
210213
private ReadConcern readConcern = ReadConcern.DEFAULT;
211214
private CodecRegistry codecRegistry = MongoClientSettings.getDefaultCodecRegistry();
215+
private TransportSettings transportSettings;
212216
private StreamFactoryFactory streamFactoryFactory;
213217
private List<CommandListener> commandListeners = new ArrayList<>();
214218

@@ -252,6 +256,7 @@ private Builder(final MongoClientSettings settings) {
252256
serverApi = settings.getServerApi();
253257
dnsClient = settings.getDnsClient();
254258
inetAddressResolver = settings.getInetAddressResolver();
259+
transportSettings = settings.getTransportSettings();
255260
streamFactoryFactory = settings.getStreamFactoryFactory();
256261
autoEncryptionSettings = settings.getAutoEncryptionSettings();
257262
contextProvider = settings.getContextProvider();
@@ -490,12 +495,30 @@ public Builder codecRegistry(final CodecRegistry codecRegistry) {
490495
* @param streamFactoryFactory the stream factory factory
491496
* @return this
492497
* @see #getStreamFactoryFactory()
498+
* @deprecated Prefer {@link #transportSettings(TransportSettings)}
493499
*/
500+
@Deprecated
494501
public Builder streamFactoryFactory(final StreamFactoryFactory streamFactoryFactory) {
495502
this.streamFactoryFactory = notNull("streamFactoryFactory", streamFactoryFactory);
496503
return this;
497504
}
498505

506+
/**
507+
* Sets the {@link TransportSettings} to apply.
508+
*
509+
* <p>
510+
* If transport settings are applied, application of {@link #streamFactoryFactory} is ignored.
511+
* </p>
512+
*
513+
* @param transportSettings the transport settings
514+
* @return this
515+
* @see #getTransportSettings()
516+
*/
517+
public Builder transportSettings(final TransportSettings transportSettings) {
518+
this.transportSettings = notNull("transportSettings", transportSettings);
519+
return this;
520+
}
521+
499522
/**
500523
* Adds the given command listener.
501524
*
@@ -771,12 +794,27 @@ public CodecRegistry getCodecRegistry() {
771794
*
772795
* @return the stream factory factory
773796
* @see Builder#streamFactoryFactory(StreamFactoryFactory)
797+
* @deprecated Prefer {@link #getTransportSettings()}
774798
*/
799+
@Deprecated
775800
@Nullable
776801
public StreamFactoryFactory getStreamFactoryFactory() {
777802
return streamFactoryFactory;
778803
}
779804

805+
/**
806+
* Gets the settings for the underlying transport implementation
807+
*
808+
* @return the settings for the underlying transport implementation
809+
*
810+
* @since 4.11
811+
* @see Builder#transportSettings(TransportSettings)
812+
*/
813+
@Nullable
814+
public TransportSettings getTransportSettings() {
815+
return transportSettings;
816+
}
817+
780818
/**
781819
* Gets the list of added {@code CommandListener}.
782820
*
@@ -978,6 +1016,7 @@ public boolean equals(final Object o) {
9781016
&& Objects.equals(writeConcern, that.writeConcern)
9791017
&& Objects.equals(readConcern, that.readConcern)
9801018
&& Objects.equals(credential, that.credential)
1019+
&& Objects.equals(transportSettings, that.transportSettings)
9811020
&& Objects.equals(streamFactoryFactory, that.streamFactoryFactory)
9821021
&& Objects.equals(commandListeners, that.commandListeners)
9831022
&& Objects.equals(codecRegistry, that.codecRegistry)
@@ -1000,11 +1039,11 @@ public boolean equals(final Object o) {
10001039

10011040
@Override
10021041
public int hashCode() {
1003-
return Objects.hash(readPreference, writeConcern, retryWrites, retryReads, readConcern, credential, streamFactoryFactory,
1004-
commandListeners, codecRegistry, loggerSettings, clusterSettings, socketSettings, heartbeatSocketSettings,
1005-
connectionPoolSettings, serverSettings, sslSettings, applicationName, compressorList, uuidRepresentation, serverApi,
1006-
autoEncryptionSettings, heartbeatSocketTimeoutSetExplicitly, heartbeatConnectTimeoutSetExplicitly, dnsClient,
1007-
inetAddressResolver, contextProvider);
1042+
return Objects.hash(readPreference, writeConcern, retryWrites, retryReads, readConcern, credential, transportSettings,
1043+
streamFactoryFactory, commandListeners, codecRegistry, loggerSettings, clusterSettings, socketSettings,
1044+
heartbeatSocketSettings, connectionPoolSettings, serverSettings, sslSettings, applicationName, compressorList,
1045+
uuidRepresentation, serverApi, autoEncryptionSettings, heartbeatSocketTimeoutSetExplicitly,
1046+
heartbeatConnectTimeoutSetExplicitly, dnsClient, inetAddressResolver, contextProvider);
10081047
}
10091048

10101049
@Override
@@ -1016,6 +1055,7 @@ public String toString() {
10161055
+ ", retryReads=" + retryReads
10171056
+ ", readConcern=" + readConcern
10181057
+ ", credential=" + credential
1058+
+ ", transportSettings=" + transportSettings
10191059
+ ", streamFactoryFactory=" + streamFactoryFactory
10201060
+ ", commandListeners=" + commandListeners
10211061
+ ", codecRegistry=" + codecRegistry
@@ -1044,6 +1084,7 @@ private MongoClientSettings(final Builder builder) {
10441084
retryReads = builder.retryReads;
10451085
readConcern = builder.readConcern;
10461086
credential = builder.credential;
1087+
transportSettings = builder.transportSettings;
10471088
streamFactoryFactory = builder.streamFactoryFactory;
10481089
codecRegistry = builder.codecRegistry;
10491090
commandListeners = builder.commandListeners;

driver-core/src/main/com/mongodb/annotations/Evolving.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package com.mongodb.annotations;
2020

21-
import com.mongodb.connection.StreamFactoryFactory;
21+
import org.bson.codecs.Codec;
2222
import org.bson.conversions.Bson;
2323

2424
import java.lang.annotation.Documented;
@@ -52,7 +52,7 @@
5252
* </tr>
5353
* <tr>
5454
* <td>Doing so allows customizing API behavior.</td>
55-
* <td>{@link StreamFactoryFactory}</td>
55+
* <td>{@link Codec}</td>
5656
* <td>Not applicable.</td>
5757
* </tr>
5858
* <tr>

driver-core/src/main/com/mongodb/connection/AsynchronousSocketChannelStreamFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
* Factory to create a Stream that's an AsynchronousSocketChannelStream. Throws an exception if SSL is enabled.
3030
*
3131
* @since 3.0
32+
* @deprecated There is no replacement for this class.
3233
*/
34+
@Deprecated
3335
public class AsynchronousSocketChannelStreamFactory implements StreamFactory {
3436
private final PowerOfTwoBufferPool bufferProvider = PowerOfTwoBufferPool.DEFAULT;
3537
private final SocketSettings settings;

driver-core/src/main/com/mongodb/connection/AsynchronousSocketChannelStreamFactoryFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
*
2424
* @see java.nio.channels.AsynchronousSocketChannel
2525
* @since 3.1
26+
* @deprecated There is no replacement for this class.
2627
*/
28+
@Deprecated
2729
public final class AsynchronousSocketChannelStreamFactoryFactory implements StreamFactoryFactory {
2830
private final AsynchronousChannelGroup group;
2931

driver-core/src/main/com/mongodb/connection/BufferProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
* A provider of instances of ByteBuf.
2424
*
2525
* @since 3.0
26+
* @deprecated There is no replacement for this interface.
2627
*/
28+
@Deprecated
2729
@ThreadSafe
2830
public interface BufferProvider {
2931
/**

0 commit comments

Comments
 (0)