in core/src/main/java/com/datastax/oss/driver/api/core/session/SessionBuilder.java [843:915]
protected final CompletionStage<CqlSession> buildDefaultSessionAsync() {
try {
ProgrammaticArguments programmaticArguments = programmaticArgumentsBuilder.build();
DriverConfigLoader configLoader =
this.configLoader != null
? this.configLoader
: defaultConfigLoader(programmaticArguments.getClassLoader());
DriverExecutionProfile defaultConfig = configLoader.getInitialConfig().getDefaultProfile();
if (cloudConfigInputStream == null) {
String configUrlString =
defaultConfig.getString(DefaultDriverOption.CLOUD_SECURE_CONNECT_BUNDLE, null);
if (configUrlString != null) {
cloudConfigInputStream = () -> getURL(configUrlString).openStream();
}
}
List<String> configContactPoints =
defaultConfig.getStringList(DefaultDriverOption.CONTACT_POINTS, Collections.emptyList());
if (cloudConfigInputStream != null) {
if (!programmaticContactPoints.isEmpty() || !configContactPoints.isEmpty()) {
LOG.info(
"Both a secure connect bundle and contact points were provided. These are mutually exclusive. The contact points from the secure bundle will have priority.");
// clear the contact points provided in the setting file and via addContactPoints
configContactPoints = Collections.emptyList();
programmaticContactPoints = new HashSet<>();
}
if (programmaticSslFactory
|| defaultConfig.isDefined(DefaultDriverOption.SSL_ENGINE_FACTORY_CLASS)) {
LOG.info(
"Both a secure connect bundle and SSL options were provided. They are mutually exclusive. The SSL options from the secure bundle will have priority.");
}
CloudConfig cloudConfig =
new CloudConfigFactory().createCloudConfig(cloudConfigInputStream.call());
addContactEndPoints(cloudConfig.getEndPoints());
boolean localDataCenterDefined =
anyProfileHasDatacenterDefined(configLoader.getInitialConfig());
if (programmaticLocalDatacenter || localDataCenterDefined) {
LOG.info(
"Both a secure connect bundle and a local datacenter were provided. They are mutually exclusive. The local datacenter from the secure bundle will have priority.");
programmaticArgumentsBuilder.clearDatacenters();
}
withLocalDatacenter(cloudConfig.getLocalDatacenter());
withSslEngineFactory(cloudConfig.getSslEngineFactory());
withCloudProxyAddress(cloudConfig.getProxyAddress());
programmaticArguments = programmaticArgumentsBuilder.build();
}
boolean resolveAddresses =
defaultConfig.getBoolean(DefaultDriverOption.RESOLVE_CONTACT_POINTS, true);
Set<EndPoint> contactPoints =
ContactPoints.merge(programmaticContactPoints, configContactPoints, resolveAddresses);
if (keyspace == null && defaultConfig.isDefined(DefaultDriverOption.SESSION_KEYSPACE)) {
keyspace =
CqlIdentifier.fromCql(defaultConfig.getString(DefaultDriverOption.SESSION_KEYSPACE));
}
return DefaultSession.init(
(InternalDriverContext) buildContext(configLoader, programmaticArguments),
contactPoints,
keyspace);
} catch (Throwable t) {
// We construct the session synchronously (until the init() call), but async clients expect a
// failed future if anything goes wrong. So wrap any error from that synchronous part.
return CompletableFutures.failedFuture(t);
}
}