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()));
}
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();
}
}
}
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());
}
}
Aggregations