Skip to content

Commit 56fddc5

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 56fddc5

File tree

3 files changed

+113
-3
lines changed

3 files changed

+113
-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: 69 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,11 @@ 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
80+
) {
7481
this.policies = policies;
7582
this.protocolOptions = protocolOptions;
7683
this.poolingOptions = poolingOptions;
@@ -81,6 +88,9 @@ private Configuration(
8188
this.nettyOptions = nettyOptions;
8289
this.codecRegistry = codecRegistry;
8390
this.defaultKeyspace = defaultKeyspace;
91+
this.applicationName = applicationName;
92+
this.applicationVersion = applicationVersion;
93+
this.clientId = clientId;
8494
}
8595

8696
/**
@@ -99,7 +109,10 @@ protected Configuration(Configuration toCopy) {
99109
toCopy.getThreadingOptions(),
100110
toCopy.getNettyOptions(),
101111
toCopy.getCodecRegistry(),
102-
toCopy.getDefaultKeyspace());
112+
toCopy.getDefaultKeyspace(),
113+
toCopy.getApplicationName(),
114+
toCopy.getApplicationVersion(),
115+
toCopy.getClientId());
103116
}
104117

105118
void register(Cluster.Manager manager) {
@@ -213,6 +226,19 @@ public NettyOptions getNettyOptions() {
213226
public String getDefaultKeyspace() {
214227
return defaultKeyspace;
215228
}
229+
230+
public String getApplicationName() {
231+
return applicationName;
232+
}
233+
234+
public String getApplicationVersion() {
235+
return applicationVersion;
236+
}
237+
238+
public String getClientId() {
239+
return clientId;
240+
}
241+
216242
/**
217243
* Returns the {@link CodecRegistry} instance for this configuration.
218244
*
@@ -239,6 +265,42 @@ public static class Builder {
239265
private NettyOptions nettyOptions;
240266
private CodecRegistry codecRegistry;
241267
private String defaultKeyspace;
268+
private String applicationName;
269+
private String applicationVersion;
270+
private String clientId;
271+
272+
/**
273+
* Sets application name, to be reported to server
274+
*
275+
* @param applicationName application name.
276+
* @return this builder.
277+
*/
278+
public Builder withApplicationName(String applicationName) {
279+
this.applicationName = applicationName;
280+
return this;
281+
}
282+
283+
/**
284+
* Sets application version, to be reported to server
285+
*
286+
* @param applicationVersion application version.
287+
* @return this builder.
288+
*/
289+
public Builder withApplicationVersion(String applicationVersion) {
290+
this.applicationVersion = applicationVersion;
291+
return this;
292+
}
293+
294+
/**
295+
* Sets client id, to be reported to server
296+
*
297+
* @param clientId application version.
298+
* @return this builder.
299+
*/
300+
public Builder withClientId(String clientId) {
301+
this.clientId = clientId;
302+
return this;
303+
}
242304

243305
/**
244306
* Sets the policies for this cluster.
@@ -370,7 +432,11 @@ public Configuration build() {
370432
threadingOptions != null ? threadingOptions : new ThreadingOptions(),
371433
nettyOptions != null ? nettyOptions : NettyOptions.DEFAULT_INSTANCE,
372434
codecRegistry != null ? codecRegistry : CodecRegistry.DEFAULT_INSTANCE,
373-
defaultKeyspace);
435+
defaultKeyspace,
436+
applicationName,
437+
applicationVersion,
438+
clientId
439+
);
374440
}
375441
}
376442
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,17 @@ 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 && !factory.configuration.getApplicationName().isEmpty()) {
521+
extraOptions.put("APPLICATION_NAME", factory.configuration.getApplicationName());
522+
}
523+
if (factory.configuration.getApplicationVersion() != null && !factory.configuration.getApplicationVersion().isEmpty()) {
524+
extraOptions.put("APPLICATION_VERSION", factory.configuration.getApplicationVersion());
525+
}
526+
if (factory.configuration.getClientId() != null && !factory.configuration.getClientId().isEmpty()) {
527+
extraOptions.put("CLIENT_ID", factory.configuration.getClientId());
528+
}
529+
519530
Future startupResponseFuture =
520531
write(
521532
new Requests.Startup(

0 commit comments

Comments
 (0)