Created
February 11, 2012 23:49
-
-
Save dieu/1805173 to your computer and use it in GitHub Desktop.
Path for mongo-java-driver 2.5.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mongodb; | |
import com.mongodb.DBTCPConnector; | |
import com.mongodb.Mongo; | |
import com.mongodb.MongoURI; | |
import com.mongodb.ServerAddress; | |
import java.net.UnknownHostException; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.ConcurrentHashMap; | |
import java.util.concurrent.ConcurrentMap; | |
/** | |
* @author Anton Panasenko | |
*/ | |
public class MongoConnect extends Mongo { | |
final ServerAddress _addr; | |
final List<ServerAddress> _addrs; | |
final MongoOptions _options; | |
final DBTCPConnector _connector; | |
final ConcurrentMap<String,DB> _dbs = new ConcurrentHashMap<String,DB>(); | |
private WriteConcern _concern = WriteConcern.NORMAL; | |
final Bytes.OptionHolder _netOptions = new Bytes.OptionHolder( null ); | |
final DBCleanerThread _cleaner; | |
public MongoConnect(MongoURI uri, int port) throws UnknownHostException { | |
_options = uri.getOptions(); | |
_applyMongoOptions(); | |
if ( uri.getHosts().size() == 1 ){ | |
_addr = new ServerAddress( uri.getHosts().get(0) , port); | |
_addrs = null; | |
_connector = new DBTCPConnector( this , _addr ); | |
} | |
else { | |
List<ServerAddress> replicaSetSeeds = new ArrayList<ServerAddress>( uri.getHosts().size() ); | |
for ( String host : uri.getHosts() ) | |
replicaSetSeeds.add( new ServerAddress( host ) ); | |
_addr = null; | |
_addrs = replicaSetSeeds; | |
_connector = new DBTCPConnector( this , replicaSetSeeds ); | |
} | |
_cleaner = new DBCleanerThread(); | |
_cleaner.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment