/** * Creates a new {@code MongoOptions} with the given options. This class is deprecated, use {@link com.mongodb.MongoClientOptions}. * * @param options the MongoClientOptions to copy values from into the new MongoOptions. * @deprecated use {@link com.mongodb.MongoClientOptions} */ @SuppressWarnings("deprecation") @Deprecated public MongoOptions(final MongoClientOptions options) { connectionsPerHost = options.getConnectionsPerHost(); threadsAllowedToBlockForConnectionMultiplier = options.getThreadsAllowedToBlockForConnectionMultiplier(); maxWaitTime = options.getMaxWaitTime(); connectTimeout = options.getConnectTimeout(); socketFactory = options.getSocketFactory(); socketTimeout = options.getSocketTimeout(); socketKeepAlive = options.isSocketKeepAlive(); readPreference = options.getReadPreference(); dbDecoderFactory = options.getDbDecoderFactory(); dbEncoderFactory = options.getDbEncoderFactory(); description = options.getDescription(); writeConcern = options.getWriteConcern(); alwaysUseMBeans = options.isAlwaysUseMBeans(); requiredReplicaSetName = options.getRequiredReplicaSetName(); }
maxConnectionIdleTime = options.getMaxConnectionIdleTime(); maxConnectionLifeTime = options.getMaxConnectionLifeTime(); connectTimeout = options.getConnectTimeout(); socketTimeout = options.getSocketTimeout(); socketKeepAlive = options.isSocketKeepAlive();
.connectTimeout(getConnectTimeout(), MILLISECONDS) .readTimeout(getSocketTimeout(), MILLISECONDS) .keepAlive(isSocketKeepAlive())
/** * Connection time out in milli seconds for doing something in mongo. Zero is indefinite * * @return number representing milli seconds of timeout */ public int getConnectionTimeout() { return (connectionTimeout > 0) ? connectionTimeout : defaults.getConnectTimeout(); }
/** * Connection time out in milli seconds for doing something in mongo. Zero is indefinite * * @return number representing milli seconds of timeout */ public int getConnectionTimeout() { return (connectionTimeout > 0) ? connectionTimeout : defaults.getConnectTimeout(); }
Assert.assertEquals(32, options.getConnectTimeout());
Assert.assertEquals(32, options.getConnectTimeout());
public static String toString(MongoClientOptions opts) { return Objects.toStringHelper(opts) .add("connectionsPerHost", opts.getConnectionsPerHost()) .add("connectTimeout", opts.getConnectTimeout()) .add("socketTimeout", opts.getSocketTimeout()) .add("socketKeepAlive", opts.isSocketKeepAlive()) .add("maxWaitTime", opts.getMaxWaitTime()) .add("heartbeatFrequency", opts.getHeartbeatFrequency()) .add("threadsAllowedToBlockForConnectionMultiplier", opts.getThreadsAllowedToBlockForConnectionMultiplier()) .add("readPreference", opts.getReadPreference().getName()) .add("writeConcern", opts.getWriteConcern()) .toString(); }
public static String toString(MongoClientOptions opts) { return Objects.toStringHelper(opts) .add("connectionsPerHost", opts.getConnectionsPerHost()) .add("connectTimeout", opts.getConnectTimeout()) .add("socketTimeout", opts.getSocketTimeout()) .add("socketKeepAlive", opts.isSocketKeepAlive()) .add("maxWaitTime", opts.getMaxWaitTime()) .add("heartbeatFrequency", opts.getHeartbeatFrequency()) .add("threadsAllowedToBlockForConnectionMultiplier", opts.getThreadsAllowedToBlockForConnectionMultiplier()) .add("readPreference", opts.getReadPreference().getName()) .add("writeConcern", opts.getWriteConcern()) .toString(); }
@Override public Map<String, ?> properties(RequestContext ctx) throws Exception { Map properties = new HashMap<>(); properties.put(DESCRIPTION, mongoClientOptions.getDescription()); properties.put(CONNECTIONS_PER_HOST, mongoClientOptions.getConnectionsPerHost()); properties.put(THREADS_ALLOWED_TO_BLOCK_FOR_CONNECTION_MULTIPLIER, mongoClientOptions.getThreadsAllowedToBlockForConnectionMultiplier()); properties.put(MAX_WAIT_TIME, mongoClientOptions.getMaxWaitTime()); properties.put(CONNECT_TIMEOUT, mongoClientOptions.getConnectTimeout()); properties.put(SOCKET_KEEP_ALIVE, mongoClientOptions.isSocketKeepAlive()); properties.put(AUTOCONNECT_RETRY, mongoClientOptions.isAutoConnectRetry()); properties.put(MAX_AUTOCONNECT_RETRY_TIME, mongoClientOptions.getMaxAutoConnectRetryTime()); properties.put(CURSOR_FINALIZER_ENABLED, mongoClientOptions.isCursorFinalizerEnabled()); properties.put(ALWAYS_USE_MBEANS, mongoClientOptions.isAlwaysUseMBeans()); return properties; } }
protected MongoClient createMongoClient(MongoDBConfiguration config) { MongoClientOptions clientOptions = config.buildOptions(); List<MongoCredential> credentials = config.buildCredentials(); log.connectingToMongo( config.getHosts().toString(), clientOptions.getConnectTimeout() ); try { List<ServerAddress> serverAddresses = new ArrayList<>( config.getHosts().size() ); for ( Hosts.HostAndPort hostAndPort : config.getHosts() ) { serverAddresses.add( new ServerAddress( hostAndPort.getHost(), hostAndPort.getPort() ) ); } return credentials == null ? new MongoClient( serverAddresses, clientOptions ) : new MongoClient( serverAddresses, credentials, clientOptions ); } catch (RuntimeException e) { throw log.unableToInitializeMongoDB( e ); } }
protected MongoClient createMongoClient(MongoDBConfiguration config) { MongoClientOptions clientOptions = config.buildOptions(); List<MongoCredential> credentials = config.buildCredentials(); log.connectingToMongo( config.getHosts().toString(), clientOptions.getConnectTimeout() ); try { List<ServerAddress> serverAddresses = new ArrayList<>( config.getHosts().size() ); for ( Hosts.HostAndPort hostAndPort : config.getHosts() ) { serverAddresses.add( new ServerAddress( hostAndPort.getHost(), hostAndPort.getPort() ) ); } return credentials == null ? new MongoClient( serverAddresses, clientOptions ) : new MongoClient( serverAddresses, credentials, clientOptions ); } catch (RuntimeException e) { throw log.unableToInitializeMongoDB( e ); } }
/** * Uses the configured parameters to create a MongoOptions instance. * * @return MongoOptions instance based on the configured properties */ public MongoClientOptions createMongoOptions() { MongoClientOptions options = MongoClientOptions.builder() .connectionsPerHost(getConnectionsPerHost()) .connectTimeout(getConnectionTimeout()) .maxWaitTime(getMaxWaitTime()) .threadsAllowedToBlockForConnectionMultiplier(getThreadsAllowedToBlockForConnectionMultiplier()) .socketTimeout(getSocketTimeOut()).build(); if (logger.isDebugEnabled()) { logger.debug("Mongo Options"); logger.debug("Connections per host :{}", options.getConnectionsPerHost()); logger.debug("Connection timeout : {}", options.getConnectTimeout()); logger.debug("Max wait timeout : {}", options.getMaxWaitTime()); logger.debug("Threads allowed to block : {}", options.getThreadsAllowedToBlockForConnectionMultiplier()); logger.debug("Socket timeout : {}", options.getSocketTimeout()); } return options; }
/** * Uses the configured parameters to create a MongoOptions instance. * * @return MongoOptions instance based on the configured properties */ public MongoClientOptions createMongoOptions() { MongoClientOptions options = MongoClientOptions.builder() .connectionsPerHost(getConnectionsPerHost()) .connectTimeout(getConnectionTimeout()) .maxWaitTime(getMaxWaitTime()) .threadsAllowedToBlockForConnectionMultiplier(getThreadsAllowedToBlockForConnectionMultiplier()) .socketTimeout(getSocketTimeOut()).build(); if (logger.isDebugEnabled()) { logger.debug("Mongo Options"); logger.debug("Connections per host :{}", options.getConnectionsPerHost()); logger.debug("Connection timeout : {}", options.getConnectTimeout()); logger.debug("Max wait timeout : {}", options.getMaxWaitTime()); logger.debug("Threads allowed to block : {}", options.getThreadsAllowedToBlockForConnectionMultiplier()); logger.debug("Socket timeout : {}", options.getSocketTimeout()); } return options; }
/** * Creates a new {@code MongoOptions} with the given options. This class is deprecated, use {@link com.mongodb.MongoClientOptions}. * * @param options the MongoClientOptions to copy values from into the new MongoOptions. * @deprecated use {@link com.mongodb.MongoClientOptions} */ @SuppressWarnings("deprecation") @Deprecated public MongoOptions(final MongoClientOptions options) { connectionsPerHost = options.getConnectionsPerHost(); threadsAllowedToBlockForConnectionMultiplier = options.getThreadsAllowedToBlockForConnectionMultiplier(); maxWaitTime = options.getMaxWaitTime(); connectTimeout = options.getConnectTimeout(); socketFactory = options.getSocketFactory(); socketTimeout = options.getSocketTimeout(); socketKeepAlive = options.isSocketKeepAlive(); readPreference = options.getReadPreference(); dbDecoderFactory = options.getDbDecoderFactory(); dbEncoderFactory = options.getDbEncoderFactory(); description = options.getDescription(); writeConcern = options.getWriteConcern(); alwaysUseMBeans = options.isAlwaysUseMBeans(); requiredReplicaSetName = options.getRequiredReplicaSetName(); }
maxConnectionIdleTime = options.getMaxConnectionIdleTime(); maxConnectionLifeTime = options.getMaxConnectionLifeTime(); connectTimeout = options.getConnectTimeout(); socketTimeout = options.getSocketTimeout(); socketKeepAlive = options.isSocketKeepAlive();
.connectTimeout(getConnectTimeout(), MILLISECONDS) .readTimeout(getSocketTimeout(), MILLISECONDS) .keepAlive(isSocketKeepAlive())