com.mongodb.connection.SocketSettings Java Examples
The following examples show how to use
com.mongodb.connection.SocketSettings.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SocketSettingsParser.java From vertx-mongo-client with Apache License 2.0 | 6 votes |
public SocketSettingsParser(ConnectionString connectionString, JsonObject config) { SocketSettings.Builder settings = SocketSettings.builder(); if (connectionString != null) { settings.applyConnectionString(connectionString); } else { Integer connectTimeoutMS = config.getInteger("connectTimeoutMS"); if (connectTimeoutMS != null) { settings.connectTimeout(connectTimeoutMS, MILLISECONDS); } Integer socketTimeoutMS = config.getInteger("socketTimeoutMS"); if (socketTimeoutMS != null) { settings.readTimeout(socketTimeoutMS, MILLISECONDS); } Integer receiveBufferSize = config.getInteger("receiveBufferSize"); if (receiveBufferSize != null) { settings.receiveBufferSize(receiveBufferSize); } Integer sendBufferSize = config.getInteger("sendBufferSize"); if (sendBufferSize != null) { settings.sendBufferSize(sendBufferSize); } } this.settings = settings.build(); }
Example #2
Source File: SocketSettingsParserTest.java From vertx-mongo-client with Apache License 2.0 | 6 votes |
@Test public void testSocketSettings() { int connectTimeoutMS = Math.abs(TestUtils.randomInt()); int socketTimeoutMS = Math.abs(TestUtils.randomInt()); int receiveBufferSize = Math.abs(TestUtils.randomInt()); int sendBufferSize = Math.abs(TestUtils.randomInt()); JsonObject config = new JsonObject(); config.put("connectTimeoutMS", connectTimeoutMS); config.put("socketTimeoutMS", socketTimeoutMS); config.put("receiveBufferSize", receiveBufferSize); config.put("sendBufferSize", sendBufferSize); SocketSettings settings = new SocketSettingsParser(null, config).settings(); assertEquals(connectTimeoutMS, settings.getConnectTimeout(TimeUnit.MILLISECONDS)); assertEquals(socketTimeoutMS, settings.getReadTimeout(TimeUnit.MILLISECONDS)); assertEquals(receiveBufferSize, settings.getReceiveBufferSize()); assertEquals(sendBufferSize, settings.getSendBufferSize()); }
Example #3
Source File: MongoClients.java From quarkus with Apache License 2.0 | 5 votes |
@Override public void apply(SocketSettings.Builder builder) { if (config.connectTimeout.isPresent()) { builder.connectTimeout((int) config.connectTimeout.get().toMillis(), TimeUnit.MILLISECONDS); } if (config.readTimeout.isPresent()) { builder.readTimeout((int) config.readTimeout.get().toMillis(), TimeUnit.MILLISECONDS); } }
Example #4
Source File: MongoImpl.java From core-ng-project with Apache License 2.0 | 5 votes |
private MongoDatabase createDatabase(CodecRegistry registry) { if (uri == null) throw new Error("uri must not be null"); String database = uri.getDatabase(); if (database == null) throw new Error("uri must have database, uri=" + uri); var watch = new StopWatch(); try { connectionPoolSettings.maxWaitTime(timeoutInMs, TimeUnit.MILLISECONDS); // pool checkout timeout var socketSettings = SocketSettings.builder() .connectTimeout((int) timeoutInMs, TimeUnit.MILLISECONDS) .readTimeout((int) timeoutInMs, TimeUnit.MILLISECONDS) .build(); var clusterSettings = ClusterSettings.builder() .serverSelectionTimeout(timeoutInMs * 3, TimeUnit.MILLISECONDS) // able to try 3 servers .build(); var settings = MongoClientSettings.builder() .applicationName(LogManager.APP_NAME) .codecRegistry(registry) .applyToConnectionPoolSettings(builder -> builder.applySettings(connectionPoolSettings.build())) .applyToSocketSettings(builder -> builder.applySettings(socketSettings)) .applyToClusterSettings(builder -> builder.applySettings(clusterSettings)) .applyConnectionString(uri) .build(); mongoClient = MongoClients.create(settings); return mongoClient.getDatabase(database); } finally { logger.info("create mongo client, uri={}, elapsed={}", uri, watch.elapsed()); } }
Example #5
Source File: SocketSettingsParser.java From vertx-mongo-client with Apache License 2.0 | 4 votes |
public SocketSettings settings() { return settings; }