Examples of MongoOptions


Examples of com.mongodb.MongoOptions

  public void testMongoSingletonWithSslEnabled() throws Exception {

    assertTrue(ctx.containsBean("mongoSsl"));
    MongoFactoryBean mfb = (MongoFactoryBean) ctx.getBean("&mongoSsl");

    MongoOptions options = (MongoOptions) getField(mfb, "mongoOptions");
    assertTrue("socketFactory should be a SSLSocketFactory", options.getSocketFactory() instanceof SSLSocketFactory);
  }
View Full Code Here

Examples of com.mongodb.MongoOptions

    assertTrue(ctx.containsBean("mongoSslWithCustomSslFactory"));
    MongoFactoryBean mfb = (MongoFactoryBean) ctx.getBean("&mongoSslWithCustomSslFactory");

    SSLSocketFactory customSslSocketFactory = ctx.getBean("customSslSocketFactory", SSLSocketFactory.class);
    MongoOptions options = (MongoOptions) getField(mfb, "mongoOptions");

    assertTrue("socketFactory should be a SSLSocketFactory", options.getSocketFactory() instanceof SSLSocketFactory);
    assertSame(customSslSocketFactory, options.getSocketFactory());
  }
View Full Code Here

Examples of com.mongodb.MongoOptions

    assertEquals("127.0.0.1", host);
    assertEquals(new Integer(27017), port);

    Mongo mongo = mfb.getObject();
    MongoOptions mongoOpts = mongo.getMongoOptions();

    assertEquals(8, mongoOpts.connectionsPerHost);
    assertEquals(1000, mongoOpts.connectTimeout);
    assertEquals(1500, mongoOpts.maxWaitTime);
    assertEquals(true, mongoOpts.autoConnectRetry);
    assertEquals(1500, mongoOpts.socketTimeout);
    assertEquals(4, mongoOpts.threadsAllowedToBlockForConnectionMultiplier);
    assertEquals(true, mongoOpts.socketKeepAlive);
    assertEquals(true, mongoOpts.fsync);
    assertEquals(true, mongoOpts.slaveOk);
    assertEquals(1, mongoOpts.getWriteConcern().getW());
    assertEquals(0, mongoOpts.getWriteConcern().getWtimeout());
    assertEquals(true, mongoOpts.getWriteConcern().fsync());
  }
View Full Code Here

Examples of com.mongodb.MongoOptions

          catch ( NumberFormatException e ) {
            throw log.mongoDBTimeOutIllegalValue( cfgTimeout.toString() );
          }
        }

        MongoOptions options = new MongoOptions();
        options.safe = safe;
        options.connectTimeout = timeout;
        log.useSafe( safe );
        log.connectingToMongo( host, port, timeout );
View Full Code Here

Examples of com.mongodb.MongoOptions

        factory = new MongoOptionsFactory();
    }

    @Test
    public void testCreateMongoOptions_defaults() throws Exception {
        MongoOptions options = factory.createMongoOptions();
        MongoOptions defaults = new MongoOptions();

        assertEquals(defaults.autoConnectRetry, options.autoConnectRetry);
        assertEquals(defaults.maxWaitTime, options.maxWaitTime);
        assertEquals(defaults.socketTimeout, options.socketTimeout);
        assertEquals(defaults.connectionsPerHost, options.connectionsPerHost);
View Full Code Here

Examples of com.mongodb.MongoOptions

        factory.setConnectionTimeout(11);
        factory.setMaxWaitTime(3);
        factory.setSocketTimeOut(23);
        factory.setThreadsAllowedToBlockForConnectionMultiplier(31);

        MongoOptions options = factory.createMongoOptions();
        assertTrue(options.autoConnectRetry);
        assertEquals(3, options.maxWaitTime);
        assertEquals(23, options.socketTimeout);
        assertEquals(9, options.connectionsPerHost);
        assertEquals(11, options.connectTimeout);
View Full Code Here

Examples of com.mongodb.MongoOptions

    /**
     * Default constructor for the factory that initializes the defaults.
     */
    public MongoOptionsFactory() {
        defaults = new MongoOptions();
    }
View Full Code Here

Examples of com.mongodb.MongoOptions

     * Uses the configured parameters to create a MongoOptions instance.
     *
     * @return MongoOptions instance based on the configured properties
     */
    public MongoOptions createMongoOptions() {
        MongoOptions options = new MongoOptions();
        options.connectionsPerHost = getConnectionsPerHost();
        options.connectTimeout = getConnectionTimeout();
        options.maxWaitTime = getMaxWaitTime();
        options.threadsAllowedToBlockForConnectionMultiplier = getThreadsAllowedToBlockForConnectionMultiplier();
        options.autoConnectRetry = isAutoConnectRetry();
View Full Code Here

Examples of com.mongodb.MongoOptions

     */
    private Mongo onSetMongoServerProperties(String contactNode, String defaultPort, String poolSize,
            List<ServerAddress> addrs) throws UnknownHostException
    {
        Mongo mongo = null;
        MongoOptions mo = null;
        MongoDBSchemaMetadata metadata = MongoDBPropertyReader.msmd;
        ClientProperties cp = metadata != null ? metadata.getClientProperties() : null;
        if (cp != null)
        {
            DataStore dataStore = metadata != null ? metadata.getDataStore() : null;
            List<Server> servers = dataStore != null && dataStore.getConnection() != null ? dataStore.getConnection()
                    .getServers() : null;
            if (servers != null && !servers.isEmpty())
            {
                for (Server server : servers)
                {
                    addrs.add(new ServerAddress(server.getHost().trim(), Integer.parseInt(server.getPort().trim())));
                }
                mongo = new Mongo(addrs);
            }
            else
            {
                logger.info("Connecting to mongodb at " + contactNode + " on port " + defaultPort);
                mongo = new Mongo(contactNode, Integer.parseInt(defaultPort));
            }
            mo = mongo.getMongoOptions();
            Properties p = dataStore != null && dataStore.getConnection() != null ? dataStore.getConnection()
                    .getProperties() : null;

            PopulateMongoOptions.populateMongoOptions(mo, p);
        }
        else
        {
            logger.info("Connecting to mongodb at " + contactNode + " on port " + defaultPort);
            mongo = new Mongo(contactNode, Integer.parseInt(defaultPort));
            mo = mongo.getMongoOptions();
        }
        // setting server property.

        if (mo.getConnectionsPerHost() <= 0 && !StringUtils.isEmpty(poolSize))
        {
            mo.connectionsPerHost = Integer.parseInt(poolSize);
        }
        return mongo;
    }
View Full Code Here

Examples of com.mongodb.MongoOptions

     * @param port The port.
     * @param database The database name.
     * @throws Exception If an error occurred while trying to connect.
     */
    public MongoConnection(String host, int port, String database) throws Exception {
        MongoOptions options = new MongoOptions();
        options.setThreadsAllowedToBlockForConnectionMultiplier(100);
        mongo = new Mongo(new ServerAddress(host, port), options);
        db = mongo.getDB(database);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.