com.mongodb.Mongo Java Examples
The following examples show how to use
com.mongodb.Mongo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SparkCache.java From scava with Eclipse Public License 2.0 | 6 votes |
private SparkCache() { sparkMap = DBMaker.newTempTreeMap(); dataMap = DBMaker.newTempTreeMap(); // If we're running in a cluster, where the API is load balanced, we actually // need to store the spark bytes in a DB. In memory cache wouldn't work. Mongo mongo; try { mongo = Configuration.getInstance().getMongoConnection(); } catch (UnknownHostException e) { e.printStackTrace(); return; } DB db = mongo.getDB("scava"); DBCollection col = db.getCollection("sparks"); col.ensureIndex("sparkid"); col.ensureIndex(new BasicDBObject("created_at", 1), new BasicDBObject("expireAfterSeconds", 3600)); }
Example #2
Source File: ApiAnalysisTests.java From scava with Eclipse Public License 2.0 | 6 votes |
@Before public void setUp() throws UnknownHostException { mongo = new Mongo(); helper = new ApiHelper(); PongoFactory.getInstance().getContributors().add(new OsgiPongoFactoryContributor()); platform = Platform.getInstance(); platform.setMongo(mongo); platform.initialize(); WORKER_ID = Configuration.getInstance().getSlaveIdentifier(); // Register Worker platform.getAnalysisRepositoryManager().getWorkerService().registerWorker(WORKER_ID); Component component = new Component(); Server server = new Server(Protocol.HTTP, 8182); component.getServers().add(server); final Application app = new ApiApplication(); component.getDefaultHost().attachDefault(app); try { component.start(); } catch (Exception e) { e.printStackTrace(); } }
Example #3
Source File: MongoUtil.java From gameserver with Apache License 2.0 | 6 votes |
/** * Intialize the mongo database connection * @param mongoHost * @param mongoPort */ public static Mongo initMongo(String mongoHost, int mongoPort) { try { ServerAddress address = new ServerAddress(mongoHost, mongoPort); MongoOptions options = new MongoOptions(); options.autoConnectRetry = true; options.connectionsPerHost = GlobalConfig.getInstance().getIntProperty("mongdb.connectionsPerHost"); options.connectTimeout = GlobalConfig.getInstance().getIntProperty("mongdb.connectTimeout"); options.maxWaitTime = GlobalConfig.getInstance().getIntProperty("mongdb.maxWaitTime"); options.socketTimeout = GlobalConfig.getInstance().getIntProperty("mongdb.socketTimeout"); options.threadsAllowedToBlockForConnectionMultiplier = GlobalConfig.getInstance().getIntProperty("mongdb.threadsAllowedToBlockForConnectionMultiplier"); Mongo mongo = new Mongo(address, options); if ( logger.isInfoEnabled() ) { logger.info("MongoDB initialized OK: host:{}", mongoHost); } refreshMongoDatabase(mongo); return mongo; } catch (Exception e) { logger.info("Failed to open mongodb", e); } return null; }
Example #4
Source File: DependencyOrderingTest.java From scava with Eclipse Public License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws UnknownHostException { PongoFactory.getInstance().getContributors().add(new OsgiPongoFactoryContributor()); mongo = new Mongo(); platform = Platform.getInstance(); platform.setMongo(mongo); platform.initialize(); Project project = new Project(); project.setName(PROJECT_NAME); String startDate = new Date().addDays(-2).toString(); project.getExecutionInformation().setLastExecuted(startDate); platform.getProjectRepositoryManager().getProjectRepository().getProjects().add(project); platform.getProjectRepositoryManager().getProjectRepository().getProjects().sync(); project = platform.getProjectRepositoryManager().getProjectRepository().getProjects().findOneByName(PROJECT_NAME); projectAnalyser = new ProjectAnalyser(platform); }
Example #5
Source File: MongoDBUtil.java From gameserver with Apache License 2.0 | 6 votes |
/** * * @param mongoHost * @param mongoPort * @return */ public static Mongo initCfgMongo(String mongoHost, int mongoPort) { try { ServerAddress address = new ServerAddress(mongoHost, mongoPort); MongoOptions options = new MongoOptions(); options.autoConnectRetry = true; Mongo mongo = new Mongo(address, options); if ( logger.isInfoEnabled() ) { logger.info("MongoDB for cfg is initialized OK: host:{}", mongoHost); } for ( String cfgColl : CFG_COLL ) { String key = StringUtil.concat(cfgNamespace, Constant.DOT, cfgColl); if ( !mongoMap.containsKey(key) ) { //Put it into our cache mongoMap.put(key, mongo); logger.debug("Put the cfg db mongo key: {} for server", key); } else { logger.warn("Key:{} is duplicate in mongo database", key); } } return mongo; } catch (Exception e) { logger.info("Failed to open mongodb", e); } return null; }
Example #6
Source File: Configuration.java From scava with Eclipse Public License 2.0 | 6 votes |
public Mongo getMongoConnection() throws UnknownHostException { if (this.mongo == null) { String[] hosts = properties.getProperty(MONGO_HOSTS, "localhost:27017").split(","); if (hosts.length > 1) { List<ServerAddress> mongoHostAddresses = new ArrayList<>(); for (String host : hosts) { String[] s = host.split(":"); mongoHostAddresses.add(new ServerAddress(s[0], Integer.valueOf(s[1]))); } this.mongo = new Mongo(mongoHostAddresses); } else { this.mongo = new Mongo();//hosts[0]); } } return this.mongo; }
Example #7
Source File: SvnManagerTests.java From scava with Eclipse Public License 2.0 | 6 votes |
public void testPrintContents() throws Exception { SvnRepository repository = new SvnRepository(); repository.setUrl("http://pongo.googlecode.com/svn"); Platform platform = Platform.getInstance(); platform.setMongo(new Mongo()); platform.initialize(); PlatformVcsManager platformVcsManager = platform.getVcsManager(); platformVcsManager.getVcsManagers().add(new SvnManager()); VcsRepositoryDelta delta = platformVcsManager.getDelta(repository, "95"/*, "101"*/); for (VcsCommit commit : delta.getCommits()) { System.err.println(commit.getAuthor() + " -> " + commit.getMessage() + " : " + commit.getRevision()); for (VcsCommitItem item : commit.getItems()) { //System.err.println("\t" + item.getPath() + " -> " + item.getChangeType()); System.err.println(platformVcsManager.getContents(item)); } } }
Example #8
Source File: MongoDBUtil.java From gameserver with Apache License 2.0 | 6 votes |
/** * Get the proper DB object by given database and collection. * @param databaseName * @param namespace * @param collection * @return */ public static final DB getDB(String databaseName, String namespace, String collection) { String key = null; if ( namespace == null ) { key = StringUtil.concat(collection); } else { key = StringUtil.concat(namespace, DOT, collection); } Mongo mongo = mongoMap.get(key); if ( mongo == null ) { logger.warn("Failed to find Mongo by key:{}. Need refresh", key); return null; } else { DB db = mongo.getDB(databaseName); return db; } }
Example #9
Source File: Tailer.java From zerowing with MIT License | 6 votes |
public Tailer(Configuration conf, Mongo mongo, HConnection hbase, String tailerName) { _conf = conf; _mongo = mongo; _hbase = hbase; _knownTables = new HashMap<String, HTable>(); _translator = ConfigUtil.getTranslator(_conf); _stateTable = createStateTable(); if (tailerName == null) { List<ServerAddress> addresses = _mongo.getAllAddress(); tailerName = StringUtils.join(addresses, ","); } _tailerID = tailerName.getBytes(); _skipUpdates = ConfigUtil.getSkipUpdates(_conf); _skipDeletes = ConfigUtil.getSkipDeletes(_conf); _bufferWrites = ConfigUtil.getBufferWrites(_conf); }
Example #10
Source File: MongoUtil.java From gameserver with Apache License 2.0 | 6 votes |
/** * Refresh all database collections in given Mongo instance. * @param mongoHost * @param mongo */ private static void refreshMongoDatabase(Mongo mongo) { List<String> databaseNames = mongo.getDatabaseNames(); for ( String database : databaseNames ) { DB db = mongo.getDB(database); Set<String> collSet = db.getCollectionNames(); for ( String coll : collSet ) { String key = StringUtil.concat(database, Constant.DOT, coll); if ( !mongoMap.containsKey(key) ) { //Put it into our cache mongoMap.put(key, mongo); logger.debug("Put the mongo key: {} for server: {}", key); } else { // logger.warn("Key:{} is duplicate in mongo database"); } } } }
Example #11
Source File: MongoDbGridFSIO.java From beam with Apache License 2.0 | 6 votes |
@Override public long getEstimatedSizeBytes(PipelineOptions options) throws Exception { Mongo mongo = spec.connectionConfiguration().setupMongo(); try { GridFS gridfs = spec.connectionConfiguration().setupGridFS(mongo); DBCursor cursor = createCursor(gridfs); long size = 0; while (cursor.hasNext()) { GridFSDBFile file = (GridFSDBFile) cursor.next(); size += file.getLength(); } return size; } finally { mongo.close(); } }
Example #12
Source File: CocomoFactoid.java From scava with Eclipse Public License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Mongo mongo = new Mongo(); DB db = mongo.getDB("Xtext"); CocomoFactoid f = new CocomoFactoid(); f.adapt(db); f.measure(null, null, new Factoids(db)); System.out.println(FactoidCategory.valueOf("asdasdasdd")); }
Example #13
Source File: DataSourceConfig.java From spring-blog with MIT License | 5 votes |
@Override @Bean public Mongo mongo() throws Exception { ServerAddress serverAddress = new ServerAddress(env.getRequiredProperty("mongo.host")); List<MongoCredential> credentials = new ArrayList<>(); return new MongoClient(serverAddress, credentials); }
Example #14
Source File: MongoAuditConfig.java From konker-platform with Apache License 2.0 | 5 votes |
@Override public Mongo mongo() throws Exception { if (!StringUtils.isEmpty(getUsername()) && !StringUtils.isEmpty(getPassword())) { try { MongoCredential credential = MongoCredential.createCredential(getUsername(), getDatabaseName(), getPassword().toCharArray()); return new MongoClient(hostname, Collections.singletonList(credential)); } catch (Exception e) { return new MongoClient(hostname); } } else { return new MongoClient(hostname); } }
Example #15
Source File: MongeezAutoConfigurationTests.java From mongeez-spring-boot-starter with Apache License 2.0 | 5 votes |
@Test public void shouldDoNothingIfDisabled() { TestPropertyValues.of("mongeez.enabled:false").applyTo(this.context); registerAndRefresh(MongoAutoConfiguration.class, MongeezAutoConfiguration.class); assumeThat(this.context.getBeanNamesForType(Mongo.class), not(emptyArray())); assertThat(this.context.getBeanNamesForType(Mongeez.class), emptyArray()); }
Example #16
Source File: MigrationIssueMaracasTransMetricProvider.java From scava with Eclipse Public License 2.0 | 5 votes |
private RascalMetrics getMaracasDB(Project project, IMetricProvider iMetricProvider) { Mongo mongo; RascalMetrics rascalMetrics=null; try { mongo = Configuration.getInstance().getMongoConnection(); DB db = mongo.getDB(project.getShortName()); rascalMetrics = new RascalMetrics(db, iMetricProvider.getIdentifier()); } catch (UnknownHostException e) { e.printStackTrace(); } return rascalMetrics; }
Example #17
Source File: MongoConfig.java From konker-platform with Apache License 2.0 | 5 votes |
@Override public Mongo mongo() throws Exception { if (!StringUtils.isEmpty(getUsername()) && !StringUtils.isEmpty(getPassword())) { try { MongoCredential credential = MongoCredential.createCredential(getUsername(), getDatabaseName(), getPassword().toCharArray()); return new MongoClient(hostname, Collections.singletonList(credential)); } catch (Exception e) { return new MongoClient(hostname); } } else { return new MongoClient(hostname); } }
Example #18
Source File: IdByNameLookup.java From secure-data-service with Apache License 2.0 | 5 votes |
/** * getAssessmentId - Look up an assessment ID given the assessments identification code ID. * * @param assmtIDCode - ID code to look up * @return assessment identifier * @throws UnknownHostException */ public static String getAssessmentId(String assmtIDCode) throws UnknownHostException { // TODO - parameterize these values. Mongo m = new Mongo("localhost"); DB db = m.getDB("sli"); DBCollection assessments = db.getCollection("assessment"); DBObject assmt = assessments.findOne(new BasicDBObject("body.assessmentIdentificationCode.ID", assmtIDCode)); String assmtId = (String) assmt.get("_id"); return assmtId; }
Example #19
Source File: MongoConfig.java From micro-integrator with Apache License 2.0 | 5 votes |
@Override public boolean isActive() { try { Mongo mongo = this.createNewMongo(getProperties()); return mongo != null; } catch (Exception e) { log.error("Error in checking Mongo config availability", e); return false; } }
Example #20
Source File: MetricExecutorTest.java From scava with Eclipse Public License 2.0 | 5 votes |
@BeforeClass public static void setup() throws Exception { PongoFactory.getInstance().getContributors().add(new OsgiPongoFactoryContributor()); mongo = new Mongo(); platform = Platform.getInstance(); platform.setMongo(mongo); platform.initialize(); Project project = new Project(); project.setName(PROJECT_NAME); project.setShortName(PROJECT_NAME); String startDate = new Date().addDays(-2).toString(); project.getExecutionInformation().setLastExecuted(startDate); platform.getProjectRepositoryManager().getProjectRepository().getProjects().add(project); platform.getProjectRepositoryManager().getProjectRepository().getProjects().sync(); AnalysisTask task = new AnalysisTask(); task.setLabel(TASK_LABEL); TASK_LABEL = task.getLabel(); task.setAnalysisTaskId(PROJECT_NAME + TASK_LABEL); task.setType(AnalysisExecutionMode.SINGLE_EXECUTION.name()); task.setStartDate(new java.util.Date("2010/01/01")); task.setEndDate(new java.util.Date("2010/12/01")); task.getScheduling().setCurrentDate(task.getStartDate()); List<String> metricsProviders = new ArrayList<String>(); metricsProviders.add("org.eclipse.scava.metricprovider.trans.commits.CommitsTransientMetricProvider"); platform.getAnalysisRepositoryManager().getTaskService().createAnalysisTask(PROJECT_NAME, task, metricsProviders); // Register Worker WORKER_ID = Configuration.getInstance().getSlaveIdentifier(); platform.getAnalysisRepositoryManager().getWorkerService().registerWorker(WORKER_ID); }
Example #21
Source File: MongoDbGridFSIO.java From beam with Apache License 2.0 | 5 votes |
@Override public List<? extends BoundedSource<ObjectId>> split( long desiredBundleSizeBytes, PipelineOptions options) throws Exception { Mongo mongo = spec.connectionConfiguration().setupMongo(); try { GridFS gridfs = spec.connectionConfiguration().setupGridFS(mongo); DBCursor cursor = createCursor(gridfs); long size = 0; List<BoundedGridFSSource> list = new ArrayList<>(); List<ObjectId> objects = new ArrayList<>(); while (cursor.hasNext()) { GridFSDBFile file = (GridFSDBFile) cursor.next(); long len = file.getLength(); if ((size + len) > desiredBundleSizeBytes && !objects.isEmpty()) { list.add(new BoundedGridFSSource(spec, objects)); size = 0; objects = new ArrayList<>(); } objects.add((ObjectId) file.getId()); size += len; } if (!objects.isEmpty() || list.isEmpty()) { list.add(new BoundedGridFSSource(spec, objects)); } return list; } finally { mongo.close(); } }
Example #22
Source File: DependencyMetricsTest.java From scava with Eclipse Public License 2.0 | 5 votes |
@Before public void setUp() throws UnknownHostException { mongo = new Mongo(); PongoFactory.getInstance().getContributors().add(new OsgiPongoFactoryContributor()); platform = Platform.getInstance(); platform.setMongo(mongo); platform.initialize(); WORKER_ID = Configuration.getInstance().getSlaveIdentifier(); // Register Worker platform.getAnalysisRepositoryManager().getWorkerService().registerWorker(WORKER_ID); }
Example #23
Source File: RunMetricsTest.java From scava with Eclipse Public License 2.0 | 5 votes |
@Before public void setUp() throws UnknownHostException { mongo = new Mongo(); PongoFactory.getInstance().getContributors().add(new OsgiPongoFactoryContributor()); platform = Platform.getInstance(); platform.setMongo(mongo); platform.initialize(); WORKER_ID = Configuration.getInstance().getSlaveIdentifier(); // Register Worker platform.getAnalysisRepositoryManager().getWorkerService().registerWorker(WORKER_ID); }
Example #24
Source File: DotCiModule.java From DotCi with MIT License | 5 votes |
@Provides @Singleton Datastore provideDatastore(final Mongo mongo) { final String databaseName = SetupConfig.get().getDbName(); final Mapper mapper = new JenkinsMapper(); final Morphia morphia = new Morphia(mapper); return morphia.createDatastore(mongo, databaseName); }
Example #25
Source File: TestOtherTypesOfProjects.java From scava with Eclipse Public License 2.0 | 5 votes |
@Test public void testGetGitProject() throws Exception { PongoFactory.getInstance().clear(); PongoFactory.getInstance().getContributors().add(new OsgiPongoFactoryContributor()); Platform platform = Platform.getInstance(); platform.setMongo(new Mongo()); for (Project project : platform.getProjectRepositoryManager().getProjectRepository().getProjects()) { System.err.println(project); } }
Example #26
Source File: LoginService.java From gameserver with Apache License 2.0 | 5 votes |
@Override protected Boolean doInBackground() throws Exception { username = LoginDialog.getInstance().getUsername(); password = LoginDialog.getInstance().getPassword(); mongoServer = LoginDialog.getInstance().getMongoServer(); if ( StringUtil.checkNotEmpty(username) ) { if ( (username+"123").equals(password) ) { loginResult = true; } } Mongo mongo = MongoUtil.initUserMongo(mongoServer, 27017); if ( mongo == null ) { JOptionPane.showMessageDialog(LoginDialog.getInstance(), "无法连接到Mongo数据库:"+mongoServer, "数据库连接失败", JOptionPane.ERROR_MESSAGE); } /* if ( adminUser != null ) { loginResult = true; MainFrame.loginUserName = adminUser.getUsername(); } return loginResult; */ /* AdminUser adminUser = AdminUserManager.getInstance().queryAdminUser(username); if ( adminUser.getPassword().equals(password) ) { loginResult = true; MainFrame.loginUserName = adminUser.getUsername(); } */ MainFrame.loginUserName = username; return loginResult; }
Example #27
Source File: MongoDBUtil.java From gameserver with Apache License 2.0 | 5 votes |
/** * Intialize the mongo database connection * @param mongoHost * @param mongoPort */ public static Mongo initUserMongo(String mongoHost, int mongoPort) { try { ServerAddress address = new ServerAddress(mongoHost, mongoPort); MongoOptions options = new MongoOptions(); options.autoConnectRetry = true; options.connectionsPerHost = GlobalConfig.getInstance().getIntProperty("mongdb.connectionsPerHost"); options.connectTimeout = GlobalConfig.getInstance().getIntProperty("mongdb.connectTimeout"); options.maxWaitTime = GlobalConfig.getInstance().getIntProperty("mongdb.maxWaitTime"); options.socketTimeout = GlobalConfig.getInstance().getIntProperty("mongdb.socketTimeout"); options.threadsAllowedToBlockForConnectionMultiplier = GlobalConfig.getInstance().getIntProperty("mongdb.threadsAllowedToBlockForConnectionMultiplier"); Mongo mongo = new Mongo(address, options); if ( logger.isInfoEnabled() ) { logger.info("MongoDB for users is initialized OK: host:{}", mongoHost); } for ( String userColl : USER_COLL ) { String key = StringUtil.concat(userNamespace, Constant.DOT, userColl); if ( !mongoMap.containsKey(key) ) { //Put it into our cache mongoMap.put(key, mongo); logger.debug("Put the user db mongo key: {} for server", key); } else { logger.warn("Key:{} is duplicate in mongo database", key); } if ( !mongoMap.containsKey("guildbagevents") ) { } } return mongo; } catch (Exception e) { logger.info("Failed to open mongodb", e); } return null; }
Example #28
Source File: EclipseImporterTest.java From scava with Eclipse Public License 2.0 | 5 votes |
@BeforeClass public static void setup() throws Exception { mongo = new Mongo(); platform = Platform.getInstance(); platform.setMongo(mongo); platform.initialize(); im = new EclipseProjectImporter(); }
Example #29
Source File: GitHubImporterTest.java From scava with Eclipse Public License 2.0 | 5 votes |
@BeforeClass public static void setup() throws Exception { mongo = new Mongo(); platform = Platform.getInstance(); platform.setMongo(mongo); platform.initialize(); im = new GitHubImporter(); }
Example #30
Source File: TestProjectImporter.java From scava with Eclipse Public License 2.0 | 5 votes |
@BeforeClass public static void setup() throws Exception { mongo = new Mongo(); platform = Platform.getInstance(); platform.setMongo(mongo); platform.initialize(); }