List of usage examples for com.mongodb MongoClientOptions isSocketKeepAlive
@Deprecated public boolean isSocketKeepAlive()
This flag controls the socket keep-alive feature that keeps a connection alive through firewalls java.net.Socket#setKeepAlive(boolean)
Default is true .
From source file:com.bnrc.sdn.properties.MongoProperties.java
License:Apache License
private Builder builder(MongoClientOptions options) { Builder builder = MongoClientOptions.builder(); if (options != null) { builder.alwaysUseMBeans(options.isAlwaysUseMBeans()); builder.connectionsPerHost(options.getConnectionsPerHost()); builder.connectTimeout(options.getConnectTimeout()); builder.cursorFinalizerEnabled(options.isCursorFinalizerEnabled()); builder.dbDecoderFactory(options.getDbDecoderFactory()); builder.dbEncoderFactory(options.getDbEncoderFactory()); builder.description(options.getDescription()); builder.maxWaitTime(options.getMaxWaitTime()); builder.readPreference(options.getReadPreference()); builder.socketFactory(options.getSocketFactory()); builder.socketKeepAlive(options.isSocketKeepAlive()); builder.socketTimeout(options.getSocketTimeout()); builder.threadsAllowedToBlockForConnectionMultiplier( options.getThreadsAllowedToBlockForConnectionMultiplier()); builder.writeConcern(options.getWriteConcern()); }/* w ww. ja va 2 s. com*/ return builder; }
From source file:org.apache.jackrabbit.oak.plugins.document.util.MongoConnection.java
License:Apache License
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("threadsAllowedToBlockForConnectionMultiplier", opts.getThreadsAllowedToBlockForConnectionMultiplier()) .add("readPreference", opts.getReadPreference().getName()) .add("writeConcern", opts.getWriteConcern()).toString(); }
From source file:org.s1.mongodb.MongoDBConnectionHelper.java
License:Apache License
/** * * @param instance/*from w ww . j a v a2 s .c o m*/ */ private static synchronized void initialize(String instance) { if (!connections.containsKey(instance)) { Map<String, Object> mopt = Options.getStorage().getMap(OPTIONS); Map<String, Object> m = Objects.get(mopt, "connections." + instance); if (Objects.isNullOrEmpty(m)) { m = Objects.get(mopt, "connections." + DEFAULT_INSTANCE); } MongoClientOptions.Builder b = MongoClientOptions.builder(); MongoClientOptions def_opt = MongoClientOptions.builder().build(); b.connectionsPerHost(Objects.get(m, "connectionsPerHost", def_opt.getConnectionsPerHost())); b.autoConnectRetry(Objects.get(m, "autoConnectRetry", def_opt.isAutoConnectRetry())); b.connectTimeout(Objects.get(m, "connectTimeout", def_opt.getConnectTimeout())); b.socketKeepAlive(Objects.get(m, "socketKeepAlive", def_opt.isSocketKeepAlive())); b.socketTimeout(Objects.get(m, "socketTimeout", def_opt.getSocketTimeout())); b.maxAutoConnectRetryTime( Objects.get(m, "maxAutoConnectRetryTime", def_opt.getMaxAutoConnectRetryTime())); b.maxWaitTime(Objects.get(m, "maxWaitTime", def_opt.getMaxWaitTime())); b.threadsAllowedToBlockForConnectionMultiplier( Objects.get(m, "threadsAllowedToBlockForConnectionMultiplier", def_opt.getThreadsAllowedToBlockForConnectionMultiplier())); b.writeConcern(WriteConcern.FSYNC_SAFE); MongoClientOptions opt = b.build(); MongoClient cl = null; try { cl = new MongoClient( new ServerAddress(Objects.get(m, "host", "localhost"), Objects.get(m, "port", 27017)), opt); } catch (UnknownHostException e) { throw S1SystemError.wrap(e); } String dbName = Objects.get(m, "name"); if (Objects.isNullOrEmpty(dbName)) throw new S1SystemError("Cannot initialize MongoDB connection, because name is not set"); DB db = cl.getDB(dbName); String user = Objects.get(m, "user"); String password = Objects.get(m, "password"); if (!Objects.isNullOrEmpty(user)) { if (!db.authenticate(user, password.toCharArray())) { throw new S1SystemError( "Cannot authenticate MongoDB connection " + dbName + " with user " + user); } } LOG.info("MongoDB connected " + cl.getAddress().getHost() + ":" + cl.getAddress().getPort()); connections.put(instance, db); } }