[JAVA-780] Expose MongoClientURI constructor for overriding default options Created: 07/Mar/13  Updated: 19/Mar/13  Resolved: 09/Mar/13

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: 2.10.1
Fix Version/s: 2.11.0

Type: Improvement Priority: Major - P3
Reporter: John Morales Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by JAVA-784 Allow merge of options from URI and o... Closed

 Description   

Overview: Making a case for this constructor to be public:

https://github.com/mongodb/mongo-java-driver/blob/1d2e6faa80aeb5287a26d0348f18f4b51d566759/src/main/com/mongodb/MongoClientURI.java#L162

Within the MMS server implementation, we have a use case where MongoDB connections are configured via MongoURIs. And, we have application-specific default options that want to take precedence over the driver defaults.

In the past, this was easy enough since MongoURI and MongoOptions were both mutable. However now that MongoClientURI and MongoClientOptions are both immutable, I'm struggling for how to implement the same behavior without going through a deprecated alternative.

Fwiw, it appears that what I'm looking for exactly is the package private constructor linked above, which would allow me to specify my own set of default options.

(Encountered using 2.11.0-SNAPSHOT at githash 1d2e6faa80aeb5287a26d0348f18f4b51d566759, but looks unchanged on master.)

Thanks!



 Comments   
Comment by John Morales [ 11/Mar/13 ]

Awesome - thank you! Will try out this snapshot.

Comment by Jeffrey Yemin [ 09/Mar/13 ]

Snapshot available: https://oss.sonatype.org/content/repositories/snapshots/org/mongodb/mongo-java-driver/2.11.0-SNAPSHOT/mongo-java-driver-2.11.0-20130309.221945-6.jar

Comment by Jeffrey Yemin [ 09/Mar/13 ]

Constructor is public

Comment by auto [ 09/Mar/13 ]

Author:

{u'date': u'2013-03-09T22:14:03Z', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-780: Made MongoClientURI constructor that takes a MongoClientOptions.Builder public
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/0cd926a386b83de5fe475c73e0fbff3064526998

Comment by Benson Margulies [ 09/Mar/13 ]

As I see it, the behavior of the constructor is what's nice. For example, one could turn autoconnectretry on in the options, and that would persist unless the URI asked otherwise.

Comment by John Morales [ 07/Mar/13 ]

Yes. But I mean if any options are specified on the URI, then that will be a conflict under that definition, right? Because the default builder/options has a 'value' for everything, no?

The scenario is only that I'm specifying an alternative set of default options, which are overwritten by any option specified on the URI.

Comment by Jeffrey Yemin [ 07/Mar/13 ]

in your use case, are there actually conflicts between them? Are you specifying anything on URI that is also in options?

Comment by John Morales [ 07/Mar/13 ]

I am in fact expecting the URI params to win. The thinking being that if the option's on the URI, then that's an explicit choice made by the client/user so it should be respected. It's only for options not explicitly specified that I'd like this alternate set of default options to be used in lieu of driver defaults.

Having options win is to say ignore/overwrite anything settings the user specified on the URI, which is not the case we're looking for, but I suppose could be useful generally?

Comment by Jeffrey Yemin [ 07/Mar/13 ]

Do you care about conflicts between the URI and the options, and if so, who would you want to win? With this approach the URI will win, which I think is backwards. Another option is to provide a MongoClient constructor that takes both a URI and options, and merge the two, with options winning.

Generated at Thu Feb 08 08:53:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.