导航菜单

页面标题

页面副标题

xDrip+ v04633772025.07.16 - MongoClientOptions.java 源代码

正在查看: xDrip+ v04633772025.07.16 应用的 MongoClientOptions.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.mongodb;

import androidx.health.platform.client.error.ErrorCode;
import com.mongodb.assertions.Assertions;
import com.mongodb.connection.ConnectionPoolSettings;
import com.mongodb.connection.ServerSettings;
import com.mongodb.connection.SocketSettings;
import com.mongodb.connection.SslSettings;
import com.mongodb.event.ClusterListener;
import com.mongodb.event.CommandListener;
import com.mongodb.event.ServerListener;
import com.mongodb.event.ServerMonitorListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.net.SocketFactory;
import javax.net.ssl.SSLSocketFactory;
import org.bson.codecs.configuration.CodecRegistry;

public class MongoClientOptions {
    private final boolean alwaysUseMBeans;
    private final List<ClusterListener> clusterListeners;
    private final CodecRegistry codecRegistry;
    private final List<CommandListener> commandListeners;
    private final int connectTimeout;
    private final ConnectionPoolSettings connectionPoolSettings;
    private final boolean cursorFinalizerEnabled;
    private final DBDecoderFactory dbDecoderFactory;
    private final DBEncoderFactory dbEncoderFactory;
    private final String description;
    private final int heartbeatConnectTimeout;
    private final int heartbeatFrequency;
    private final SocketSettings heartbeatSocketSettings;
    private final int heartbeatSocketTimeout;
    private final int localThreshold;
    private final int maxConnectionIdleTime;
    private final int maxConnectionLifeTime;
    private final int maxConnectionsPerHost;
    private final int maxWaitTime;
    private final int minConnectionsPerHost;
    private final int minHeartbeatFrequency;
    private final ReadConcern readConcern;
    private final ReadPreference readPreference;
    private final String requiredReplicaSetName;
    private final List<ServerListener> serverListeners;
    private final List<ServerMonitorListener> serverMonitorListeners;
    private final int serverSelectionTimeout;
    private final ServerSettings serverSettings;
    private final SocketFactory socketFactory;
    private final boolean socketKeepAlive;
    private final SocketSettings socketSettings;
    private final int socketTimeout;
    private final boolean sslEnabled;
    private final boolean sslInvalidHostNameAllowed;
    private final SslSettings sslSettings;
    private final int threadsAllowedToBlockForConnectionMultiplier;
    private final WriteConcern writeConcern;

    private MongoClientOptions(Builder builder) {
        this.description = builder.description;
        this.minConnectionsPerHost = builder.minConnectionsPerHost;
        this.maxConnectionsPerHost = builder.maxConnectionsPerHost;
        this.threadsAllowedToBlockForConnectionMultiplier = builder.threadsAllowedToBlockForConnectionMultiplier;
        this.serverSelectionTimeout = builder.serverSelectionTimeout;
        this.maxWaitTime = builder.maxWaitTime;
        this.maxConnectionIdleTime = builder.maxConnectionIdleTime;
        this.maxConnectionLifeTime = builder.maxConnectionLifeTime;
        this.connectTimeout = builder.connectTimeout;
        this.socketTimeout = builder.socketTimeout;
        this.socketKeepAlive = builder.socketKeepAlive;
        this.readPreference = builder.readPreference;
        this.writeConcern = builder.writeConcern;
        this.readConcern = builder.readConcern;
        this.codecRegistry = builder.codecRegistry;
        this.sslEnabled = builder.sslEnabled;
        this.sslInvalidHostNameAllowed = builder.sslInvalidHostNameAllowed;
        this.alwaysUseMBeans = builder.alwaysUseMBeans;
        this.heartbeatFrequency = builder.heartbeatFrequency;
        this.minHeartbeatFrequency = builder.minHeartbeatFrequency;
        this.heartbeatConnectTimeout = builder.heartbeatConnectTimeout;
        this.heartbeatSocketTimeout = builder.heartbeatSocketTimeout;
        this.localThreshold = builder.localThreshold;
        this.requiredReplicaSetName = builder.requiredReplicaSetName;
        this.dbDecoderFactory = builder.dbDecoderFactory;
        this.dbEncoderFactory = builder.dbEncoderFactory;
        this.socketFactory = builder.socketFactory;
        this.cursorFinalizerEnabled = builder.cursorFinalizerEnabled;
        this.commandListeners = builder.commandListeners;
        this.clusterListeners = builder.clusterListeners;
        List<ServerListener> list = builder.serverListeners;
        this.serverListeners = list;
        this.serverMonitorListeners = builder.serverMonitorListeners;
        ConnectionPoolSettings.Builder maxWaitQueueSize = ConnectionPoolSettings.builder().minSize(getMinConnectionsPerHost()).maxSize(getConnectionsPerHost()).maxWaitQueueSize(getThreadsAllowedToBlockForConnectionMultiplier() * getConnectionsPerHost());
        long maxWaitTime = getMaxWaitTime();
        TimeUnit timeUnit = TimeUnit.MILLISECONDS;
        this.connectionPoolSettings = maxWaitQueueSize.maxWaitTime(maxWaitTime, timeUnit).maxConnectionIdleTime(getMaxConnectionIdleTime(), timeUnit).maxConnectionLifeTime(getMaxConnectionLifeTime(), timeUnit).build();
        this.socketSettings = SocketSettings.builder().connectTimeout(getConnectTimeout(), timeUnit).readTimeout(getSocketTimeout(), timeUnit).keepAlive(isSocketKeepAlive()).build();
        this.heartbeatSocketSettings = SocketSettings.builder().connectTimeout(getHeartbeatConnectTimeout(), timeUnit).readTimeout(getHeartbeatSocketTimeout(), timeUnit).keepAlive(isSocketKeepAlive()).build();
        ServerSettings.Builder minHeartbeatFrequency = ServerSettings.builder().heartbeatFrequency(getHeartbeatFrequency(), timeUnit).minHeartbeatFrequency(getMinHeartbeatFrequency(), timeUnit);
        Iterator<ServerListener> it = list.iterator();
        while (it.hasNext()) {
            minHeartbeatFrequency.addServerListener(it.next());
        }
        Iterator<ServerMonitorListener> it2 = this.serverMonitorListeners.iterator();
        while (it2.hasNext()) {
            minHeartbeatFrequency.addServerMonitorListener(it2.next());
        }
        this.serverSettings = minHeartbeatFrequency.build();
        try {
            this.sslSettings = SslSettings.builder().enabled(this.sslEnabled).invalidHostNameAllowed(this.sslInvalidHostNameAllowed).build();
        } catch (MongoInternalException unused) {
            throw new MongoInternalException("By default, SSL connections are only supported on Java 7 or later.  If the application must run on Java 6, you must set the MongoClientOptions.sslInvalidHostNameAllowed property to false");
        }
    }

    public static Builder builder() {
        return new Builder();
    }

    public String getDescription() {
        return this.description;
    }

    public int getConnectionsPerHost() {
        return this.maxConnectionsPerHost;
    }

    public int getMinConnectionsPerHost() {
        return this.minConnectionsPerHost;
    }

    public int getThreadsAllowedToBlockForConnectionMultiplier() {
        return this.threadsAllowedToBlockForConnectionMultiplier;
    }

    public int getServerSelectionTimeout() {
        return this.serverSelectionTimeout;
    }

    public int getMaxWaitTime() {
        return this.maxWaitTime;
    }

    public int getMaxConnectionIdleTime() {
        return this.maxConnectionIdleTime;
    }

    public int getMaxConnectionLifeTime() {
        return this.maxConnectionLifeTime;
    }

    public int getConnectTimeout() {
        return this.connectTimeout;
    }

    public int getSocketTimeout() {
        return this.socketTimeout;
    }

    public boolean isSocketKeepAlive() {
        return this.socketKeepAlive;
    }

    public int getHeartbeatFrequency() {
        return this.heartbeatFrequency;
    }

    public int getMinHeartbeatFrequency() {
        return this.minHeartbeatFrequency;
    }

    public int getHeartbeatConnectTimeout() {
        return this.heartbeatConnectTimeout;
    }

    public int getHeartbeatSocketTimeout() {
        return this.heartbeatSocketTimeout;
    }

    public int getLocalThreshold() {
        return this.localThreshold;
    }

    public String getRequiredReplicaSetName() {
        return this.requiredReplicaSetName;
    }

    public ReadPreference getReadPreference() {
        return this.readPreference;
    }

    public WriteConcern getWriteConcern() {
        return this.writeConcern;
    }

    public ReadConcern getReadConcern() {
        return this.readConcern;
    }

    public List<CommandListener> getCommandListeners() {
        return Collections.unmodifiableList(this.commandListeners);
    }

    public List<ClusterListener> getClusterListeners() {
        return Collections.unmodifiableList(this.clusterListeners);
    }

    public DBDecoderFactory getDbDecoderFactory() {
        return this.dbDecoderFactory;
    }

    public DBEncoderFactory getDbEncoderFactory() {
        return this.dbEncoderFactory;
    }

    public SocketFactory getSocketFactory() {
        return this.socketFactory;
    }

    public boolean isCursorFinalizerEnabled() {
        return this.cursorFinalizerEnabled;
    }

    ConnectionPoolSettings getConnectionPoolSettings() {
        return this.connectionPoolSettings;
    }

    SocketSettings getSocketSettings() {
        return this.socketSettings;
    }

    ServerSettings getServerSettings() {
        return this.serverSettings;
    }

    SocketSettings getHeartbeatSocketSettings() {
        return this.heartbeatSocketSettings;
    }

    SslSettings getSslSettings() {
        return this.sslSettings;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        MongoClientOptions mongoClientOptions = (MongoClientOptions) obj;
        if (this.localThreshold != mongoClientOptions.localThreshold || this.alwaysUseMBeans != mongoClientOptions.alwaysUseMBeans || this.connectTimeout != mongoClientOptions.connectTimeout || this.cursorFinalizerEnabled != mongoClientOptions.cursorFinalizerEnabled || this.minHeartbeatFrequency != mongoClientOptions.minHeartbeatFrequency || this.heartbeatConnectTimeout != mongoClientOptions.heartbeatConnectTimeout || this.heartbeatFrequency != mongoClientOptions.heartbeatFrequency || this.heartbeatSocketTimeout != mongoClientOptions.heartbeatSocketTimeout || this.maxConnectionIdleTime != mongoClientOptions.maxConnectionIdleTime || this.maxConnectionLifeTime != mongoClientOptions.maxConnectionLifeTime || this.maxConnectionsPerHost != mongoClientOptions.maxConnectionsPerHost || this.serverSelectionTimeout != mongoClientOptions.serverSelectionTimeout || this.maxWaitTime != mongoClientOptions.maxWaitTime || this.minConnectionsPerHost != mongoClientOptions.minConnectionsPerHost || this.socketKeepAlive != mongoClientOptions.socketKeepAlive || this.socketTimeout != mongoClientOptions.socketTimeout || this.sslEnabled != mongoClientOptions.sslEnabled || this.sslInvalidHostNameAllowed != mongoClientOptions.sslInvalidHostNameAllowed || this.threadsAllowedToBlockForConnectionMultiplier != mongoClientOptions.threadsAllowedToBlockForConnectionMultiplier) {
            return false;
        }
        DBDecoderFactory dBDecoderFactory = this.dbDecoderFactory;
        if (dBDecoderFactory == null ? mongoClientOptions.dbDecoderFactory != null : !dBDecoderFactory.equals(mongoClientOptions.dbDecoderFactory)) {
            return false;
        }
        DBEncoderFactory dBEncoderFactory = this.dbEncoderFactory;
        if (dBEncoderFactory == null ? mongoClientOptions.dbEncoderFactory != null : !dBEncoderFactory.equals(mongoClientOptions.dbEncoderFactory)) {
            return false;
        }
        String str = this.description;
        if (str == null ? mongoClientOptions.description != null : !str.equals(mongoClientOptions.description)) {
            return false;
        }
        if (!this.readPreference.equals(mongoClientOptions.readPreference) || !this.writeConcern.equals(mongoClientOptions.writeConcern) || !this.readConcern.equals(mongoClientOptions.readConcern) || !this.codecRegistry.equals(mongoClientOptions.codecRegistry) || !this.commandListeners.equals(mongoClientOptions.commandListeners) || !this.clusterListeners.equals(mongoClientOptions.clusterListeners) || !this.serverListeners.equals(mongoClientOptions.serverListeners) || !this.serverMonitorListeners.equals(mongoClientOptions.serverMonitorListeners)) {
            return false;
        }
        String str2 = this.requiredReplicaSetName;
        if (str2 == null ? mongoClientOptions.requiredReplicaSetName == null : str2.equals(mongoClientOptions.requiredReplicaSetName)) {
            return this.socketFactory.getClass().equals(mongoClientOptions.socketFactory.getClass());
        }
        return false;
    }

    public int hashCode() {
        String str = this.description;
        int hashCode = (((((str != null ? str.hashCode() : 0) * 31) + this.readPreference.hashCode()) * 31) + this.writeConcern.hashCode()) * 31;
        ReadConcern readConcern = this.readConcern;
        int hashCode2 = (((((((((((((((((((((((((((((((((((((((((((((((hashCode + (readConcern != null ? readConcern.hashCode() : 0)) * 31) + this.codecRegistry.hashCode()) * 31) + this.commandListeners.hashCode()) * 31) + this.clusterListeners.hashCode()) * 31) + this.serverListeners.hashCode()) * 31) + this.serverMonitorListeners.hashCode()) * 31) + this.minConnectionsPerHost) * 31) + this.maxConnectionsPerHost) * 31) + this.threadsAllowedToBlockForConnectionMultiplier) * 31) + this.serverSelectionTimeout) * 31) + this.maxWaitTime) * 31) + this.maxConnectionIdleTime) * 31) + this.maxConnectionLifeTime) * 31) + this.connectTimeout) * 31) + this.socketTimeout) * 31) + (this.socketKeepAlive ? 1 : 0)) * 31) + (this.sslEnabled ? 1 : 0)) * 31) + (this.sslInvalidHostNameAllowed ? 1 : 0)) * 31) + (this.alwaysUseMBeans ? 1 : 0)) * 31) + this.heartbeatFrequency) * 31) + this.minHeartbeatFrequency) * 31) + this.heartbeatConnectTimeout) * 31) + this.heartbeatSocketTimeout) * 31) + this.localThreshold) * 31;
        String str2 = this.requiredReplicaSetName;
        int hashCode3 = (hashCode2 + (str2 != null ? str2.hashCode() : 0)) * 31;
        DBDecoderFactory dBDecoderFactory = this.dbDecoderFactory;
        int hashCode4 = (hashCode3 + (dBDecoderFactory != null ? dBDecoderFactory.hashCode() : 0)) * 31;
        DBEncoderFactory dBEncoderFactory = this.dbEncoderFactory;
        return ((((hashCode4 + (dBEncoderFactory != null ? dBEncoderFactory.hashCode() : 0)) * 31) + (this.cursorFinalizerEnabled ? 1 : 0)) * 31) + this.socketFactory.getClass().hashCode();
    }

    public String toString() {
        return "MongoClientOptions{description='" + this.description + "', readPreference=" + this.readPreference + ", writeConcern=" + this.writeConcern + ", readConcern=" + this.readConcern + ", codecRegistry=" + this.codecRegistry + ", commandListeners=" + this.commandListeners + ", clusterListeners=" + this.clusterListeners + ", serverListeners=" + this.serverListeners + ", serverMonitorListeners=" + this.serverMonitorListeners + ", minConnectionsPerHost=" + this.minConnectionsPerHost + ", maxConnectionsPerHost=" + this.maxConnectionsPerHost + ", threadsAllowedToBlockForConnectionMultiplier=" + this.threadsAllowedToBlockForConnectionMultiplier + ", serverSelectionTimeout=" + this.serverSelectionTimeout + ", maxWaitTime=" + this.maxWaitTime + ", maxConnectionIdleTime=" + this.maxConnectionIdleTime + ", maxConnectionLifeTime=" + this.maxConnectionLifeTime + ", connectTimeout=" + this.connectTimeout + ", socketTimeout=" + this.socketTimeout + ", socketKeepAlive=" + this.socketKeepAlive + ", sslEnabled=" + this.sslEnabled + ", sslInvalidHostNamesAllowed=" + this.sslInvalidHostNameAllowed + ", alwaysUseMBeans=" + this.alwaysUseMBeans + ", heartbeatFrequency=" + this.heartbeatFrequency + ", minHeartbeatFrequency=" + this.minHeartbeatFrequency + ", heartbeatConnectTimeout=" + this.heartbeatConnectTimeout + ", heartbeatSocketTimeout=" + this.heartbeatSocketTimeout + ", localThreshold=" + this.localThreshold + ", requiredReplicaSetName='" + this.requiredReplicaSetName + "', dbDecoderFactory=" + this.dbDecoderFactory + ", dbEncoderFactory=" + this.dbEncoderFactory + ", socketFactory=" + this.socketFactory + ", cursorFinalizerEnabled=" + this.cursorFinalizerEnabled + ", connectionPoolSettings=" + this.connectionPoolSettings + ", socketSettings=" + this.socketSettings + ", serverSettings=" + this.serverSettings + ", heartbeatSocketSettings=" + this.heartbeatSocketSettings + '}';
    }

    public static class Builder {
        private String description;
        private int maxConnectionIdleTime;
        private int maxConnectionLifeTime;
        private int minConnectionsPerHost;
        private String requiredReplicaSetName;
        private ReadPreference readPreference = ReadPreference.primary();
        private WriteConcern writeConcern = WriteConcern.ACKNOWLEDGED;
        private ReadConcern readConcern = ReadConcern.DEFAULT;
        private CodecRegistry codecRegistry = MongoClient.getDefaultCodecRegistry();
        private final List<CommandListener> commandListeners = new ArrayList();
        private final List<ClusterListener> clusterListeners = new ArrayList();
        private final List<ServerListener> serverListeners = new ArrayList();
        private final List<ServerMonitorListener> serverMonitorListeners = new ArrayList();
        private int maxConnectionsPerHost = 100;
        private int threadsAllowedToBlockForConnectionMultiplier = 5;
        private int serverSelectionTimeout = 30000;
        private int maxWaitTime = 120000;
        private int connectTimeout = ErrorCode.INVALID_OWNERSHIP;
        private int socketTimeout = 0;
        private boolean socketKeepAlive = false;
        private boolean sslEnabled = false;
        private boolean sslInvalidHostNameAllowed = false;
        private boolean alwaysUseMBeans = false;
        private int heartbeatFrequency = ErrorCode.INVALID_OWNERSHIP;
        private int minHeartbeatFrequency = 500;
        private int heartbeatConnectTimeout = 20000;
        private int heartbeatSocketTimeout = 20000;
        private int localThreshold = 15;
        private DBDecoderFactory dbDecoderFactory = DefaultDBDecoder.FACTORY;
        private DBEncoderFactory dbEncoderFactory = DefaultDBEncoder.FACTORY;
        private SocketFactory socketFactory = SocketFactory.getDefault();
        private boolean cursorFinalizerEnabled = true;

        public Builder() {
            heartbeatFrequency(Integer.parseInt(System.getProperty("com.mongodb.updaterIntervalMS", "10000")));
            minHeartbeatFrequency(Integer.parseInt(System.getProperty("com.mongodb.updaterIntervalNoMasterMS", "500")));
            heartbeatConnectTimeout(Integer.parseInt(System.getProperty("com.mongodb.updaterConnectTimeoutMS", "20000")));
            heartbeatSocketTimeout(Integer.parseInt(System.getProperty("com.mongodb.updaterSocketTimeoutMS", "20000")));
            localThreshold(Integer.parseInt(System.getProperty("com.mongodb.slaveAcceptableLatencyMS", "15")));
        }

        public Builder minConnectionsPerHost(int i) {
            Assertions.isTrueArgument("minConnectionsPerHost must be >= 0", i >= 0);
            this.minConnectionsPerHost = i;
            return this;
        }

        public Builder connectionsPerHost(int i) {
            Assertions.isTrueArgument("connectionPerHost must be > 0", i > 0);
            this.maxConnectionsPerHost = i;
            return this;
        }

        public Builder threadsAllowedToBlockForConnectionMultiplier(int i) {
            Assertions.isTrueArgument("threadsAllowedToBlockForConnectionMultiplier must be > 0", i > 0);
            this.threadsAllowedToBlockForConnectionMultiplier = i;
            return this;
        }

        public Builder serverSelectionTimeout(int i) {
            this.serverSelectionTimeout = i;
            return this;
        }

        public Builder maxWaitTime(int i) {
            this.maxWaitTime = i;
            return this;
        }

        public Builder maxConnectionIdleTime(int i) {
            this.maxConnectionIdleTime = i;
            return this;
        }

        public Builder maxConnectionLifeTime(int i) {
            this.maxConnectionLifeTime = i;
            return this;
        }

        public Builder connectTimeout(int i) {
            Assertions.isTrueArgument("connectTimeout must be >= 0", i >= 0);
            this.connectTimeout = i;
            return this;
        }

        public Builder socketTimeout(int i) {
            this.socketTimeout = i;
            return this;
        }

        public Builder sslEnabled(boolean z) {
            this.sslEnabled = z;
            socketFactory(z ? SSLSocketFactory.getDefault() : SocketFactory.getDefault());
            return this;
        }

        public Builder sslInvalidHostNameAllowed(boolean z) {
            this.sslInvalidHostNameAllowed = z;
            return this;
        }

        public Builder readPreference(ReadPreference readPreference) {
            this.readPreference = (ReadPreference) Assertions.notNull("readPreference", readPreference);
            return this;
        }

        public Builder writeConcern(WriteConcern writeConcern) {
            this.writeConcern = (WriteConcern) Assertions.notNull("writeConcern", writeConcern);
            return this;
        }

        public Builder readConcern(ReadConcern readConcern) {
            this.readConcern = (ReadConcern) Assertions.notNull("readConcern", readConcern);
            return this;
        }

        public Builder socketFactory(SocketFactory socketFactory) {
            if (socketFactory == null) {
                throw new IllegalArgumentException("null is not a legal value");
            }
            this.socketFactory = socketFactory;
            return this;
        }

        public Builder heartbeatFrequency(int i) {
            Assertions.isTrueArgument("heartbeatFrequency must be > 0", i > 0);
            this.heartbeatFrequency = i;
            return this;
        }

        public Builder minHeartbeatFrequency(int i) {
            Assertions.isTrueArgument("minHeartbeatFrequency must be > 0", i > 0);
            this.minHeartbeatFrequency = i;
            return this;
        }

        public Builder heartbeatConnectTimeout(int i) {
            this.heartbeatConnectTimeout = i;
            return this;
        }

        public Builder heartbeatSocketTimeout(int i) {
            this.heartbeatSocketTimeout = i;
            return this;
        }

        public Builder localThreshold(int i) {
            Assertions.isTrueArgument("localThreshold must be >= 0", i >= 0);
            this.localThreshold = i;
            return this;
        }

        public Builder requiredReplicaSetName(String str) {
            this.requiredReplicaSetName = str;
            return this;
        }

        public Builder legacyDefaults() {
            connectionsPerHost(10).writeConcern(WriteConcern.UNACKNOWLEDGED);
            return this;
        }

        public MongoClientOptions build() {
            return new MongoClientOptions(this);
        }
    }
}