use of com.mongodb.connection.ClusterSettings in project JavaForFun by gumartinm.
the class MongoConfiguration method reactiveMongoClient.
@Bean
@Override
public MongoClient reactiveMongoClient() {
SocketSettings socketSettings = SocketSettings.builder().connectTimeout(30000, TimeUnit.MILLISECONDS).readTimeout(30000, TimeUnit.MILLISECONDS).build();
ServerAddress serverAddress = new ServerAddress(host, port);
ClusterSettings clusterSettings = ClusterSettings.builder().hosts(Collections.singletonList(serverAddress)).build();
ConnectionPoolSettings connectionPoolSettings = ConnectionPoolSettings.builder().maxWaitTime(15000, TimeUnit.MILLISECONDS).build();
MongoClientSettings mongoClientSettings = MongoClientSettings.builder().applicationName(databaseName).socketSettings(socketSettings).clusterSettings(clusterSettings).connectionPoolSettings(connectionPoolSettings).build();
return MongoClients.create(mongoClientSettings);
}
use of com.mongodb.connection.ClusterSettings in project georocket by georocket.
the class MongoDBChunkReadStreamTest method createAsyncClient.
/**
* Create an asynchronous MongoDB client
* @return the client
*/
private com.mongodb.async.client.MongoClient createAsyncClient() {
ClusterSettings clusterSettings = ClusterSettings.builder().hosts(Arrays.asList(mongoConnector.serverAddress)).build();
MongoClientSettings settings = MongoClientSettings.builder().clusterSettings(clusterSettings).build();
return MongoClients.create(settings);
}
use of com.mongodb.connection.ClusterSettings 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.ClusterSettings in project mongo-java-driver by mongodb.
the class DefaultClusterFactory method createCluster.
/**
* Creates a cluster with the given settings. The cluster mode will be based on the mode from the settings.
*
* @param originalClusterSettings the cluster settings
* @param originalServerSettings the server settings
* @param connectionPoolSettings the connection pool settings
* @param internalConnectionPoolSettings the internal connection pool settings
* @param streamFactory the stream factory
* @param heartbeatStreamFactory the heartbeat stream factory
* @param credential the credential, which may be null
* @param commandListener an optional listener for command-related events
* @param applicationName an optional application name to associate with connections to the servers in this cluster
* @param mongoDriverInformation the optional driver information associate with connections to the servers in this cluster
* @param compressorList the list of compressors to request, in priority order
* @param serverApi the server api, which may be null
* @return the cluster
*
* @since 3.6
*/
public Cluster createCluster(final ClusterSettings originalClusterSettings, final ServerSettings originalServerSettings, final ConnectionPoolSettings connectionPoolSettings, final InternalConnectionPoolSettings internalConnectionPoolSettings, final StreamFactory streamFactory, final StreamFactory heartbeatStreamFactory, @Nullable final MongoCredential credential, final CommandListener commandListener, final String applicationName, final MongoDriverInformation mongoDriverInformation, final List<MongoCompressor> compressorList, @Nullable final ServerApi serverApi) {
ClusterId clusterId = new ClusterId();
ClusterSettings clusterSettings;
ServerSettings serverSettings;
if (noClusterEventListeners(originalClusterSettings, originalServerSettings)) {
clusterSettings = ClusterSettings.builder(originalClusterSettings).clusterListenerList(singletonList(NO_OP_CLUSTER_LISTENER)).build();
serverSettings = ServerSettings.builder(originalServerSettings).serverListenerList(singletonList(NO_OP_SERVER_LISTENER)).serverMonitorListenerList(singletonList(NO_OP_SERVER_MONITOR_LISTENER)).build();
} else {
AsynchronousClusterEventListener clusterEventListener = AsynchronousClusterEventListener.startNew(clusterId, getClusterListener(originalClusterSettings), getServerListener(originalServerSettings), getServerMonitorListener(originalServerSettings));
clusterSettings = ClusterSettings.builder(originalClusterSettings).clusterListenerList(singletonList(clusterEventListener)).build();
serverSettings = ServerSettings.builder(originalServerSettings).serverListenerList(singletonList(clusterEventListener)).serverMonitorListenerList(singletonList(clusterEventListener)).build();
}
DnsSrvRecordMonitorFactory dnsSrvRecordMonitorFactory = new DefaultDnsSrvRecordMonitorFactory(clusterId, serverSettings);
if (clusterSettings.getMode() == ClusterConnectionMode.LOAD_BALANCED) {
ClusterableServerFactory serverFactory = new LoadBalancedClusterableServerFactory(serverSettings, connectionPoolSettings, internalConnectionPoolSettings, streamFactory, credential, commandListener, applicationName, mongoDriverInformation != null ? mongoDriverInformation : MongoDriverInformation.builder().build(), compressorList, serverApi);
return new LoadBalancedCluster(clusterId, clusterSettings, serverFactory, dnsSrvRecordMonitorFactory);
} else {
ClusterableServerFactory serverFactory = new DefaultClusterableServerFactory(serverSettings, connectionPoolSettings, internalConnectionPoolSettings, streamFactory, heartbeatStreamFactory, credential, commandListener, applicationName, mongoDriverInformation != null ? mongoDriverInformation : MongoDriverInformation.builder().build(), compressorList, serverApi);
if (clusterSettings.getMode() == ClusterConnectionMode.SINGLE) {
return new SingleServerCluster(clusterId, clusterSettings, serverFactory);
} else if (clusterSettings.getMode() == ClusterConnectionMode.MULTIPLE) {
if (clusterSettings.getSrvHost() == null) {
return new MultiServerCluster(clusterId, clusterSettings, serverFactory);
} else {
return new DnsMultiServerCluster(clusterId, clusterSettings, serverFactory, dnsSrvRecordMonitorFactory);
}
} else {
throw new UnsupportedOperationException("Unsupported cluster mode: " + clusterSettings.getMode());
}
}
}
use of com.mongodb.connection.ClusterSettings in project mongo-java-driver by mongodb.
the class AbstractServerDiscoveryAndMonitoringTest method init.
protected void init(final ServerListenerFactory serverListenerFactory, final ClusterListener clusterListener) {
ConnectionString connectionString = new ConnectionString(definition.getString("uri").getValue());
ClusterSettings settings = ClusterSettings.builder().applyConnectionString(connectionString).serverSelectionTimeout(1, TimeUnit.SECONDS).build();
ClusterId clusterId = new ClusterId();
factory = new DefaultTestClusterableServerFactory(settings.getMode(), serverListenerFactory);
ClusterSettings clusterSettings = settings.getClusterListeners().contains(clusterListener) ? settings : ClusterSettings.builder(settings).addClusterListener(clusterListener).build();
if (settings.getMode() == ClusterConnectionMode.SINGLE) {
cluster = new SingleServerCluster(clusterId, clusterSettings, factory);
} else if (settings.getMode() == ClusterConnectionMode.MULTIPLE) {
cluster = new MultiServerCluster(clusterId, clusterSettings, factory);
} else {
cluster = new LoadBalancedCluster(clusterId, clusterSettings, factory, null);
}
}
Aggregations