Skip to content

Commit 53d626f

Browse files
committed
Configuration: implement application name, version and client id
Make driver report application name, version and client id to server on startup message.
1 parent d57e192 commit 53d626f

File tree

3 files changed

+114
-3
lines changed

3 files changed

+114
-3
lines changed

driver-core/src/main/java/com/datastax/driver/core/Cluster.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,36 @@ public Builder withLocalPortRange(int low, int high) {
15211521
return this;
15221522
}
15231523

1524+
/**
1525+
* Sets application name that will be sent to the server on startup.
1526+
*
1527+
* @param applicationName name of the application.
1528+
*/
1529+
public Builder withApplicationName(String applicationName) {
1530+
configurationBuilder.withApplicationName(applicationName);
1531+
return this;
1532+
}
1533+
1534+
/**
1535+
* Sets application version that will be sent to the server on startup.
1536+
*
1537+
* @param applicationVersion version of the application.
1538+
*/
1539+
public Builder withApplicationVersion(String applicationVersion) {
1540+
configurationBuilder.withApplicationVersion(applicationVersion);
1541+
return this;
1542+
}
1543+
1544+
/**
1545+
* Sets client id that will be sent to the server on startup.
1546+
*
1547+
* @param clientId id of the application.
1548+
*/
1549+
public Builder withClientId(String clientId) {
1550+
configurationBuilder.withClientId(clientId);
1551+
return this;
1552+
}
1553+
15241554
/**
15251555
* The configuration that will be used for the new cluster.
15261556
*
@@ -1675,6 +1705,9 @@ private Manager(
16751705
.withThreadingOptions(configuration.getThreadingOptions())
16761706
.withNettyOptions(configuration.getNettyOptions())
16771707
.withCodecRegistry(configuration.getCodecRegistry())
1708+
.withApplicationName(configuration.getApplicationName())
1709+
.withApplicationVersion(configuration.getApplicationVersion())
1710+
.withClientId(configuration.getClientId())
16781711
.build();
16791712
} else {
16801713
this.configuration = configuration;

driver-core/src/main/java/com/datastax/driver/core/Configuration.java

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public static Builder builder() {
5959
private final NettyOptions nettyOptions;
6060
private final CodecRegistry codecRegistry;
6161
private final String defaultKeyspace;
62+
private final String applicationName;
63+
private final String applicationVersion;
64+
private final String clientId;
6265

6366
private Configuration(
6467
Policies policies,
@@ -70,7 +73,10 @@ private Configuration(
7073
ThreadingOptions threadingOptions,
7174
NettyOptions nettyOptions,
7275
CodecRegistry codecRegistry,
73-
String defaultKeyspace) {
76+
String defaultKeyspace,
77+
String applicationName,
78+
String applicationVersion,
79+
String clientId) {
7480
this.policies = policies;
7581
this.protocolOptions = protocolOptions;
7682
this.poolingOptions = poolingOptions;
@@ -81,6 +87,9 @@ private Configuration(
8187
this.nettyOptions = nettyOptions;
8288
this.codecRegistry = codecRegistry;
8389
this.defaultKeyspace = defaultKeyspace;
90+
this.applicationName = applicationName;
91+
this.applicationVersion = applicationVersion;
92+
this.clientId = clientId;
8493
}
8594

8695
/**
@@ -99,7 +108,10 @@ protected Configuration(Configuration toCopy) {
99108
toCopy.getThreadingOptions(),
100109
toCopy.getNettyOptions(),
101110
toCopy.getCodecRegistry(),
102-
toCopy.getDefaultKeyspace());
111+
toCopy.getDefaultKeyspace(),
112+
toCopy.getApplicationName(),
113+
toCopy.getApplicationVersion(),
114+
toCopy.getClientId());
103115
}
104116

105117
void register(Cluster.Manager manager) {
@@ -213,6 +225,19 @@ public NettyOptions getNettyOptions() {
213225
public String getDefaultKeyspace() {
214226
return defaultKeyspace;
215227
}
228+
229+
public String getApplicationName() {
230+
return applicationName;
231+
}
232+
233+
public String getApplicationVersion() {
234+
return applicationVersion;
235+
}
236+
237+
public String getClientId() {
238+
return clientId;
239+
}
240+
216241
/**
217242
* Returns the {@link CodecRegistry} instance for this configuration.
218243
*
@@ -239,6 +264,42 @@ public static class Builder {
239264
private NettyOptions nettyOptions;
240265
private CodecRegistry codecRegistry;
241266
private String defaultKeyspace;
267+
private String applicationName;
268+
private String applicationVersion;
269+
private String clientId;
270+
271+
/**
272+
* Sets application name, to be reported to server
273+
*
274+
* @param applicationName application name.
275+
* @return this builder.
276+
*/
277+
public Builder withApplicationName(String applicationName) {
278+
this.applicationName = applicationName;
279+
return this;
280+
}
281+
282+
/**
283+
* Sets application version, to be reported to server
284+
*
285+
* @param applicationVersion application version.
286+
* @return this builder.
287+
*/
288+
public Builder withApplicationVersion(String applicationVersion) {
289+
this.applicationVersion = applicationVersion;
290+
return this;
291+
}
292+
293+
/**
294+
* Sets client id, to be reported to server
295+
*
296+
* @param clientId application version.
297+
* @return this builder.
298+
*/
299+
public Builder withClientId(String clientId) {
300+
this.clientId = clientId;
301+
return this;
302+
}
242303

243304
/**
244305
* Sets the policies for this cluster.
@@ -370,7 +431,10 @@ public Configuration build() {
370431
threadingOptions != null ? threadingOptions : new ThreadingOptions(),
371432
nettyOptions != null ? nettyOptions : NettyOptions.DEFAULT_INSTANCE,
372433
codecRegistry != null ? codecRegistry : CodecRegistry.DEFAULT_INSTANCE,
373-
defaultKeyspace);
434+
defaultKeyspace,
435+
applicationName,
436+
applicationVersion,
437+
clientId);
374438
}
375439
}
376440
}

driver-core/src/main/java/com/datastax/driver/core/Connection.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,20 @@ public ListenableFuture<Void> apply(Void input) throws Exception {
516516
logger.debug("Enabling tablet support in OPTIONS message");
517517
TabletInfo.addOption(extraOptions);
518518
}
519+
520+
if (factory.configuration.getApplicationName() != null
521+
&& !factory.configuration.getApplicationName().isEmpty()) {
522+
extraOptions.put("APPLICATION_NAME", factory.configuration.getApplicationName());
523+
}
524+
if (factory.configuration.getApplicationVersion() != null
525+
&& !factory.configuration.getApplicationVersion().isEmpty()) {
526+
extraOptions.put("APPLICATION_VERSION", factory.configuration.getApplicationVersion());
527+
}
528+
if (factory.configuration.getClientId() != null
529+
&& !factory.configuration.getClientId().isEmpty()) {
530+
extraOptions.put("CLIENT_ID", factory.configuration.getClientId());
531+
}
532+
519533
Future startupResponseFuture =
520534
write(
521535
new Requests.Startup(

0 commit comments

Comments
 (0)