Skip to content

Commit 8452be3

Browse files
author
Ryan
committed
changed all localhost examples to use 127.0.0.1. Localhost behaves strangely on some platforms.
1 parent 742d9c8 commit 8452be3

File tree

3 files changed

+81
-81
lines changed

3 files changed

+81
-81
lines changed

src/main/com/mongodb/Mongo.java

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
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
*
@@ -45,18 +45,18 @@
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
@@ -71,17 +71,17 @@
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 {

src/main/com/mongodb/MongoURI.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@
1313
public class MongoURI {
1414

1515
public static final String MONGODB_PREFIX = "mongodb://";
16-
16+
1717
/**
1818
* Creates a MongoURI described by a String.
1919
* examples
20-
* mongodb://localhost
21-
* mongodb://fred:foobar@localhost/
20+
* mongodb://127.0.0.1
21+
* mongodb://fred:foobar@127.0.0.1/
2222
* @param uri the URI
2323
* @dochub connections
2424
*/
2525
public MongoURI( String uri ){
2626
_uri = uri;
2727
if ( ! uri.startsWith( MONGODB_PREFIX ) )
2828
throw new IllegalArgumentException( "uri needs to start with " + MONGODB_PREFIX );
29-
29+
3030
uri = uri.substring(MONGODB_PREFIX.length());
31-
31+
3232
String serverPart;
3333
String nsPart;
3434
String optionsPart;
@@ -43,7 +43,7 @@ public MongoURI( String uri ){
4343
else {
4444
serverPart = uri.substring( 0 , idx );
4545
nsPart = uri.substring( idx + 1 );
46-
46+
4747
idx = nsPart.indexOf( "?" );
4848
if ( idx >= 0 ){
4949
optionsPart = nsPart.substring( idx + 1 );
@@ -52,14 +52,14 @@ public MongoURI( String uri ){
5252
else {
5353
optionsPart = null;
5454
}
55-
55+
5656
}
5757
}
58-
58+
5959
{ // _username,_password,_hosts
6060
List<String> all = new LinkedList<String>();
61-
62-
61+
62+
6363
if ( serverPart.indexOf( "@" ) > 0 ){
6464
int idx = serverPart.indexOf( "@" );
6565
_username = serverPart.substring( 0 , idx );
@@ -76,10 +76,10 @@ public MongoURI( String uri ){
7676

7777
for ( String s : serverPart.split( "," ) )
7878
all.add( s );
79-
79+
8080
_hosts = Collections.unmodifiableList( all );
8181
}
82-
82+
8383
if ( nsPart != null ){ // _database,_collection
8484
int idx = nsPart.indexOf( "." );
8585
if ( idx < 0 ){
@@ -141,7 +141,7 @@ boolean _parseBoolean( String _in ){
141141
public String getUsername(){
142142
return _username;
143143
}
144-
144+
145145
/**
146146
* Gets the password
147147
* @return
@@ -157,7 +157,7 @@ public char[] getPassword(){
157157
public List<String> getHosts(){
158158
return _hosts;
159159
}
160-
160+
161161
/**
162162
* Gets the database name
163163
* @return

0 commit comments

Comments
 (0)