com.datastax.dse.driver.api.core.DseSessionBuilder Maven / Gradle / Ivy
/*
* Copyright DataStax, Inc.
*
* This software can be used solely with DataStax Enterprise. Please consult the license at
* http://www.datastax.com/terms/datastax-dse-driver-license-terms
*/
package com.datastax.dse.driver.api.core;
import com.datastax.dse.driver.api.core.type.codec.DseTypeCodecs;
import com.datastax.dse.driver.internal.core.config.typesafe.DefaultDseDriverConfigLoader;
import com.datastax.dse.driver.internal.core.context.DseDriverContext;
import com.datastax.dse.driver.internal.core.session.DefaultDseSession;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
import com.datastax.oss.driver.api.core.context.DriverContext;
import com.datastax.oss.driver.api.core.metadata.Node;
import com.datastax.oss.driver.api.core.metadata.NodeStateListener;
import com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener;
import com.datastax.oss.driver.api.core.session.SessionBuilder;
import com.datastax.oss.driver.api.core.tracker.RequestTracker;
import com.datastax.oss.driver.api.core.type.codec.TypeCodec;
import com.datastax.oss.driver.api.core.uuid.Uuids;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Predicate;
import net.jcip.annotations.NotThreadSafe;
@NotThreadSafe
public class DseSessionBuilder extends SessionBuilder {
// Startup options
private UUID startupClientId;
private String startupApplicationName;
private String startupApplicationVersion;
/**
* A unique identifier for the created session.
*
* It will be sent in the {@code STARTUP} protocol message for each new connection established
* by the driver, and may be used by future DSE versions for monitoring purposes.
*
*
If you don't call this method, the driver will generate an identifier with {@link
* Uuids#random()}.
*/
@NonNull
public DseSessionBuilder withClientId(@Nullable UUID clientId) {
this.startupClientId = clientId;
return this;
}
/**
* The name of the application using the created session.
*
*
It will be sent in the {@code STARTUP} protocol message for each new connection established
* by the driver, and may be used by future DSE versions for monitoring purposes.
*
*
This can also be defined in the driver configuration with the option {@code
* basic.application.name}; if you specify both, this method takes precedence and the
* configuration option will be ignored.
*/
@NonNull
public DseSessionBuilder withApplicationName(@Nullable String applicationName) {
this.startupApplicationName = applicationName;
return this;
}
/**
* The version of the application using the created session.
*
*
It will be sent in the {@code STARTUP} protocol message for each new connection established
* by the driver, and may be used by future DSE versions for monitoring purposes.
*
*
This can also be defined in the driver configuration with the option {@code
* basic.application.version}; if you specify both, this method takes precedence and the
* configuration option will be ignored.
*/
@NonNull
public DseSessionBuilder withApplicationVersion(@Nullable String applicationVersion) {
this.startupApplicationVersion = applicationVersion;
return this;
}
@Override
protected DriverContext buildContext(
DriverConfigLoader configLoader,
List> typeCodecs,
NodeStateListener nodeStateListener,
SchemaChangeListener schemaChangeListener,
RequestTracker requestTracker,
Map localDatacenters,
Map> nodeFilters,
ClassLoader classLoader) {
typeCodecs.add(DseTypeCodecs.LINE_STRING);
typeCodecs.add(DseTypeCodecs.POINT);
typeCodecs.add(DseTypeCodecs.POLYGON);
typeCodecs.add(DseTypeCodecs.DATE_RANGE);
return new DseDriverContext(
configLoader,
typeCodecs,
nodeStateListener,
schemaChangeListener,
requestTracker,
localDatacenters,
nodeFilters,
classLoader,
startupClientId,
startupApplicationName,
startupApplicationVersion);
}
@NonNull
@Override
protected DriverConfigLoader defaultConfigLoader() {
return new DefaultDseDriverConfigLoader();
}
@NonNull
@Override
protected DseSession wrap(@NonNull CqlSession defaultSession) {
return new DefaultDseSession(defaultSession);
}
}