Search in sources :

Example 1 with SocketStreamFactory

use of com.mongodb.connection.SocketStreamFactory in project mongo-java-driver by mongodb.

the class SingleServerClusterTest method setUpCluster.

private void setUpCluster(final ServerAddress serverAddress) {
    SocketStreamFactory streamFactory = new SocketStreamFactory(SocketSettings.builder().build(), getSslSettings());
    ClusterId clusterId = new ClusterId();
    ClusterSettings clusterSettings = ClusterSettings.builder().mode(ClusterConnectionMode.SINGLE).hosts(singletonList(serverAddress)).build();
    cluster = new SingleServerCluster(clusterId, clusterSettings, new DefaultClusterableServerFactory(ServerSettings.builder().build(), ConnectionPoolSettings.builder().maxSize(1).build(), InternalConnectionPoolSettings.builder().build(), streamFactory, streamFactory, getCredential(), null, null, null, Collections.<MongoCompressor>emptyList(), getServerApi()));
}
Also used : SocketStreamFactory(com.mongodb.connection.SocketStreamFactory) ClusterSettings(com.mongodb.connection.ClusterSettings) ClusterId(com.mongodb.connection.ClusterId)

Example 2 with SocketStreamFactory

use of com.mongodb.connection.SocketStreamFactory 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)

Example 3 with SocketStreamFactory

use of com.mongodb.connection.SocketStreamFactory in project mongo-java-driver by mongodb.

the class MongoClientImpl method getStreamFactory.

private static StreamFactory getStreamFactory(final MongoClientSettings settings, final boolean isHeartbeat) {
    StreamFactoryFactory streamFactoryFactory = settings.getStreamFactoryFactory();
    SocketSettings socketSettings = isHeartbeat ? settings.getHeartbeatSocketSettings() : settings.getSocketSettings();
    if (streamFactoryFactory == null) {
        return new SocketStreamFactory(socketSettings, settings.getSslSettings());
    } else {
        return streamFactoryFactory.create(socketSettings, settings.getSslSettings());
    }
}
Also used : SocketStreamFactory(com.mongodb.connection.SocketStreamFactory) StreamFactoryFactory(com.mongodb.connection.StreamFactoryFactory) SocketSettings(com.mongodb.connection.SocketSettings)

Aggregations

SocketStreamFactory (com.mongodb.connection.SocketStreamFactory)3 ClusterId (com.mongodb.connection.ClusterId)1 ClusterSettings (com.mongodb.connection.ClusterSettings)1 SocketSettings (com.mongodb.connection.SocketSettings)1 StreamFactoryFactory (com.mongodb.connection.StreamFactoryFactory)1 AsyncClusterBinding (com.mongodb.internal.binding.AsyncClusterBinding)1 ClusterBinding (com.mongodb.internal.binding.ClusterBinding)1 Cluster (com.mongodb.internal.connection.Cluster)1 BsonDocument (org.bson.BsonDocument)1 BsonInt32 (org.bson.BsonInt32)1 BsonDocumentCodec (org.bson.codecs.BsonDocumentCodec)1