List of usage examples for com.mongodb MongoClientURI MongoClientURI
public MongoClientURI(final String uri)
From source file:com.bluedragon.profiler.ProfilerExtension.java
License:Open Source License
public static void setMongo(String mongourl, String database, String collection) throws Exception { if (thisInst.mongourl != null && !thisInst.mongourl.equals(mongourl)) return;// w ww . j a va 2s.c o m thisInst.mongourl = mongourl; MongoClientURI m = new MongoClientURI(thisInst.mongourl); thisInst.mongo = new MongoClient(m); thisInst.coll = thisInst.mongo.getDB(database).getCollection(collection); Thread t = new Thread(thisInst); t.setName("ProfilerExtension:MongoThread"); t.setPriority(Thread.MIN_PRIORITY); t.start(); }
From source file:com.bnrc.sdn.properties.MongoProperties.java
License:Apache License
public String getMongoClientDatabase() { if (this.database != null) { return this.database; }// w w w .j a v a2 s.c o m return new MongoClientURI(this.uri).getDatabase(); }
From source file:com.cloudbees.demo.beesshop.util.MongodbDBFactoryBean.java
License:Apache License
@Override public void afterPropertiesSet() throws Exception { MongoClientURI mongoDbUri = new MongoClientURI(uri); logger.info("host=" + mongoDbUri.getHosts() + ",username=" + mongoDbUri.getUsername() + ",database=" + mongoDbUri.getDatabase() + ",collection=" + mongoDbUri.getCollection()); mongoClient = new MongoClient(mongoDbUri); db = mongoClient.getDB(mongoDbUri.getDatabase()); }
From source file:com.cognifide.aet.vs.mongodb.MongoDBClient.java
License:Apache License
private void setupMongoDBConnection() throws UnknownHostException { mongoClient = new MongoClient(new MongoClientURI(mongoUri)); testConnection();/*from www .j a v a2 s. c o m*/ LOGGER.info("Mongo client connected at: " + mongoUri); }
From source file:com.commercehub.jackson.datatype.mongo.deser.MongoClientURIDeserializer.java
License:Apache License
@Override public MongoClientURI deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException { return new MongoClientURI(jsonParser.getText()); }
From source file:com.connection.Connection.java
private void establishConnection() { if (mongoClient == null) { MongoClientURI uri = new MongoClientURI("mongodb://352634:cs-120@ds023418.mlab.com:23418/example"); try {/* w ww . j a v a 2 s . com*/ mongoClient = new MongoClient(uri); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } dbname = uri.getDatabase(); // mongoClient = new MongoClient("localhost", 27017); mongoDB = mongoClient.getDB(dbname); } }
From source file:com.davidsalter.cappedcollection.JavaDriverCappedCollection.java
License:Apache License
/** * @param args the command line arguments *///from ww w.ja v a 2 s . c o m public static void main(String[] args) throws UnknownHostException { MongoClient mongoClient = new MongoClient(new MongoClientURI("mongodb://localhost")); DB db = mongoClient.getDB("test"); DBCollection collection; if (!db.collectionExists("cappedLogsJavaDriver")) { BasicDBObject options = new BasicDBObject("capped", true); options.append("size", 4096); options.append("max", 5); collection = db.createCollection("cappedLogsJavaDriver", options); } else { collection = db.getCollection("cappedLogsJavaDriver"); } for (int i = 0; i < 8; i++) { BasicDBObject logEntry = new BasicDBObject("logId", i); collection.insert(logEntry); } }
From source file:com.davidsalter.cappedcollection.MorphiaCappedCollection.java
License:Apache License
/** * @param args the command line arguments *//*w ww.j a v a 2 s. c o m*/ public static void main(String[] args) throws UnknownHostException { MongoClient mongoClient = new MongoClient(new MongoClientURI("mongodb://localhost")); DB db = mongoClient.getDB("test"); Morphia morphia = new Morphia(); morphia.map(LogEntry.class); Datastore datastore = morphia.createDatastore(mongoClient, "test"); datastore.ensureCaps(); for (int i = 0; i < 8; i++) { LogEntry logEntry = new LogEntry(i); datastore.save(logEntry); } }
From source file:com.deftlabs.lock.mongo.impl.SvcImpl.java
License:Apache License
/** * Initialize the service./* w w w. j a v a 2s . c om*/ */ @Override public void startup() { if (!_running.compareAndSet(false, true)) throw new IllegalStateException("startup called but already running"); _lock.lock(); try { if (_options.getMongoClient() == null) { _mongo = new MongoClient(new MongoClientURI(_options.getMongoUri())); } else { _mongo = _options.getMongoClient(); } // Init the db/collection. LockDao.setup(_mongo, _options); if (_options.getEnableHistory()) LockHistoryDao.setup(_mongo, _options); // Init the monitor threads. _lockHeartbeat = new Monitor.LockHeartbeat(_mongo, _options, _locks); _lockHeartbeat.start(); _lockTimeout = new Monitor.LockTimeout(_mongo, _options); _lockTimeout.start(); _lockUnlocked = new Monitor.LockUnlocked(_mongo, _options, _locks); _lockUnlocked.start(); } catch (final Throwable t) { throw new DistributedLockException(t); } finally { _lock.unlock(); } }
From source file:com.deliveronthego.CommonAPI.java
public MongoClient getConnection() { mongoclienturi = new MongoClientURI( "mongodb://deliveronthego:deliveronthego@ds037097.mongolab.com:37097/deliveronthego"); mongoclient = new MongoClient(mongoclienturi); return mongoclient; }