/** * 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(); }
connectTimeout = options.getConnectTimeout(); socketTimeout = options.getSocketTimeout(); socketKeepAlive = options.isSocketKeepAlive(); readPreference = options.getReadPreference(); writeConcern = options.getWriteConcern();
.connectTimeout(getConnectTimeout(), MILLISECONDS) .readTimeout(getSocketTimeout(), MILLISECONDS) .keepAlive(isSocketKeepAlive()) .build(); heartbeatSocketSettings = SocketSettings.builder() .connectTimeout(getHeartbeatConnectTimeout(), MILLISECONDS) .readTimeout(getHeartbeatSocketTimeout(), MILLISECONDS) .keepAlive(isSocketKeepAlive()) .build();
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; } }
/** * 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(); }
@Test public void keepAlive() throws Exception { Map<String, Object> config = newConfig(repoHome); config.put(DocumentNodeStoreServiceConfiguration.PROP_SO_KEEP_ALIVE, true); MockOsgi.setConfigForPid(context.bundleContext(), PID, config); MockOsgi.activate(service, context.bundleContext()); DocumentNodeStore store = context.getService(DocumentNodeStore.class); MongoDocumentStore mds = getMongoDocumentStore(store); MongoClient client = MongoDocumentStoreTestHelper.getClient(mds); assertTrue(client.getMongoClientOptions().isSocketKeepAlive()); }
connectTimeout = options.getConnectTimeout(); socketTimeout = options.getSocketTimeout(); socketKeepAlive = options.isSocketKeepAlive(); readPreference = options.getReadPreference(); writeConcern = options.getWriteConcern();
@Test public void socketKeepAlive() throws Exception { assumeTrue(MongoUtils.isAvailable()); MongoClientOptions.Builder options = MongoConnection.getDefaultBuilder(); options.socketKeepAlive(false); MongoConnection c = new MongoConnection(MongoUtils.URL, options); try { assertFalse(c.getMongoClient().getMongoClientOptions().isSocketKeepAlive()); } finally { c.close(); } // default is with keep-alive (starting with 3.6 driver) c = new MongoConnection(MongoUtils.URL); try { assertTrue(c.getMongoClient().getMongoClientOptions().isSocketKeepAlive()); } finally { c.close(); } }
@Test public void presetOverride() throws Exception { MockOsgi.setConfigForPid(context.bundleContext(), Configuration.PRESET_PID, DocumentNodeStoreServiceConfiguration.PROP_SO_KEEP_ALIVE, true); MockOsgi.activate(preset, context.bundleContext()); Map<String, Object> config = newConfig(repoHome); config.put(DocumentNodeStoreServiceConfiguration.PROP_SO_KEEP_ALIVE, false); MockOsgi.setConfigForPid(context.bundleContext(), PID, config); MockOsgi.activate(service, context.bundleContext()); DocumentNodeStore store = context.getService(DocumentNodeStore.class); MongoDocumentStore mds = getMongoDocumentStore(store); MongoClient client = MongoDocumentStoreTestHelper.getClient(mds); assertFalse(client.getMongoClientOptions().isSocketKeepAlive()); }
.connectTimeout(getConnectTimeout(), MILLISECONDS) .readTimeout(getSocketTimeout(), MILLISECONDS) .keepAlive(isSocketKeepAlive()) .build(); heartbeatSocketSettings = SocketSettings.builder() .connectTimeout(getHeartbeatConnectTimeout(), MILLISECONDS) .readTimeout(getHeartbeatSocketTimeout(), MILLISECONDS) .keepAlive(isSocketKeepAlive()) .build();
@Test public void preset() throws Exception { MockOsgi.setConfigForPid(context.bundleContext(), Configuration.PRESET_PID, DocumentNodeStoreServiceConfiguration.PROP_SO_KEEP_ALIVE, true); MockOsgi.activate(preset, context.bundleContext()); MockOsgi.setConfigForPid(context.bundleContext(), PID, newConfig(repoHome)); MockOsgi.activate(service, context.bundleContext()); DocumentNodeStore store = context.getService(DocumentNodeStore.class); MongoDocumentStore mds = getMongoDocumentStore(store); assertNotNull(mds); MongoClient client = MongoDocumentStoreTestHelper.getClient(mds); assertTrue(client.getMongoClientOptions().isSocketKeepAlive()); }