Search in sources :

Example 1 with ClusterBinding

use of com.mongodb.internal.binding.ClusterBinding in project mongo-java-driver by mongodb.

the class ClusterFixture method getBinding.

private static ReadWriteBinding getBinding(final Cluster cluster, final ReadPreference readPreference) {
    if (!bindingMap.containsKey(readPreference)) {
        ReadWriteBinding binding = new ClusterBinding(cluster, readPreference, ReadConcern.DEFAULT, getServerApi(), IgnorableRequestContext.INSTANCE);
        if (serverVersionAtLeast(3, 6)) {
            binding = new SessionBinding(binding);
        }
        bindingMap.put(readPreference, binding);
    }
    return bindingMap.get(readPreference);
}
Also used : AsyncReadWriteBinding(com.mongodb.internal.binding.AsyncReadWriteBinding) ReadWriteBinding(com.mongodb.internal.binding.ReadWriteBinding) ClusterBinding(com.mongodb.internal.binding.ClusterBinding) AsyncClusterBinding(com.mongodb.internal.binding.AsyncClusterBinding) AsyncSessionBinding(com.mongodb.internal.binding.AsyncSessionBinding) SessionBinding(com.mongodb.internal.binding.SessionBinding)

Example 2 with ClusterBinding

use of com.mongodb.internal.binding.ClusterBinding in project mongo-java-driver by mongodb.

the class ClusterFixture method getConnectionString.

public static synchronized ConnectionString getConnectionString() {
    if (connectionString != null) {
        return connectionString;
    }
    ConnectionString mongoURIProperty = getConnectionStringFromSystemProperty(MONGODB_URI_SYSTEM_PROPERTY_NAME);
    if (mongoURIProperty != null) {
        return mongoURIProperty;
    }
    // Figure out what the connection string should be
    Cluster cluster = createCluster(new ConnectionString(DEFAULT_URI), new SocketStreamFactory(SocketSettings.builder().build(), SslSettings.builder().build()));
    try {
        BsonDocument helloResult = new CommandReadOperation<BsonDocument>("admin", new BsonDocument(LEGACY_HELLO, new BsonInt32(1)), new BsonDocumentCodec()).execute(new ClusterBinding(cluster, ReadPreference.nearest(), ReadConcern.DEFAULT, getServerApi(), IgnorableRequestContext.INSTANCE));
        if (helloResult.containsKey("setName")) {
            connectionString = new ConnectionString(DEFAULT_URI + "/?replicaSet=" + helloResult.getString("setName").getValue());
        } else {
            connectionString = new ConnectionString(DEFAULT_URI);
            ClusterFixture.cluster = cluster;
        }
        return connectionString;
    } finally {
        if (ClusterFixture.cluster == null) {
            cluster.close();
        }
    }
}
Also used : BsonInt32(org.bson.BsonInt32) SocketStreamFactory(com.mongodb.connection.SocketStreamFactory) BsonDocument(org.bson.BsonDocument) Cluster(com.mongodb.internal.connection.Cluster) ClusterBinding(com.mongodb.internal.binding.ClusterBinding) AsyncClusterBinding(com.mongodb.internal.binding.AsyncClusterBinding) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec)

Aggregations

AsyncClusterBinding (com.mongodb.internal.binding.AsyncClusterBinding)2 ClusterBinding (com.mongodb.internal.binding.ClusterBinding)2 SocketStreamFactory (com.mongodb.connection.SocketStreamFactory)1 AsyncReadWriteBinding (com.mongodb.internal.binding.AsyncReadWriteBinding)1 AsyncSessionBinding (com.mongodb.internal.binding.AsyncSessionBinding)1 ReadWriteBinding (com.mongodb.internal.binding.ReadWriteBinding)1 SessionBinding (com.mongodb.internal.binding.SessionBinding)1 Cluster (com.mongodb.internal.connection.Cluster)1 BsonDocument (org.bson.BsonDocument)1 BsonInt32 (org.bson.BsonInt32)1 BsonDocumentCodec (org.bson.codecs.BsonDocumentCodec)1