List of usage examples for com.mongodb Mongo getDB
@Deprecated public DB getDB(final String dbName)
From source file:com.ccoe.build.alerts.connector.Connector.java
License:Apache License
public static DB connectDB(List<String> location, int port, String dbname) { try {/*from w w w. java 2s . c o m*/ List<ServerAddress> serverAddressList = new ArrayList<ServerAddress>(); ServerAddress serverAddress = null; for (String loc : location) { serverAddress = new ServerAddress(loc, port); serverAddressList.add(serverAddress); } Mongo mongo = new Mongo(serverAddressList); DB db = mongo.getDB(dbname); return db; } catch (UnknownHostException e) { e.printStackTrace(); } catch (MongoException e) { e.printStackTrace(); } return null; }
From source file:com.cedac.security.acls.mongo.MongoAclService.java
License:Apache License
public MongoAclService(Mongo mongo, String databaseName, AclCache aclCache, PermissionGrantingStrategy permissionGrantingStrategy, AclAuthorizationStrategy aclAuthorizationStrategy) { this(mongo.getDB(databaseName), aclCache, permissionGrantingStrategy, aclAuthorizationStrategy); }
From source file:com.cedac.security.oauth2.provider.approval.MongoApprovalStore.java
License:Apache License
public MongoApprovalStore(Mongo mongo, String databaseName) { this(mongo.getDB(databaseName)); }
From source file:com.cedac.security.oauth2.provider.client.MongoClientDetailsService.java
License:Apache License
public MongoClientDetailsService(Mongo mongo, String databaseName) { this(mongo.getDB(databaseName)); }
From source file:com.cedac.security.oauth2.provider.code.MongoAuthorizationCodeServices.java
License:Apache License
public MongoAuthorizationCodeServices(Mongo mongo, String databaseName) { this(mongo.getDB(databaseName)); }
From source file:com.cedac.security.oauth2.provider.token.store.MongoTokenStore.java
License:Apache License
public MongoTokenStore(Mongo mongo, String databaseName) { this(mongo.getDB(databaseName)); }
From source file:com.deftlabs.examples.mongo.TailableCursorExample.java
License:Apache License
public static void main(final String[] pArgs) throws Exception { final Mongo mongo = new Mongo(new MongoURI("mongodb://127.0.0.1:27017")); mongo.getDB("testTailableCursor").dropDatabase(); // Create the capped collection final BasicDBObject conf = new BasicDBObject("capped", true); conf.put("size", 20971520); // 20 MB mongo.getDB("testTailableCursor").createCollection("test", conf); final AtomicBoolean readRunning = new AtomicBoolean(true); final AtomicBoolean writeRunning = new AtomicBoolean(true); final AtomicLong writeCounter = new AtomicLong(0); final AtomicLong readCounter = new AtomicLong(0); final ArrayList<Thread> writeThreads = new ArrayList<Thread>(); final ArrayList<Thread> readThreads = new ArrayList<Thread>(); for (int idx = 0; idx < 10; idx++) { final Thread writeThread = new Thread(new Writer(mongo, writeRunning, writeCounter)); final Thread readThread = new Thread(new Reader(mongo, readRunning, readCounter)); writeThread.start();/* w w w .ja va 2 s. com*/ readThread.start(); writeThreads.add(writeThread); readThreads.add(readThread); } // Run for five minutes //Thread.sleep(300000); Thread.sleep(20000); writeRunning.set(false); Thread.sleep(5000); readRunning.set(false); Thread.sleep(5000); for (final Thread readThread : readThreads) readThread.interrupt(); for (final Thread writeThread : writeThreads) writeThread.interrupt(); System.out.println("----- write count: " + writeCounter.get()); System.out.println("----- read count: " + readCounter.get()); }
From source file:com.ebay.cloud.cms.config.CMSProperties.java
License:Apache License
private DBCollection getPropertiesCollection(Mongo mongo) { return mongo.getDB(CMSConsts.SYS_DB).getCollection(CMSConsts.PROPERTIES_COLLECTION); }
From source file:com.ebay.cloud.cms.dal.persistence.PersistenceContext.java
License:Apache License
public DB getDB() { Mongo mongoInstance = dataSource.getMongoInstance(); String dbName = metaService.getRepository().getRepositoryName(); return mongoInstance.getDB(dbName); }
From source file:com.ebay.cloud.cms.lock.mongo.MongoMutex.java
License:Apache License
public MongoMutex(Mongo mongo, String dbName, String collName, String lockName, String clientName, int expireTime, int renewPeriod) { super();//from w w w . ja va2 s . c o m CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(dbName), "dbName should not be null or empty"); CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(collName), "collName should not be null or empty"); CheckConditions.checkArgument(mongo != null, "mongo should not be null"); CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(lockName), "lockName should not be null or empty"); CheckConditions.checkArgument(!StringUtils.isNullOrEmpty(clientName), "clientName should not be null or empty"); CheckConditions.checkArgument(expireTime >= 1000, "expireTime must be larger than 1 second"); CheckConditions.checkArgument(renewPeriod >= 400, "renewPeroid must larger than 0.4 second so renew will not cost cpu alot"); CheckConditions.checkArgument(expireTime - renewPeriod >= 1000, "expireTime - renewPeriod must be larger than 1 second so client have enough time to renew"); this.lockName = lockName; this.clientName = clientName; this.expireTime = expireTime; this.renewPeriod = renewPeriod; coll = mongo.getDB(dbName).getCollection(collName); coll.setWriteConcern(WriteConcern.SAFE); createIfNotExist(coll, lockName); }