Example usage for com.mongodb MongoOptions setSocketFactory

List of usage examples for com.mongodb MongoOptions setSocketFactory

Introduction

In this page you can find the example usage for com.mongodb MongoOptions setSocketFactory.

Prototype

public synchronized void setSocketFactory(final SocketFactory factory) 

Source Link

Document

Sets the socket factory for creating sockets to mongod.

Usage

From source file:org.springframework.data.mongodb.core.MongoOptionsFactoryBean.java

License:Apache License

@Override
protected MongoOptions createInstance() throws Exception {

    if (MongoClientVersion.isMongo3Driver()) {
        throw new IllegalArgumentException(String.format(
                "Usage of 'mongo-options' is no longer supported for MongoDB Java driver version 3 and above. Please use 'mongo-client-options' and refer to chapter 'MongoDB 3.0 Support' for details."));
    }/*from  w w w.j av  a2s.c o  m*/

    MongoOptions options = new MongoOptions();

    options.setConnectionsPerHost(connectionsPerHost);
    options.setThreadsAllowedToBlockForConnectionMultiplier(threadsAllowedToBlockForConnectionMultiplier);
    options.setMaxWaitTime(maxWaitTime);
    options.setConnectTimeout(connectTimeout);
    options.setSocketTimeout(socketTimeout);
    options.setSocketKeepAlive(socketKeepAlive);

    options.setW(writeNumber);
    options.setWtimeout(writeTimeout);
    options.setFsync(writeFsync);

    if (ssl) {
        options.setSocketFactory(sslSocketFactory != null ? sslSocketFactory : SSLSocketFactory.getDefault());
    }

    ReflectiveMongoOptionsInvoker.setAutoConnectRetry(options, autoConnectRetry);
    ReflectiveMongoOptionsInvoker.setMaxAutoConnectRetryTime(options, maxAutoConnectRetryTime);
    ReflectiveMongoOptionsInvoker.setSlaveOk(options, slaveOk);

    return options;
}