List of usage examples for com.mongodb MongoOptions getConnectionsPerHost
public synchronized int getConnectionsPerHost()
From source file:com.seer.datacruncher.jpa.dao.MongoDbDao.java
License:Open Source License
/** * Gets connection to data base./*from w ww . j a v a 2 s.c om*/ * Note: mongoPool is thread-safe. * * @return connection */ private static DB getConnection() { try { if (mongoPool == null) { mongoPool = new Mongo(contactNode, Integer.parseInt(defaultPort)); MongoOptions mo = mongoPool.getMongoOptions(); if (mo.getConnectionsPerHost() <= 0 && !StringUtils.isEmpty(poolSize)) { mo.connectionsPerHost = Integer.parseInt(poolSize); } } DB mongoDB = mongoPool.getDB(MONGO_KEY_SPACE); if (userName != null && !userName.isEmpty() && password != null && !password.isEmpty()) { mongoDB.authenticate(userName, password.toCharArray()); } return mongoDB; } catch (NumberFormatException e) { log.error("Number format exception", e); } catch (UnknownHostException e) { log.error(e); } return null; }