Skip to content

Deprecate Stream-related API #1195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ configure(javaMainProjects) {
options.encoding = 'ISO-8859-1'
options.fork = true
options.debug = true
options.compilerArgs = ['-Xlint:all']
options.compilerArgs = ['-Xlint:all', '-Xlint:-deprecation']
}
}

Expand Down
51 changes: 46 additions & 5 deletions driver-core/src/main/com/mongodb/MongoClientSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.mongodb.connection.SocketSettings;
import com.mongodb.connection.SslSettings;
import com.mongodb.connection.StreamFactoryFactory;
import com.mongodb.connection.TransportSettings;
import com.mongodb.event.CommandListener;
import com.mongodb.lang.Nullable;
import com.mongodb.spi.dns.DnsClient;
Expand Down Expand Up @@ -62,6 +63,7 @@
*
* @since 3.7
*/
@SuppressWarnings("deprecation")
@Immutable
public final class MongoClientSettings {
private static final CodecRegistry DEFAULT_CODEC_REGISTRY =
Expand Down Expand Up @@ -89,6 +91,7 @@ public final class MongoClientSettings {
private final boolean retryReads;
private final ReadConcern readConcern;
private final MongoCredential credential;
private final TransportSettings transportSettings;
private final StreamFactoryFactory streamFactoryFactory;
private final List<CommandListener> commandListeners;
private final CodecRegistry codecRegistry;
Expand Down Expand Up @@ -209,6 +212,7 @@ public static final class Builder {
private boolean retryReads = true;
private ReadConcern readConcern = ReadConcern.DEFAULT;
private CodecRegistry codecRegistry = MongoClientSettings.getDefaultCodecRegistry();
private TransportSettings transportSettings;
private StreamFactoryFactory streamFactoryFactory;
private List<CommandListener> commandListeners = new ArrayList<>();

Expand Down Expand Up @@ -252,6 +256,7 @@ private Builder(final MongoClientSettings settings) {
serverApi = settings.getServerApi();
dnsClient = settings.getDnsClient();
inetAddressResolver = settings.getInetAddressResolver();
transportSettings = settings.getTransportSettings();
streamFactoryFactory = settings.getStreamFactoryFactory();
autoEncryptionSettings = settings.getAutoEncryptionSettings();
contextProvider = settings.getContextProvider();
Expand Down Expand Up @@ -490,12 +495,30 @@ public Builder codecRegistry(final CodecRegistry codecRegistry) {
* @param streamFactoryFactory the stream factory factory
* @return this
* @see #getStreamFactoryFactory()
* @deprecated Prefer {@link #transportSettings(TransportSettings)}
*/
@Deprecated
public Builder streamFactoryFactory(final StreamFactoryFactory streamFactoryFactory) {
this.streamFactoryFactory = notNull("streamFactoryFactory", streamFactoryFactory);
return this;
}

/**
* Sets the {@link TransportSettings} to apply.
*
* <p>
* If transport settings are applied, application of {@link #streamFactoryFactory} is ignored.
* </p>
*
* @param transportSettings the transport settings
* @return this
* @see #getTransportSettings()
*/
public Builder transportSettings(final TransportSettings transportSettings) {
this.transportSettings = notNull("transportSettings", transportSettings);
return this;
}

/**
* Adds the given command listener.
*
Expand Down Expand Up @@ -771,12 +794,27 @@ public CodecRegistry getCodecRegistry() {
*
* @return the stream factory factory
* @see Builder#streamFactoryFactory(StreamFactoryFactory)
* @deprecated Prefer {@link #getTransportSettings()}
*/
@Deprecated
@Nullable
public StreamFactoryFactory getStreamFactoryFactory() {
return streamFactoryFactory;
}

/**
* Gets the settings for the underlying transport implementation
*
* @return the settings for the underlying transport implementation
*
* @since 4.11
* @see Builder#transportSettings(TransportSettings)
*/
@Nullable
public TransportSettings getTransportSettings() {
return transportSettings;
}

/**
* Gets the list of added {@code CommandListener}.
*
Expand Down Expand Up @@ -978,6 +1016,7 @@ public boolean equals(final Object o) {
&& Objects.equals(writeConcern, that.writeConcern)
&& Objects.equals(readConcern, that.readConcern)
&& Objects.equals(credential, that.credential)
&& Objects.equals(transportSettings, that.transportSettings)
&& Objects.equals(streamFactoryFactory, that.streamFactoryFactory)
&& Objects.equals(commandListeners, that.commandListeners)
&& Objects.equals(codecRegistry, that.codecRegistry)
Expand All @@ -1000,11 +1039,11 @@ public boolean equals(final Object o) {

@Override
public int hashCode() {
return Objects.hash(readPreference, writeConcern, retryWrites, retryReads, readConcern, credential, streamFactoryFactory,
commandListeners, codecRegistry, loggerSettings, clusterSettings, socketSettings, heartbeatSocketSettings,
connectionPoolSettings, serverSettings, sslSettings, applicationName, compressorList, uuidRepresentation, serverApi,
autoEncryptionSettings, heartbeatSocketTimeoutSetExplicitly, heartbeatConnectTimeoutSetExplicitly, dnsClient,
inetAddressResolver, contextProvider);
return Objects.hash(readPreference, writeConcern, retryWrites, retryReads, readConcern, credential, transportSettings,
streamFactoryFactory, commandListeners, codecRegistry, loggerSettings, clusterSettings, socketSettings,
heartbeatSocketSettings, connectionPoolSettings, serverSettings, sslSettings, applicationName, compressorList,
uuidRepresentation, serverApi, autoEncryptionSettings, heartbeatSocketTimeoutSetExplicitly,
heartbeatConnectTimeoutSetExplicitly, dnsClient, inetAddressResolver, contextProvider);
}

@Override
Expand All @@ -1016,6 +1055,7 @@ public String toString() {
+ ", retryReads=" + retryReads
+ ", readConcern=" + readConcern
+ ", credential=" + credential
+ ", transportSettings=" + transportSettings
+ ", streamFactoryFactory=" + streamFactoryFactory
+ ", commandListeners=" + commandListeners
+ ", codecRegistry=" + codecRegistry
Expand Down Expand Up @@ -1044,6 +1084,7 @@ private MongoClientSettings(final Builder builder) {
retryReads = builder.retryReads;
readConcern = builder.readConcern;
credential = builder.credential;
transportSettings = builder.transportSettings;
streamFactoryFactory = builder.streamFactoryFactory;
codecRegistry = builder.codecRegistry;
commandListeners = builder.commandListeners;
Expand Down
4 changes: 2 additions & 2 deletions driver-core/src/main/com/mongodb/annotations/Evolving.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package com.mongodb.annotations;

import com.mongodb.connection.StreamFactoryFactory;
import org.bson.codecs.Codec;
import org.bson.conversions.Bson;

import java.lang.annotation.Documented;
Expand Down Expand Up @@ -52,7 +52,7 @@
* </tr>
* <tr>
* <td>Doing so allows customizing API behavior.</td>
* <td>{@link StreamFactoryFactory}</td>
* <td>{@link Codec}</td>
* <td>Not applicable.</td>
* </tr>
* <tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
* Factory to create a Stream that's an AsynchronousSocketChannelStream. Throws an exception if SSL is enabled.
*
* @since 3.0
* @deprecated There is no replacement for this class.
*/
@Deprecated
public class AsynchronousSocketChannelStreamFactory implements StreamFactory {
private final PowerOfTwoBufferPool bufferProvider = PowerOfTwoBufferPool.DEFAULT;
private final SocketSettings settings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
*
* @see java.nio.channels.AsynchronousSocketChannel
* @since 3.1
* @deprecated There is no replacement for this class.
*/
@Deprecated
public final class AsynchronousSocketChannelStreamFactoryFactory implements StreamFactoryFactory {
private final AsynchronousChannelGroup group;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
* A provider of instances of ByteBuf.
*
* @since 3.0
* @deprecated There is no replacement for this interface.
*/
@Deprecated
@ThreadSafe
public interface BufferProvider {
/**
Expand Down
Loading