@@ -88,6 +88,7 @@ public class MongoConnection implements Connection {
8888 private String logDirPath ;
8989 private boolean extJsonMode ;
9090 private UuidRepresentation uuidRepresentation ;
91+ private String appName ;
9192
9293 public MongoConnection (
9394 MongoClient mongoClient , MongoConnectionProperties connectionProperties ) {
@@ -104,7 +105,13 @@ public MongoConnection(
104105 this .mongoClientSettings = createMongoClientSettings (connectionProperties );
105106
106107 if (mongoClient == null ) {
107- this .mongoClient = createMongoClient (connectionProperties );
108+ this .mongoClient =
109+ MongoClients .create (
110+ this .mongoClientSettings ,
111+ MongoDriverInformation .builder ()
112+ .driverName (MongoDriver .NAME )
113+ .driverVersion (MongoDriver .getVersion ())
114+ .build ());
108115 } else {
109116 this .mongoClient = mongoClient ;
110117 }
@@ -121,44 +128,32 @@ private void initializeConnection(MongoConnectionProperties connectionProperties
121128 this .extJsonMode = connectionProperties .getExtJsonMode ();
122129 this .uuidRepresentation =
123130 connectionProperties .getConnectionString ().getUuidRepresentation ();
131+ this .appName = buildAppName (connectionProperties );
124132
125133 this .isClosed = false ;
126134 }
127135
128- private MongoClient createMongoClient (MongoConnectionProperties connectionProperties ) {
129- StringBuilder appName =
136+ private String buildAppName (MongoConnectionProperties connectionProperties ) {
137+ StringBuilder appNameBuilder =
130138 new StringBuilder (MongoDriver .NAME ).append ("+" ).append (MongoDriver .getVersion ());
131139
132- MongoDriverInformation .Builder mdiBuilder ;
133140 String clientInfo = connectionProperties .getClientInfo ();
134- String [] clientInfoSplit = (clientInfo == null ) ? null : clientInfo .split ("\\ +" );
135- if (clientInfoSplit != null && clientInfoSplit .length == 2 ) {
136- appName .append ('|' ).append (clientInfo );
137- MongoDriverInformation driverInfoWithClientInfo =
138- MongoDriverInformation .builder ()
139- .driverName (clientInfoSplit [0 ])
140- .driverVersion (clientInfoSplit [1 ])
141- .build ();
142- mdiBuilder = MongoDriverInformation .builder (driverInfoWithClientInfo );
143- } else {
144- mdiBuilder = MongoDriverInformation .builder ();
141+ if (clientInfo != null ) {
142+ String [] clientInfoSplit = clientInfo .split ("\\ +" );
143+ if (clientInfoSplit .length == 2 ) {
144+ appNameBuilder .append ('|' ).append (clientInfo );
145+ }
145146 }
146- MongoDriverInformation mongoDriverInformation =
147- mdiBuilder
148- .driverName (MongoDriver .NAME )
149- .driverVersion (MongoDriver .getVersion ())
150- .build ();
151147
152- return MongoClients . create ( this . mongoClientSettings , mongoDriverInformation );
148+ return appNameBuilder . toString ( );
153149 }
154150
155151 private MongoClientSettings createMongoClientSettings (
156152 MongoConnectionProperties connectionProperties ) {
157- String appName = MongoDriver .NAME + "+" + MongoDriver .getVersion ();
158153
159154 MongoClientSettings .Builder settingsBuilder =
160155 MongoClientSettings .builder ()
161- .applicationName (appName )
156+ .applicationName (this . appName )
162157 .applyConnectionString (connectionProperties .getConnectionString ());
163158
164159 MongoCredential credential = connectionProperties .getConnectionString ().getCredential ();
0 commit comments