Refine search
/** * Creates a Mongo instance based on a (single) mongodb node and a list of credentials * * @param addr the database address * @param credentialsList the list of credentials used to authenticate all connections * @see com.mongodb.ServerAddress * @since 2.11.0 * @deprecated Prefer {@link #MongoClient(ServerAddress, MongoCredential, MongoClientOptions)} */ @Deprecated public MongoClient(final ServerAddress addr, final List<MongoCredential> credentialsList) { this(addr, credentialsList, MongoClientOptions.builder().build()); }
description = options.getDescription(); applicationName = options.getApplicationName(); compressorList = options.getCompressorList(); minConnectionsPerHost = options.getMinConnectionsPerHost(); maxConnectionsPerHost = options.getConnectionsPerHost(); threadsAllowedToBlockForConnectionMultiplier = options.getThreadsAllowedToBlockForConnectionMultiplier(); serverSelectionTimeout = options.getServerSelectionTimeout(); maxWaitTime = options.getMaxWaitTime(); maxConnectionIdleTime = options.getMaxConnectionIdleTime(); maxConnectionLifeTime = options.getMaxConnectionLifeTime(); connectTimeout = options.getConnectTimeout(); socketTimeout = options.getSocketTimeout(); socketKeepAlive = options.isSocketKeepAlive(); readPreference = options.getReadPreference(); writeConcern = options.getWriteConcern(); retryWrites = options.getRetryWrites(); readConcern = options.getReadConcern(); codecRegistry = options.getCodecRegistry(); serverSelector = options.getServerSelector(); sslEnabled = options.isSslEnabled(); sslInvalidHostNameAllowed = options.isSslInvalidHostNameAllowed(); sslContext = options.getSslContext(); alwaysUseMBeans = options.isAlwaysUseMBeans(); heartbeatFrequency = options.getHeartbeatFrequency(); minHeartbeatFrequency = options.getMinHeartbeatFrequency(); heartbeatConnectTimeout = options.getHeartbeatConnectTimeout(); heartbeatSocketTimeout = options.getHeartbeatSocketTimeout(); localThreshold = options.getLocalThreshold(); requiredReplicaSetName = options.getRequiredReplicaSetName();
/** * 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(); }
.minSize(getMinConnectionsPerHost()) .maxSize(getConnectionsPerHost()) .maxWaitQueueSize(getThreadsAllowedToBlockForConnectionMultiplier() * getConnectionsPerHost()) .maxWaitTime(getMaxWaitTime(), MILLISECONDS) .maxConnectionIdleTime(getMaxConnectionIdleTime(), MILLISECONDS) .maxConnectionLifeTime(getMaxConnectionLifeTime(), MILLISECONDS); .connectTimeout(getConnectTimeout(), MILLISECONDS) .readTimeout(getSocketTimeout(), MILLISECONDS) .keepAlive(isSocketKeepAlive()) .build(); heartbeatSocketSettings = SocketSettings.builder() .connectTimeout(getHeartbeatConnectTimeout(), MILLISECONDS) .readTimeout(getHeartbeatSocketTimeout(), MILLISECONDS) .keepAlive(isSocketKeepAlive()) .build(); .heartbeatFrequency(getHeartbeatFrequency(), MILLISECONDS) .minHeartbeatFrequency(getMinHeartbeatFrequency(), MILLISECONDS);
/** * 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; }
/** * Returns {@code true} if the given {@code uri} has a write concern set. * @param uri the URI to check. * @return {@code true} if the URI has a write concern set, {@code false} * otherwise. */ public static boolean hasWriteConcern(@NotNull String uri) { MongoClientOptions.Builder builder = MongoClientOptions.builder(); builder.writeConcern(WC_UNKNOWN); WriteConcern wc = new MongoClientURI(checkNotNull(uri), builder) .getOptions().getWriteConcern(); return !WC_UNKNOWN.equals(wc); }
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(); }
Assert.assertEquals(WriteConcern.NORMAL, options.getWriteConcern()); WriteConcern wc = options.getWriteConcern(); Assert.assertEquals(0, wc.getW()); Assert.assertEquals(1000, wc.getWtimeout()); Assert.assertEquals(LazyDBDecoder.FACTORY, options.getDbDecoderFactory()); Assert.assertEquals(TestDBDecoderFactory.class, options.getDbDecoderFactory().getClass()); Assert.assertEquals(TestDBEncoderFactory.class, options.getDbEncoderFactory().getClass()); Assert.assertEquals(INSECURE_SSL_SOCKET_FACTORY, options.getSocketFactory()); Assert.assertEquals(SSLSocketFactory.getDefault().getClass(), options.getSocketFactory().getClass()); Assert.assertEquals(7, options.getConnectionsPerHost()); Assert.assertEquals(32, options.getConnectTimeout()); Assert.assertEquals(41, options.getMaxWaitTime()); Assert.assertEquals(3, options.getThreadsAllowedToBlockForConnectionMultiplier());
@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; } }
public static void assertConfigProperties(MongoDbFactory connector, String writeConcern, Integer connectionsPerHost, Integer maxWaitTime) { if (connectionsPerHost == null) { connectionsPerHost = 100; // default } if (maxWaitTime == null) { maxWaitTime = 120000; // default } assertNotNull(connector); assertEquals(ReflectionTestUtils.getField(connector, "writeConcern"), writeConcern == null ? null : WriteConcern.valueOf(writeConcern)); MongoClient mongoClient = (MongoClient) ReflectionTestUtils.getField(connector, "mongoClient"); assertEquals(connectionsPerHost.intValue(), mongoClient.getMongoClientOptions().getConnectionsPerHost()); assertEquals(maxWaitTime.intValue(), mongoClient.getMongoClientOptions().getMaxWaitTime()); }
mo = b.build(); if (mo.getConnectionsPerHost() <= 0 && !StringUtils.isEmpty(poolSize)) mo = b.connectionsPerHost(Integer.parseInt(poolSize)).build();
/** * 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(); }
/** * get the maximum time a blocked thread that waits for a connection should wait. * * @return number of milli seconds the thread waits for a connection */ public int getMaxWaitTime() { return (maxWaitTime > 0) ? maxWaitTime : defaults.getMaxWaitTime(); }
/** * 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; }
/** * Returns {@code true} if the given {@code uri} has a write concern set. * @param uri the URI to check. * @return {@code true} if the URI has a write concern set, {@code false} * otherwise. */ public static boolean hasWriteConcern(@NotNull String uri) { MongoClientOptions.Builder builder = MongoClientOptions.builder(); builder.writeConcern(WC_UNKNOWN); WriteConcern wc = new MongoClientURI(checkNotNull(uri), builder) .getOptions().getWriteConcern(); return !WC_UNKNOWN.equals(wc); }
/** * 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(); }
.minSize(getMinConnectionsPerHost()) .maxSize(getConnectionsPerHost()) .maxWaitQueueSize(getThreadsAllowedToBlockForConnectionMultiplier() * getConnectionsPerHost()) .maxWaitTime(getMaxWaitTime(), MILLISECONDS) .maxConnectionIdleTime(getMaxConnectionIdleTime(), MILLISECONDS) .maxConnectionLifeTime(getMaxConnectionLifeTime(), MILLISECONDS); .connectTimeout(getConnectTimeout(), MILLISECONDS) .readTimeout(getSocketTimeout(), MILLISECONDS) .keepAlive(isSocketKeepAlive()) .build(); heartbeatSocketSettings = SocketSettings.builder() .connectTimeout(getHeartbeatConnectTimeout(), MILLISECONDS) .readTimeout(getHeartbeatSocketTimeout(), MILLISECONDS) .keepAlive(isSocketKeepAlive()) .build(); .heartbeatFrequency(getHeartbeatFrequency(), MILLISECONDS) .minHeartbeatFrequency(getMinHeartbeatFrequency(), MILLISECONDS);
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(); }
Assert.assertEquals(WriteConcern.NORMAL, options.getWriteConcern()); WriteConcern wc = options.getWriteConcern(); Assert.assertEquals(0, wc.getW()); Assert.assertEquals(1000, wc.getWtimeout()); Assert.assertEquals(LazyDBDecoder.FACTORY, options.getDbDecoderFactory()); Assert.assertEquals(TestDBDecoderFactory.class, options.getDbDecoderFactory().getClass()); Assert.assertEquals(TestDBEncoderFactory.class, options.getDbEncoderFactory().getClass()); Assert.assertEquals(INSECURE_SSL_SOCKET_FACTORY, options.getSocketFactory()); Assert.assertEquals(SSLSocketFactory.getDefault().getClass(), options.getSocketFactory().getClass()); Assert.assertEquals(7, options.getConnectionsPerHost()); Assert.assertEquals(32, options.getConnectTimeout()); Assert.assertEquals(41, options.getMaxWaitTime()); Assert.assertEquals(3, options.getThreadsAllowedToBlockForConnectionMultiplier());
/** * Getter for connectionsPerHost. * * @return number representing the connections per host */ public int getConnectionsPerHost() { return (connectionsPerHost > 0) ? connectionsPerHost : defaults.getConnectionsPerHost(); }