Example usage for com.mongodb MongoClientOptions toString

List of usage examples for com.mongodb MongoClientOptions toString

Introduction

In this page you can find the example usage for com.mongodb MongoClientOptions toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:org.apache.jmeter.protocol.mongodb.config.MongoSourceElement.java

License:Apache License

@Override
public void testStarted() {
    if (log.isDebugEnabled()) {
        log.debug(getTitle() + " testStarted");
    }//  ww w. j  a v a2 s  .c  om

    MongoClientOptions.Builder builder = MongoClientOptions.builder().autoConnectRetry(getAutoConnectRetry())
            .connectTimeout(getConnectTimeout()).connectionsPerHost(getConnectionsPerHost())
            .maxAutoConnectRetryTime(getMaxAutoConnectRetryTime()).maxWaitTime(getMaxWaitTime())
            .socketKeepAlive(getSocketKeepAlive()).socketTimeout(getSocketTimeout())
            .threadsAllowedToBlockForConnectionMultiplier(getThreadsAllowedToBlockForConnectionMultiplier());

    if (getSafe()) {
        builder.writeConcern(WriteConcern.SAFE);
    } else {
        builder.writeConcern(new WriteConcern(getWriteOperationNumberOfServers(), getWriteOperationTimeout(),
                getFsync(), getWaitForJournaling(), getContinueOnInsertError()));
    }
    MongoClientOptions mongoOptions = builder.build();

    if (log.isDebugEnabled()) {
        log.debug("options : " + mongoOptions.toString());
    }

    if (getThreadContext().getVariables().getObject(getSource()) != null) {
        if (log.isWarnEnabled()) {
            log.warn(getSource() + " has already been defined.");
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug(getSource() + "  is being defined.");
        }
        try {
            getThreadContext().getVariables().putObject(getSource(),
                    new MongoDB(MongoUtils.toServerAddresses(getConnection()), mongoOptions));
        } catch (UnknownHostException e) {
            throw new IllegalStateException(e);
        }
    }
}