List of usage examples for com.mongodb MongoOptions MongoOptions
@Deprecated
public MongoOptions()
From source file:org.axonframework.eventsourcing.eventstore.mongo.MongoOptionsFactory.java
License:Apache License
/** * Uses the configured parameters to create a MongoOptions instance. * * @return MongoOptions instance based on the configured properties *///from ww w .j av a2s.c o m public MongoOptions createMongoOptions() { MongoOptions options = new MongoOptions(); options.connectionsPerHost = getConnectionsPerHost(); options.connectTimeout = getConnectionTimeout(); options.maxWaitTime = getMaxWaitTime(); options.threadsAllowedToBlockForConnectionMultiplier = getThreadsAllowedToBlockForConnectionMultiplier(); options.autoConnectRetry = isAutoConnectRetry(); options.socketTimeout = getSocketTimeOut(); if (logger.isDebugEnabled()) { logger.debug("Mongo Options"); logger.debug("Connections per host :{}", options.connectionsPerHost); logger.debug("Connection timeout : {}", options.connectTimeout); logger.debug("Max wait timeout : {}", options.maxWaitTime); logger.debug("Threads allowed to block : {}", options.threadsAllowedToBlockForConnectionMultiplier); logger.debug("Autoconnect retry : {}", options.autoConnectRetry); logger.debug("Socket timeout : {}", options.socketTimeout); } return options; }
From source file:org.benjp.services.mongodb.MongoBootstrap.java
License:Open Source License
private Mongo mongo() { if (m == null) { try {//from w ww. j ava 2 s. c om if (PropertyManager.PROPERTY_SERVER_TYPE_EMBED .equals(PropertyManager.getProperty(PropertyManager.PROPERTY_SERVER_TYPE))) { log.warning("WE WILL NOW USE MONGODB IN EMBED MODE..."); log.warning("BE AWARE..."); log.warning("EMBED MODE SHOULD NEVER BE USED IN PRODUCTION!"); setupEmbedMongo(); } MongoOptions options = new MongoOptions(); options.connectionsPerHost = 200; options.connectTimeout = 60000; options.threadsAllowedToBlockForConnectionMultiplier = 10; options.autoConnectRetry = true; String host = PropertyManager.getProperty(PropertyManager.PROPERTY_SERVER_HOST); int port = Integer.parseInt(PropertyManager.getProperty(PropertyManager.PROPERTY_SERVER_PORT)); m = new Mongo(new ServerAddress(host, port), options); m.setWriteConcern(WriteConcern.SAFE); } catch (UnknownHostException e) { } catch (IOException e) { } } return m; }
From source file:org.chililog.server.data.MongoConnection.java
License:Apache License
/** * <p>/*from ww w . ja v a 2 s .c o m*/ * Loads our mongoDB connection pool * </p> * <p> * This is a package scope method so that we can use it within our junit test cases. It should not be called from * real code. * </p> * * @throws MongoException * @throws UnknownHostException * */ void loadMongo() throws UnknownHostException, MongoException { AppProperties appProperties = AppProperties.getInstance(); ServerAddress addr = new ServerAddress(appProperties.getDbIpAddress(), appProperties.getDbIpPort()); MongoOptions options = new MongoOptions(); options.connectionsPerHost = appProperties.getDbConnectionsPerHost(); _mongo = new Mongo(addr, options); }
From source file:org.chimi.s4s.storage.mongofs.MongoFSFileStorage.java
License:Apache License
public MongoFSFileStorage(String mongoHost, int mongoPort, int poolSize) throws UnknownHostException, MongoException { MongoOptions options = new MongoOptions(); options.connectionsPerHost = poolSize; mongo = new Mongo(new ServerAddress(mongoHost, mongoPort), options); }
From source file:org.exoplatform.addons.persistence.services.mongodb.MongoBootstrap.java
License:Open Source License
private Mongo mongo() { if (m == null) { try {// ww w.jav a2 s . c o m if (PropertyManager.PROPERTY_DB_SERVER_TYPE_EMBED .equals(PropertyManager.getProperty(PropertyManager.PROPERTY_DB_SERVER_TYPE))) { log.warning("WE WILL NOW USE MONGODB IN EMBED MODE..."); log.warning("BE AWARE..."); log.warning("EMBED MODE SHOULD NEVER BE USED IN PRODUCTION!"); setupEmbedMongo(); } MongoOptions options = new MongoOptions(); options.connectionsPerHost = 200; options.connectTimeout = 60000; options.threadsAllowedToBlockForConnectionMultiplier = 10; options.autoConnectRetry = true; String host = PropertyManager.getProperty(PropertyManager.PROPERTY_DB_SERVER_HOST); int port = Integer.parseInt(PropertyManager.getProperty(PropertyManager.PROPERTY_DB_SERVER_PORT)); m = new Mongo(new ServerAddress(host, port), options); m.setWriteConcern(WriteConcern.SAFE); } catch (UnknownHostException e) { } catch (IOException e) { } } return m; }
From source file:org.exoplatform.addons.storage.services.mongodb.MongoBootstrap.java
License:Open Source License
private Mongo mongo() { if (m == null) { try {//from w w w .j av a2 s . c o m MongoOptions options = new MongoOptions(); options.connectionsPerHost = 200; options.connectTimeout = 60000; options.threadsAllowedToBlockForConnectionMultiplier = 10; options.autoConnectRetry = true; String host = PropertyManager.getProperty(PropertyManager.PROPERTY_SERVER_HOST); int port = Integer.parseInt(PropertyManager.getProperty(PropertyManager.PROPERTY_SERVER_PORT)); m = new Mongo(new ServerAddress(host, port), options); m.setWriteConcern(WriteConcern.SAFE); } catch (UnknownHostException e) { } catch (IOException e) { } } return m; }
From source file:org.exoplatform.chat.services.mongodb.MongoBootstrap.java
License:Open Source License
private Mongo mongo() { if (m == null) { try {/*from ww w.j a v a2 s .c o m*/ if (PropertyManager.PROPERTY_SERVER_TYPE_EMBED .equals(PropertyManager.getProperty(PropertyManager.PROPERTY_SERVER_TYPE))) { LOG.warning("WE WILL NOW USE MONGODB IN EMBED MODE..."); LOG.warning("BE AWARE..."); LOG.warning("EMBED MODE SHOULD NEVER BE USED IN PRODUCTION!"); setupEmbedMongo(); } MongoOptions options = new MongoOptions(); options.connectionsPerHost = 200; options.connectTimeout = 60000; options.threadsAllowedToBlockForConnectionMultiplier = 10; options.autoConnectRetry = true; String host = PropertyManager.getProperty(PropertyManager.PROPERTY_SERVER_HOST); int port = Integer.parseInt(PropertyManager.getProperty(PropertyManager.PROPERTY_SERVER_PORT)); m = new Mongo(new ServerAddress(host, port), options); m.setWriteConcern(WriteConcern.SAFE); } catch (UnknownHostException e) { LOG.warning(e.getMessage()); } catch (IOException e) { LOG.warning(e.getMessage()); } } return m; }
From source file:org.exoplatform.mongo.factory.MongoFactoryBean.java
License:Open Source License
protected Mongo createInstance() throws Exception { Mongo mongo = null;//from w w w. ja v a 2 s . co m if (mongoOptions == null) { mongoOptions = new MongoOptions(); mongoOptions.safe = true; // mongoOptions.fsync = true; // mongoOptions.slaveOk = true; } setMultiAddress(configuration.getDataStoreReplicas().split(",")); logger.debug("Created Mongo with MongoOptions: [" + mongoOptions.toString() + "], ReplicaSets: " + replicaSetSeeds); try { if (replicaSetSeeds.size() > 0) { if (mongoOptions != null) { mongo = new Mongo(replicaSetSeeds, mongoOptions); } else { mongo = new Mongo(replicaSetSeeds); } } else { mongo = new Mongo(); } } catch (MongoException mongoException) { logger.error("Problem creating Mongo instance", mongoException); throw mongoException; } return mongo; }
From source file:org.grails.datastore.gorm.mongo.bean.factory.GMongoFactoryBean.java
License:Apache License
public void afterPropertiesSet() throws UnknownHostException { // apply defaults - convenient when used to configure for tests // in an application context if (mongo != null) { return;/*from www .j av a 2s. c o m*/ } ServerAddress defaultOptions = new ServerAddress(); if (mongoOptions == null) mongoOptions = new MongoOptions(); if (replicaPair != null) { if (replicaPair.size() < 2) { throw new DatastoreConfigurationException("A replica pair must have two server entries"); } mongo = new GMongo(replicaPair.get(0), replicaPair.get(1), mongoOptions); } else if (replicaSetSeeds != null) { mongo = new GMongo(replicaSetSeeds, mongoOptions); } else { String mongoHost = host != null ? host : defaultOptions.getHost(); if (port != null) { mongo = new GMongo(new ServerAddress(mongoHost, port), mongoOptions); } else { mongo = new GMongo(mongoHost, mongoOptions); } } }
From source file:org.mule.modules.morphia.MorphiaConnector.java
License:Open Source License
/** * Construct a new instance of Morphia/*from w w w .j av a2 s .com*/ */ @PostConstruct public void init() throws ClassNotFoundException { this.mongoCache = CacheBuilder.newBuilder().maximumSize(10).build(new CacheLoader<MongoCacheKey, Mongo>() { public Mongo load(MongoCacheKey cacheKey) { return new Mongo(cacheKey.getSeeds(), cacheKey.getOptions()); } }); this.datastoreCache = CacheBuilder.newBuilder().maximumSize(50) .build(new CacheLoader<MorphiaCacheKey, Datastore>() { private Morphia morphia; @Override public Datastore load(MorphiaCacheKey morphiaCacheKey) throws Exception { initMorphia(); List<ServerAddress> seeds = getSeeds(morphiaCacheKey.getHost(), morphiaCacheKey.getPort()); MongoCacheKey mongoCacheKey = new MongoCacheKey(seeds, getMongoOptions()); Mongo mongo = mongoCache.get(mongoCacheKey); Datastore datastore = this.morphia.createDatastore(mongo, morphiaCacheKey.getDatabase(), morphiaCacheKey.getUsername(), morphiaCacheKey.getPassword().toCharArray()); datastore.ensureIndexes(ensureIndexesOnBackground); datastore.ensureCaps(); return datastore; } private void initMorphia() throws ClassNotFoundException { if (morphia == null) { morphia = new Morphia(); if (classes != null) { for (String className : classes) { this.morphia.map(Class.forName(className)); } } if (packages != null) { for (String packageName : packages) { this.morphia.mapPackage(packageName, ignoreInvalidClasses); } } } } private List<ServerAddress> getSeeds(String host, int port) throws UnknownHostException { List<ServerAddress> seeds = new ArrayList<ServerAddress>(); if (host.indexOf(',') != -1) { StringTokenizer tokenizer = new StringTokenizer(host, ","); while (tokenizer.hasMoreTokens()) { seeds.add(new ServerAddress(tokenizer.nextToken(), port)); } } else { seeds.add(new ServerAddress(host, port)); } return seeds; } private MongoOptions getMongoOptions() { MongoOptions options = new MongoOptions(); if (connectionsPerHost != null) options.connectionsPerHost = connectionsPerHost; if (threadsAllowedToBlockForConnectionMultiplier != null) options.threadsAllowedToBlockForConnectionMultiplier = threadsAllowedToBlockForConnectionMultiplier; if (maxWaitTime != null) options.maxWaitTime = maxWaitTime; if (connectTimeout != null) options.connectTimeout = connectTimeout; if (socketTimeout != null) options.socketTimeout = socketTimeout; if (autoConnectRetry != null) options.autoConnectRetry = autoConnectRetry; if (slaveOk != null) options.slaveOk = slaveOk; if (safe != null) options.safe = safe; if (w != null) options.w = w; if (wtimeout != null) options.wtimeout = wtimeout; if (fsync != null) options.fsync = fsync; return options; } }); }