Java 类com.mongodb.MongoOptions 实例源码

项目:gameserver    文件:MongoUtil.java   
/**
 * 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;
}
项目:gameserver    文件:MongoUtil.java   
/**
 * 
 * @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;
}
项目:gameserver    文件:MongoDBUtil.java   
/**
 * 
 * @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;
}
项目:SimpleJavaWS    文件:MongoConfiguration.java   
@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;
}
项目:mongo-deep-mapreduce    文件:MongoInsertOutputFormat.java   
/**
 * 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);
    }
}
项目:navi    文件:NaviMongoDriver.java   
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;
}
项目:navi    文件:NaviMongoListDriver.java   
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;
}
项目:gameserver    文件:MongoUtil.java   
/**
 * 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;
}
项目:gameserver    文件:MongoDBUtil.java   
/**
 * 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;
}
项目:ODataSync    文件:MongoManager.java   
/**
 * 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();
    }
}
项目:mongo-rest    文件:DefaultMongoConfig.java   
@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);
}
项目:mongo-rest    文件:MongoConfig.java   
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);
}
项目:rack-java    文件:RackMongoContextConfig.java   
/**
 * 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;
}
项目:mongodb-aggregation    文件:Config.java   
@Bean
public MongoOptions mongoOptions() {
    MongoOptions result = new MongoOptions();
    // adjust write concert for better performance
    result.setWriteConcern(WriteConcern.UNACKNOWLEDGED);
    return result;
}
项目:navi    文件:NaviMongoPoolConfig.java   
public MongoOptions getOptions() {
    return options;
}
项目:navi    文件:NaviMongoPoolConfig.java   
public void setOptions(MongoOptions options) {
    this.options = options;
}
项目:navi    文件:NaviMongoPoolConfig.java   
@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();
}
项目:mongo-migrations    文件:MongoConnectionSettings.java   
public MongoOptions getOptions() {
    return options;
}
项目:mongo-migrations    文件:MongoConnectionSettings.java   
public void setOptions(MongoOptions options) {
    this.options = options;
}
项目:mongo-rest    文件:ExampleMongoConfig.java   
@Override
@Bean
public MongoOptions mongoOptions() {
    return getDefaultMongoOptions();
}
项目:mongo-rest    文件:ExampleMockMongoConfig.java   
@Bean
@Override
public MongoOptions mongoOptions() {
    return getDefaultMongoOptions();
}
项目:watermelon    文件:MongoFactoryBean.java   
public MongoOptions getMongoOptions() {
    return mongoOptions;
}
项目:watermelon    文件:MongoFactoryBean.java   
public void setMongoOptions(MongoOptions mongoOptions) {
    this.mongoOptions = mongoOptions;
}
项目:mongo-rest    文件:MongoConfig.java   
public abstract MongoOptions mongoOptions();