2828/**
2929 * A database connection with internal pooling.
3030 * For most application, you should have 1 Mongo instance for the entire JVM.
31- *
31+ *
3232 * The following are equivalent, and all connect to the
3333 * local database running on the default port:
3434 *
4545 *
4646 * <h3>Connecting to a Replica Pair</h3>
4747 * <p>
48- * You can connect to a
48+ * You can connect to a
4949 * <a href="http://www.mongodb.org/display/DOCS/Replica+Pairs">replica pair</a>
5050 * using the Java driver by passing two DBAddresses to the Mongo constructor.
5151 * For example:
5252 * </p>
5353 * <blockquote><pre>
54- * DBAddress left = new DBAddress("localhost :27017/test");
55- * DBAddress right = new DBAddress("localhost :27018/test");
54+ * DBAddress left = new DBAddress("127.0.0.1 :27017/test");
55+ * DBAddress right = new DBAddress("127.0.0.1 :27018/test");
5656 *
5757 * Mongo mongo = new Mongo(left, right);
5858 * </pre></blockquote>
59- *
59+ *
6060 * <p>
6161 * If the master of a replica pair goes down, there will be a brief lag before
6262 * the slave becomes master. Thus, your application should be prepared to catch
7171 *
7272 * <h3>Connecting to a Replica Set</h3>
7373 * <p>
74- * You can connect to a
74+ * You can connect to a
7575 * <a href="http://www.mongodb.org/display/DOCS/Replica+Sets">replica set</a>
7676 * using the Java driver by passing several a list if ServerAddress to the
7777 * Mongo constructor.
7878 * For example:
7979 * </p>
8080 * <blockquote><pre>
8181 * List<ServerAddress> addrs = new ArrayList<ServerAddress>();
82- * addrs.add( new ServerAddress( "localhost " , 27017 ) );
83- * addrs.add( new ServerAddress( "localhost " , 27018 ) );
84- * addrs.add( new ServerAddress( "localhost " , 27019 ) );
82+ * addrs.add( new ServerAddress( "127.0.0.1 " , 27017 ) );
83+ * addrs.add( new ServerAddress( "127.0.0.1 " , 27018 ) );
84+ * addrs.add( new ServerAddress( "127.0.0.1 " , 27019 ) );
8585 *
8686 * Mongo mongo = new Mongo( addrs );
8787 * </pre></blockquote>
@@ -198,7 +198,7 @@ public Mongo( ServerAddress addr , MongoOptions options )
198198 * <p>Creates a Mongo in paired mode. <br/> This will also work for
199199 * a replica set and will find all members (the master will be used by
200200 * default).</p>
201- *
201+ *
202202 * @see com.mongodb.ServerAddress
203203 * @param left left side of the pair
204204 * @param right right side of the pair
@@ -213,7 +213,7 @@ public Mongo( ServerAddress left , ServerAddress right )
213213 * <p>Creates a Mongo connection in paired mode. <br/> This will also work for
214214 * a replica set and will find all members (the master will be used by
215215 * default).</p>
216- *
216+ *
217217 * @see com.mongodb.ServerAddress
218218 * @param left left side of the pair
219219 * @param right right side of the pair
@@ -249,14 +249,14 @@ public Mongo( List<ServerAddress> replicaSetSeeds )
249249 * <p>Creates a Mongo based on a replica set, or pair.
250250 * It will find all members (the master will be used by default).</p>
251251 * @see com.mongodb.ServerAddress
252- * @param replicaSetSeeds put as many servers as you can in the list.
252+ * @param replicaSetSeeds put as many servers as you can in the list.
253253 * the system will figure the rest out
254254 * @param options default query options
255255 * @throws MongoException
256- */
256+ */
257257 public Mongo ( List <ServerAddress > replicaSetSeeds , MongoOptions options )
258258 throws MongoException {
259-
259+
260260 _addr = null ;
261261 _addrs = replicaSetSeeds ;
262262 _options = options ;
@@ -273,20 +273,20 @@ public Mongo( List<ServerAddress> replicaSetSeeds , MongoOptions options )
273273 * @param uri
274274 * @see MongoURI
275275 * <p>examples:
276- * <li>mongodb://localhost </li>
277- * <li>mongodb://fred:foobar@localhost /</li>
276+ * <li>mongodb://127.0.0.1 </li>
277+ * <li>mongodb://fred:foobar@127.0.0.1 /</li>
278278 * </p>
279279 * @throws MongoException
280280 * @throws UnknownHostException
281281 * @dochub connections
282- */
282+ */
283283
284284 public Mongo ( MongoURI uri )
285285 throws MongoException , UnknownHostException {
286286
287287 _options = uri .getOptions ();
288288 _applyMongoOptions ();
289-
289+
290290 if ( uri .getHosts ().size () == 1 ){
291291 _addr = new ServerAddress ( uri .getHosts ().get (0 ) );
292292 _addrs = null ;
@@ -311,11 +311,11 @@ public Mongo( MongoURI uri )
311311 * @return
312312 */
313313 public DB getDB ( String dbname ){
314-
314+
315315 DB db = _dbs .get ( dbname );
316316 if ( db != null )
317317 return db ;
318-
318+
319319 db = new DBApiLayer ( this , dbname , _connector );
320320 DB temp = _dbs .putIfAbsent ( dbname , db );
321321 if ( temp != null )
@@ -342,7 +342,7 @@ public List<String> getDatabaseNames()
342342
343343 BasicDBObject cmd = new BasicDBObject ();
344344 cmd .put ("listDatabases" , 1 );
345-
345+
346346
347347 BasicDBObject res = (BasicDBObject )getDB ( "admin" ).command (cmd , getOptions ());
348348
@@ -367,7 +367,7 @@ public List<String> getDatabaseNames()
367367 */
368368 public void dropDatabase (String dbName )
369369 throws MongoException {
370-
370+
371371 getDB ( dbName ).dropDatabase ();
372372 }
373373
@@ -480,7 +480,7 @@ public void setOptions( int options ){
480480 public void resetOptions (){
481481 _netOptions .reset ();
482482 }
483-
483+
484484 /**
485485 * gets the default query options
486486 * @return
@@ -510,26 +510,26 @@ DBTCPConnector getConnector() {
510510 private WriteConcern _concern = WriteConcern .NORMAL ;
511511 final Bytes .OptionHolder _netOptions = new Bytes .OptionHolder ( null );
512512 final DBCleanerThread _cleaner ;
513-
514- org .bson .util .SimplePool <PoolOutputBuffer > _bufferPool =
513+
514+ org .bson .util .SimplePool <PoolOutputBuffer > _bufferPool =
515515 new org .bson .util .SimplePool <PoolOutputBuffer >( 1000 ){
516-
516+
517517 protected PoolOutputBuffer createNew (){
518518 return new PoolOutputBuffer ();
519519 }
520-
520+
521521 };
522522
523523
524- // -------
524+ // -------
525+
525526
526-
527527 /**
528528 * Mongo.Holder can be used as a static place to hold several instances of Mongo.
529529 * Security is not enforced at this level, and needs to be done on the application side.
530530 */
531531 public static class Holder {
532-
532+
533533 /**
534534 * Attempts to find an existing Mongo instance matching that URI in the holder, and returns it if exists.
535535 * Otherwise creates a new Mongo instance based on this URI and adds it to the holder.
@@ -542,19 +542,19 @@ public Mongo connect( MongoURI uri )
542542 throws MongoException , UnknownHostException {
543543
544544 String key = _toKey ( uri );
545-
545+
546546 Mongo m = _mongos .get (key );
547547 if ( m != null )
548548 return m ;
549549
550550 m = new Mongo ( uri );
551-
551+
552552 Mongo temp = _mongos .putIfAbsent ( key , m );
553553 if ( temp == null ){
554554 // ours got in
555555 return m ;
556556 }
557-
557+
558558 // there was a race and we lost
559559 // close ours and return the other one
560560 m .close ();
@@ -570,9 +570,9 @@ String _toKey( MongoURI uri ){
570570 return buf .toString ();
571571 }
572572
573-
573+
574574 private static final ConcurrentMap <String ,Mongo > _mongos = new ConcurrentHashMap <String ,Mongo >();
575-
575+
576576 }
577577
578578 class DBCleanerThread extends Thread {
0 commit comments