use of com.datastax.oss.driver.internal.core.tracker.RequestLogger in project zipkin by openzipkin.
the class SessionBuilder method buildSession.
/**
* Returns a connected session. Closes the cluster if any exception occurred.
*/
public static CqlSession buildSession(String contactPoints, String localDc, Map<DriverOption, Integer> poolingOptions, @Nullable AuthProvider authProvider, boolean useSsl) {
// Some options aren't supported by builder methods. In these cases, we use driver config
// See https://groups.google.com/a/lists.datastax.com/forum/#!topic/java-driver-user/Z8HrCDX47Q0
ProgrammaticDriverConfigLoaderBuilder config = // server, where Thread.currentThread().getContextClassLoader() returns null
DriverConfigLoader.programmaticBuilder(SessionBuilder.class.getClassLoader());
// Ported from java-driver v3 PoolingOptions.setPoolTimeoutMillis as request timeout includes that
config.withDuration(REQUEST_TIMEOUT, Duration.ofMinutes(1));
CqlSessionBuilder builder = CqlSession.builder();
builder.addContactPoints(parseContactPoints(contactPoints));
if (authProvider != null)
builder.withAuthProvider(authProvider);
// In java-driver v3, we used LatencyAwarePolicy(DCAwareRoundRobinPolicy|RoundRobinPolicy)
// where DCAwareRoundRobinPolicy was used if localDc != null
//
// In java-driver v4, the default policy is token-aware and localDc is required. Hence, we
// use the default load balancing policy
// * https://github.com/datastax/java-driver/blob/master/manual/core/load_balancing/README.md
builder.withLocalDatacenter(localDc);
config = config.withString(REQUEST_CONSISTENCY, "LOCAL_ONE");
// Pooling options changed dramatically from v3->v4. This is a close match.
poolingOptions.forEach(config::withInt);
// All Zipkin CQL writes are idempotent
config = config.withBoolean(REQUEST_DEFAULT_IDEMPOTENCE, true);
if (useSsl)
config = config.withClass(SSL_ENGINE_FACTORY_CLASS, DefaultSslEngineFactory.class);
// Log categories can enable query logging
Logger requestLogger = LoggerFactory.getLogger(RequestLogger.class);
if (requestLogger.isDebugEnabled()) {
config = config.withClass(REQUEST_TRACKER_CLASS, RequestLogger.class);
config = config.withBoolean(REQUEST_LOGGER_SUCCESS_ENABLED, true);
// Only show bodies when TRACE is enabled
config = config.withBoolean(REQUEST_LOGGER_VALUES, requestLogger.isTraceEnabled());
}
// Don't warn: ensureSchema creates the keyspace. Hence, we need to "use" it later.
config = config.withBoolean(REQUEST_WARN_IF_SET_KEYSPACE, false);
return builder.withConfigLoader(config.build()).build();
}
Aggregations