本文整理汇总了Java中com.mongodb.MongoOptions类的典型用法代码示例。如果您正苦于以下问题:Java MongoOptions类的具体用法?Java MongoOptions怎么用?Java MongoOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MongoOptions类属于com.mongodb包,在下文中一共展示了MongoOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initMongo
import com.mongodb.MongoOptions; //导入依赖的package包/类
/**
* Intialize the mongo database connection
* @param mongoHost
* @param mongoPort
*/
public static Mongo initMongo(String mongoHost, int mongoPort) {
try {
ServerAddress address = new ServerAddress(mongoHost, mongoPort);
MongoOptions options = new MongoOptions();
options.autoConnectRetry = true;
options.connectionsPerHost = GlobalConfig.getInstance().getIntProperty("mongdb.connectionsPerHost");
options.connectTimeout = GlobalConfig.getInstance().getIntProperty("mongdb.connectTimeout");
options.maxWaitTime = GlobalConfig.getInstance().getIntProperty("mongdb.maxWaitTime");
options.socketTimeout = GlobalConfig.getInstance().getIntProperty("mongdb.socketTimeout");
options.threadsAllowedToBlockForConnectionMultiplier = GlobalConfig.getInstance().getIntProperty("mongdb.threadsAllowedToBlockForConnectionMultiplier");
Mongo mongo = new Mongo(address, options);
if ( logger.isInfoEnabled() ) {
logger.info("MongoDB initialized OK: host:{}", mongoHost);
}
refreshMongoDatabase(mongo);
return mongo;
} catch (Exception e) {
logger.info("Failed to open mongodb", e);
}
return null;
}
示例2: initCfgMongo
import com.mongodb.MongoOptions; //导入依赖的package包/类
/**
*
* @param mongoHost
* @param mongoPort
* @return
*/
public static Mongo initCfgMongo(String mongoHost, int mongoPort) {
try {
ServerAddress address = new ServerAddress(mongoHost, mongoPort);
MongoOptions options = new MongoOptions();
options.autoConnectRetry = true;
Mongo mongo = new Mongo(address, options);
if ( logger.isInfoEnabled() ) {
logger.info("MongoDB for cfg is initialized OK: host:{}", mongoHost);
}
for ( String cfgColl : CFG_COLL ) {
String key = StringUtil.concat(cfgNamespace, Constant.DOT, cfgColl);
if ( !mongoMap.containsKey(key) ) {
//Put it into our cache
mongoMap.put(key, mongo);
logger.debug("Put the cfg db mongo key: {} for server", key);
} else {
logger.warn("Key:{} is duplicate in mongo database", key);
}
}
return mongo;
} catch (Exception e) {
logger.info("Failed to open mongodb", e);
}
return null;
}
示例3: mongoFactory
import com.mongodb.MongoOptions; //导入依赖的package包/类
@Bean
public MongoFactoryBean mongoFactory() throws Exception {
MongoOptions mongoOptions = new MongoOptions();
mongoOptions.connectionsPerHost = connections;
MongoFactoryBean mongoFactoryBean = new MongoFactoryBean();
//check multiple urls for replica sets
if(isReplicaSet()) {
logger.debug("connecting to mongo replica sets");
mongoFactoryBean.setReplicaSetSeeds(getServerAddresses());
mongoOptions.autoConnectRetry = true;
mongoOptions.connectTimeout = connectionTimeout;
mongoOptions.socketTimeout = socketTimeout;
}
else {
logger.debug("connecting to mongo master-slave");
mongoFactoryBean.setHost(dbUrl);
}
mongoFactoryBean.setMongoOptions(mongoOptions);
return mongoFactoryBean;
}
示例4: setMongoParams
import com.mongodb.MongoOptions; //导入依赖的package包/类
/**
* Configure Mongo with the given config and open a connection, storing the DBCollection object statically.
* @param conf Hadoop configuration object.
*/
protected static void setMongoParams(Configuration conf) {
String host = conf.get(MONGO_HOST);
String db = conf.get(MONGO_DB_NAME);
String collection = conf.get(MONGO_COLL_NAME);
int port = Integer.parseInt(conf.get(MONGO_PORT));
try {
MongoOptions options = new MongoOptions();
options.autoConnectRetry = true;
options.connectTimeout = 10000; // timeout is 10s
options.connectionsPerHost = 50; // default is 10
options.threadsAllowedToBlockForConnectionMultiplier = 500; // default is 5
options.fsync = false; // don't wait for disk flush
options.w = 1; // ensure write to memory succeeded
Mongo mongo = new Mongo(new ServerAddress(host, port), options);
mongoColl = mongo.getDB(db).getCollection(collection);
}
catch (Exception e) {
throw new RuntimeException("Could not connect to mongo host " + host + ":" + port, e);
}
}
示例5: getMongoOptions
import com.mongodb.MongoOptions; //导入依赖的package包/类
private MongoOptions getMongoOptions(NaviPoolConfig poolConfig) {
if (poolConfig instanceof NaviMongoPoolConfig) {
return ((NaviMongoPoolConfig) poolConfig).getOptions();
}
MongoOptions options = new MongoOptions();
options.connectionsPerHost = poolConfig.getMaxActive();
options.connectTimeout = poolConfig.getConnectTimeout();
options.safe = true;
return options;
}
示例6: initUserMongo
import com.mongodb.MongoOptions; //导入依赖的package包/类
/**
* Intialize the mongo database connection
* @param mongoHost
* @param mongoPort
*/
public static Mongo initUserMongo(String mongoHost, int mongoPort) {
try {
ServerAddress address = new ServerAddress(mongoHost, mongoPort);
MongoOptions options = new MongoOptions();
options.autoConnectRetry = true;
options.connectionsPerHost = GlobalConfig.getInstance().getIntProperty("mongdb.connectionsPerHost");
options.connectTimeout = GlobalConfig.getInstance().getIntProperty("mongdb.connectTimeout");
options.maxWaitTime = GlobalConfig.getInstance().getIntProperty("mongdb.maxWaitTime");
options.socketTimeout = GlobalConfig.getInstance().getIntProperty("mongdb.socketTimeout");
options.threadsAllowedToBlockForConnectionMultiplier = GlobalConfig.getInstance().getIntProperty("mongdb.threadsAllowedToBlockForConnectionMultiplier");
Mongo mongo = new Mongo(address, options);
if ( logger.isInfoEnabled() ) {
logger.info("MongoDB for users is initialized OK: host:{}", mongoHost);
}
for ( String userColl : USER_COLL ) {
String key = StringUtil.concat(userNamespace, Constant.DOT, userColl);
if ( !mongoMap.containsKey(key) ) {
//Put it into our cache
mongoMap.put(key, mongo);
logger.debug("Put the user db mongo key: {} for server", key);
} else {
logger.warn("Key:{} is duplicate in mongo database", key);
}
}
return mongo;
} catch (Exception e) {
logger.info("Failed to open mongodb", e);
}
return null;
}
示例7: initUserMongo
import com.mongodb.MongoOptions; //导入依赖的package包/类
/**
* Intialize the mongo database connection
* @param mongoHost
* @param mongoPort
*/
public static Mongo initUserMongo(String mongoHost, int mongoPort) {
try {
ServerAddress address = new ServerAddress(mongoHost, mongoPort);
MongoOptions options = new MongoOptions();
options.autoConnectRetry = true;
options.connectionsPerHost = GlobalConfig.getInstance().getIntProperty("mongdb.connectionsPerHost");
options.connectTimeout = GlobalConfig.getInstance().getIntProperty("mongdb.connectTimeout");
options.maxWaitTime = GlobalConfig.getInstance().getIntProperty("mongdb.maxWaitTime");
options.socketTimeout = GlobalConfig.getInstance().getIntProperty("mongdb.socketTimeout");
options.threadsAllowedToBlockForConnectionMultiplier = GlobalConfig.getInstance().getIntProperty("mongdb.threadsAllowedToBlockForConnectionMultiplier");
Mongo mongo = new Mongo(address, options);
if ( logger.isInfoEnabled() ) {
logger.info("MongoDB for users is initialized OK: host:{}", mongoHost);
}
for ( String userColl : USER_COLL ) {
String key = StringUtil.concat(userNamespace, Constant.DOT, userColl);
if ( !mongoMap.containsKey(key) ) {
//Put it into our cache
mongoMap.put(key, mongo);
logger.debug("Put the user db mongo key: {} for server", key);
} else {
logger.warn("Key:{} is duplicate in mongo database", key);
}
if ( !mongoMap.containsKey("guildbagevents") ) {
}
}
return mongo;
} catch (Exception e) {
logger.info("Failed to open mongodb", e);
}
return null;
}
示例8: init
import com.mongodb.MongoOptions; //导入依赖的package包/类
/**
* Init the mongo instance
*
*/
private void init() {
try {
mongo = new Mongo(host, port);
MongoOptions options = mongo.getMongoOptions();
options.connectionsPerHost = poolSize;
options.threadsAllowedToBlockForConnectionMultiplier = blockSize;
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
示例9: mongoOptions
import com.mongodb.MongoOptions; //导入依赖的package包/类
@Override
public MongoOptions mongoOptions() {
MongoClientOptions mongoClientOptions = MongoClientOptions.builder()
.autoConnectRetry(true)
.connectionsPerHost(50)
.connectTimeout(1000 * 10)
.maxAutoConnectRetryTime(1000 * 60 * 30)
.socketFactory(mongoSocketFactory)
.socketKeepAlive(true)
.socketTimeout(1000 * 60)
.build();
return new MongoOptions(mongoClientOptions);
}
示例10: getDefaultMongoOptions
import com.mongodb.MongoOptions; //导入依赖的package包/类
public MongoOptions getDefaultMongoOptions() {
MongoClientOptions mongoClientOptions = MongoClientOptions.builder()
.autoConnectRetry(true)
.connectionsPerHost(50)
.connectTimeout(1000 * 10)
.maxAutoConnectRetryTime(1000 * 60 * 30)
.socketFactory(mongoSocketFactory)
.socketKeepAlive(true)
.socketTimeout(1000 * 60)
.build();
return new MongoOptions(mongoClientOptions);
}
示例11: mongoOptions
import com.mongodb.MongoOptions; //导入依赖的package包/类
/**
* MongoオペレーションをDIコンテナに登録します。
* @return Mongoオペレーション
*/
@Bean
public MongoOptions mongoOptions() {
MongoOptions options = new MongoOptions();
options.setConnectionsPerHost(connectionsPerHost);
options.setThreadsAllowedToBlockForConnectionMultiplier(threadAllowedToBlockForConnectionMultiplier);
options.setConnectTimeout(connectTimeout);
options.setMaxWaitTime(maxWaitTime);
options.setAutoConnectRetry(autoConnectRetry);
options.setSocketKeepAlive(socketKeepAlive);
options.setSocketTimeout(socketTimeout);
options.setFsync(fsync);
return options;
}
示例12: mongoOptions
import com.mongodb.MongoOptions; //导入依赖的package包/类
@Bean
public MongoOptions mongoOptions() {
MongoOptions result = new MongoOptions();
// adjust write concert for better performance
result.setWriteConcern(WriteConcern.UNACKNOWLEDGED);
return result;
}
示例13: getOptions
import com.mongodb.MongoOptions; //导入依赖的package包/类
public MongoOptions getOptions() {
return options;
}
示例14: setOptions
import com.mongodb.MongoOptions; //导入依赖的package包/类
public void setOptions(MongoOptions options) {
this.options = options;
}
示例15: afterPropertiesSet
import com.mongodb.MongoOptions; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public void afterPropertiesSet() throws Exception {
options = new MongoOptions();
/**
* 设置获取连接池句柄的最大等待时间s
*/
options.maxWaitTime = (int) getMaxWait();
/**
* 写安全设置,如果为true,驱动每次update后会发出一个getLastError命令来保证成功, If true the driver
* will use a WriteConcern of WriteConcern.SAFE for all operations.
*/
options.safe = isSafe();
/**
* 系统在发生连接错误时是否重试 ,默认为true
*/
options.autoConnectRetry = isAutoConnectRetry();
/**
* 自动重连时间间隔
*/
if (maxAutoConnectRetryTime != 0) {
options.maxAutoConnectRetryTime = getMaxAutoConnectRetryTime();
}
/**
* 设置最大线程阻塞数,乘数
*/
if (getMaxBlockingThread() != 0) {
options.threadsAllowedToBlockForConnectionMultiplier = getMaxBlockingThread();
}
/**
* 设置socket通讯超时时间
*/
if (getSocketTimeout() != 0) {
options.socketTimeout = getSocketTimeout();
System.setProperty("com.mongodb.updaterConnectTimeoutMS", String.valueOf(getSocketTimeout()));
}
/**
* 设置socket连接超时时间
*/
if (getConnectTimeout() != 0) {
options.connectTimeout = getConnectTimeout();
System.setProperty("com.mongodb.updaterSocketTimeoutMS", String.valueOf(getConnectTimeout()));
}
/**
* 设置连接池最大连接数
*/
if (getMaxActive() != 0) {
options.connectionsPerHost = getMaxActive();
}
options.slaveOk = isSlaveOk();
options.socketKeepAlive = isSocketKeepAlive();
}