Skip to content

Configuration: implement application name, version and client id #554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions driver-core/src/main/java/com/datastax/driver/core/Cluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,36 @@ public Builder withLocalPortRange(int low, int high) {
return this;
}

/**
* Sets application name that will be sent to the server on startup.
*
* @param applicationName name of the application.
*/
public Builder withApplicationName(String applicationName) {
configurationBuilder.withApplicationName(applicationName);
return this;
}

/**
* Sets application version that will be sent to the server on startup.
*
* @param applicationVersion version of the application.
*/
public Builder withApplicationVersion(String applicationVersion) {
configurationBuilder.withApplicationVersion(applicationVersion);
return this;
}

/**
* Sets client id that will be sent to the server on startup.
*
* @param clientId id of the application.
*/
public Builder withClientId(String clientId) {
configurationBuilder.withClientId(clientId);
return this;
}

/**
* The configuration that will be used for the new cluster.
*
Expand Down Expand Up @@ -1675,6 +1705,9 @@ private Manager(
.withThreadingOptions(configuration.getThreadingOptions())
.withNettyOptions(configuration.getNettyOptions())
.withCodecRegistry(configuration.getCodecRegistry())
.withApplicationName(configuration.getApplicationName())
.withApplicationVersion(configuration.getApplicationVersion())
.withClientId(configuration.getClientId())
.build();
} else {
this.configuration = configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public static Builder builder() {
private final NettyOptions nettyOptions;
private final CodecRegistry codecRegistry;
private final String defaultKeyspace;
private final String applicationName;
private final String applicationVersion;
private final String clientId;

private Configuration(
Policies policies,
Expand All @@ -70,7 +73,10 @@ private Configuration(
ThreadingOptions threadingOptions,
NettyOptions nettyOptions,
CodecRegistry codecRegistry,
String defaultKeyspace) {
String defaultKeyspace,
String applicationName,
String applicationVersion,
String clientId) {
this.policies = policies;
this.protocolOptions = protocolOptions;
this.poolingOptions = poolingOptions;
Expand All @@ -81,6 +87,9 @@ private Configuration(
this.nettyOptions = nettyOptions;
this.codecRegistry = codecRegistry;
this.defaultKeyspace = defaultKeyspace;
this.applicationName = applicationName;
this.applicationVersion = applicationVersion;
this.clientId = clientId;
}

/**
Expand All @@ -99,7 +108,10 @@ protected Configuration(Configuration toCopy) {
toCopy.getThreadingOptions(),
toCopy.getNettyOptions(),
toCopy.getCodecRegistry(),
toCopy.getDefaultKeyspace());
toCopy.getDefaultKeyspace(),
toCopy.getApplicationName(),
toCopy.getApplicationVersion(),
toCopy.getClientId());
}

void register(Cluster.Manager manager) {
Expand Down Expand Up @@ -213,6 +225,19 @@ public NettyOptions getNettyOptions() {
public String getDefaultKeyspace() {
return defaultKeyspace;
}

public String getApplicationName() {
return applicationName;
}

public String getApplicationVersion() {
return applicationVersion;
}

public String getClientId() {
return clientId;
}

/**
* Returns the {@link CodecRegistry} instance for this configuration.
*
Expand All @@ -239,6 +264,42 @@ public static class Builder {
private NettyOptions nettyOptions;
private CodecRegistry codecRegistry;
private String defaultKeyspace;
private String applicationName;
private String applicationVersion;
private String clientId;

/**
* Sets application name, to be reported to server
*
* @param applicationName application name.
* @return this builder.
*/
public Builder withApplicationName(String applicationName) {
this.applicationName = applicationName;
return this;
}

/**
* Sets application version, to be reported to server
*
* @param applicationVersion application version.
* @return this builder.
*/
public Builder withApplicationVersion(String applicationVersion) {
this.applicationVersion = applicationVersion;
return this;
}

/**
* Sets client id, to be reported to server
*
* @param clientId application version.
* @return this builder.
*/
public Builder withClientId(String clientId) {
this.clientId = clientId;
return this;
}

/**
* Sets the policies for this cluster.
Expand Down Expand Up @@ -370,7 +431,10 @@ public Configuration build() {
threadingOptions != null ? threadingOptions : new ThreadingOptions(),
nettyOptions != null ? nettyOptions : NettyOptions.DEFAULT_INSTANCE,
codecRegistry != null ? codecRegistry : CodecRegistry.DEFAULT_INSTANCE,
defaultKeyspace);
defaultKeyspace,
applicationName,
applicationVersion,
clientId);
}
}
}
14 changes: 14 additions & 0 deletions driver-core/src/main/java/com/datastax/driver/core/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,20 @@ public ListenableFuture<Void> apply(Void input) throws Exception {
logger.debug("Enabling tablet support in OPTIONS message");
TabletInfo.addOption(extraOptions);
}

if (factory.configuration.getApplicationName() != null
&& !factory.configuration.getApplicationName().isEmpty()) {
extraOptions.put("APPLICATION_NAME", factory.configuration.getApplicationName());
}
if (factory.configuration.getApplicationVersion() != null
&& !factory.configuration.getApplicationVersion().isEmpty()) {
extraOptions.put("APPLICATION_VERSION", factory.configuration.getApplicationVersion());
}
if (factory.configuration.getClientId() != null
&& !factory.configuration.getClientId().isEmpty()) {
extraOptions.put("CLIENT_ID", factory.configuration.getClientId());
}

Future startupResponseFuture =
write(
new Requests.Startup(
Expand Down
Loading