use of com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener in project cdc-apache-cassandra by datastax.
the class CassandraClient method buildCqlSession.
public static CqlSession buildCqlSession(CassandraSourceConnectorConfig config, String version, String applicationName, SchemaChangeListener schemaChangeListener) {
log.info("CassandraClient starting with config:\n{}\n", config.toString());
SslConfig sslConfig = config.getSslConfig();
// refresh only our keyspace.
OptionsMap optionsMap = OptionsMap.driverDefaults();
optionsMap.put(TypedDriverOption.METADATA_SCHEMA_REFRESHED_KEYSPACES, Arrays.asList(config.getKeyspaceName()));
DriverConfigLoader loader = DriverConfigLoader.fromMap(optionsMap);
CqlSessionBuilder builder = new SessionBuilder(sslConfig).withConfigLoader(loader).withApplicationVersion(version).withApplicationName(applicationName).withClientId(generateClientId(config.getInstanceName())).withKeyspace(config.getKeyspaceName()).withSchemaChangeListener(schemaChangeListener);
ContactPointsValidator.validateContactPoints(config.getContactPoints());
if (sslConfig != null && sslConfig.requireHostnameValidation()) {
// if requireHostnameValidation then InetSocketAddress must be resolved
config.getContactPoints().stream().map(hostStr -> new InetSocketAddress(hostStr, config.getPort())).forEach(builder::addContactPoint);
} else {
config.getContactPoints().stream().map(hostStr -> InetSocketAddress.createUnresolved(hostStr, config.getPort())).forEach(builder::addContactPoint);
}
ProgrammaticDriverConfigLoaderBuilder configLoaderBuilder = dseProgrammaticBuilderWithFallback(ConfigFactory.parseMap(config.getJavaDriverSettings(), "Connector properties"));
processAuthenticatorConfig(config, configLoaderBuilder);
if (sslConfig != null) {
processSslConfig(sslConfig, configLoaderBuilder);
}
builder.withConfigLoader(configLoaderBuilder.build());
CqlSession cqlSession = builder.build();
cqlSession.setSchemaMetadataEnabled(true);
return cqlSession;
}
Aggregations