List of usage examples for com.mongodb Mongo close
public void close()
From source file:org.ossmeter.platform.admin.ProjectListAnalysis.java
License:Open Source License
@Get("json") public String represent() { Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes() .get("org.restlet.http.headers"); if (responseHeaders == null) { responseHeaders = new Series(Header.class); getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders); }// w ww. ja va 2s.com responseHeaders.add(new Header("Access-Control-Allow-Origin", "*")); responseHeaders.add(new Header("Access-Control-Allow-Methods", "GET")); try { Mongo mongo = Configuration.getInstance().getMongoConnection(); DB db = mongo.getDB("ossmeter"); DBCollection col = db.getCollection("metricAnalysis"); ObjectMapper mapper = new ObjectMapper(); ArrayNode results = mapper.createArrayNode(); DBCursor cursor = col.find(); try { while (cursor.hasNext()) { results.add(cursor.next().toString()); } } finally { cursor.close(); } mongo.close(); return results.toString(); } catch (UnknownHostException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return null; }
From source file:org.ossmeter.platform.admin.ProjectMetricAnalysis.java
License:Open Source License
@Get("json") public String represent() { Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes() .get("org.restlet.http.headers"); if (responseHeaders == null) { responseHeaders = new Series(Header.class); getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders); }/*from w w w . ja v a2s . co m*/ responseHeaders.add(new Header("Access-Control-Allow-Origin", "*")); responseHeaders.add(new Header("Access-Control-Allow-Methods", "GET")); try { String projectId = (String) getRequest().getAttributes().get("projectId"); String metricId = (String) getRequest().getAttributes().get("metricId"); Mongo mongo = Configuration.getInstance().getMongoConnection(); DB db = mongo.getDB("ossmeter"); DBCollection col = db.getCollection("metricAnalysis"); BasicDBObject query = new BasicDBObject("projectId", projectId); query.append("metricId", metricId); BasicDBObject sort = new BasicDBObject("analysisDate", 1); DBCursor cursor = col.find(query).sort(sort); ObjectMapper mapper = new ObjectMapper(); ArrayNode results = mapper.createArrayNode(); while (cursor.hasNext()) { DBObject obj = cursor.next(); if ("true".equals(getQueryValue("incDate"))) { ObjectNode on = mapper.createObjectNode(); on.put("date", obj.get("analysisDate").toString()); on.put("millis", (Double) obj.get("millisTaken")); results.add(on); } else { results.add((Double) obj.get("millisTaken")); } } mongo.close(); return results.toString(); } catch (UnknownHostException e1) { e1.printStackTrace(); } return null; }
From source file:org.ossmeter.platform.app.example.App.java
License:Open Source License
@Override public Object start(IApplicationContext context) throws Exception { // Add projects to the DB here Mongo mongo = new Mongo(); PongoFactory.getInstance().getContributors().add(new OsgiPongoFactoryContributor()); Platform platform = new Platform(mongo); // Project pongo = ProjectCreationUtil.createSvnProject("pongo", "http://pongo.googlecode.com/svn/trunk"); // platform.getProjectRepositoryManager().getProjectRepository().getProjects().add(pongo); // Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("xText", "news.eclipse.org", "eclipse.modeling.tmf", true, "exquisitus", "flinder1f7", 80, 10000); // Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("epsilon", "news.eclipse.org", "eclipse.epsilon", true, "exquisitus", "flinder1f7", 80, 10000); // Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("thunderbird", "news.mozilla.org", "mozilla.support.thunderbird", false, null, null, 80, 10000); // Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("eclipsePlatform", "news.eclipse.org", "eclipse.platform", true, "exquisitus", "flinder1f7", 80, 10000); Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("BIRT", "news.eclipse.org", "eclipse.birt", true, "exquisitus", "flinder1f7", 80, 10000); // Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("SiriusForum", "news.eclipse.org", "eclipse.sirius", true, "exquisitus", "flinder1f7", 80, 10000); // Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("toolsEmf", "news.eclipse.org", "eclipse.tools.emf", true, "exquisitus", "flinder1f7", 80, 10000); // Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("Log4J", "news.gmane.org", "gmane.comp.jakarta.log4j.user", false, null, null, 119, 10000); // Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("tomcat-user", "news.gmane.org", "gmane.comp.jakarta.tomcat.user", false, null, null, 119, 10000); // Project pdb = ProjectCreationUtil.createProjectWithBugTrackingSystem("epsilon", "https://bugs.eclipse.org/bugs/xmlrpc.cgi", "epsilon", null); // Project pdb = ProjectCreationUtil.createProjectWithBugTrackingSystem("eclipse", "https://bugs.eclipse.org/bugs/xmlrpc.cgi", "platform", null); // Project pdb = ProjectCreationUtil.createProjectWithBugTrackingSystem("modelinggmtamw", "https://bugs.eclipse.org/bugs/xmlrpc.cgi", "GMT", "AMW"); // Project pdb = ProjectCreationUtil.createProjectWithBugTrackingSystem("modelinggmt", "https://bugs.eclipse.org/bugs/xmlrpc.cgi", "GMT", null); // Project pdb = ProjectCreationUtil.createProjectWithBugTrackingSystem("xText", "https://bugs.eclipse.org/bugs/xmlrpc.cgi", "TMF", "Xtext"); // Project pdb = ProjectCreationUtil.createProjectWithBugTrackingSystem("fedora", "https://bugzilla.redhat.com/xmlrpc.cgi", "Fedora", "acpi"); // Project pdb = ProjectCreationUtil.createProjectWithBugTrackingSystem("bugzilla", "https://bugzilla.redhat.com/xmlrpc.cgi", "Bugzilla", null); // Url: https://bugs.eclipse.org/bugs/xmlrpc.cgi // Product: MDT.Papyrus // Components: Core, Diagram, Others, Table, Views // addSampleProjectWithBugTrackingSystem("MDT-Papyrus", "https://bugs.eclipse.org/bugs/xmlrpc.cgi", "MDT.Papyrus", "Core", platform); // addSampleProjectWithBugTrackingSystem("TMF-Xtext", "https://bugs.eclipse.org/bugs/xmlrpc.cgi", "TMF", "Xtext", platform); // Project pdb = ProjectCreationUtil.createProjectWithBugTrackingSystem("epsilon", "https://bugs.eclipse.org/bugs/xmlrpc.cgi", "epsilon", null); // Project pdb = ProjectCreationUtil.createGitProject("rascal", "file:///Users/jurgenv/Workspaces/Rascal/rascal"); pdb.getExecutionInformation().setMonitor(true); platform.getProjectRepositoryManager().getProjectRepository().getProjects().add(pdb); platform.getProjectRepositoryManager().getProjectRepository().sync(); System.err.println(platform.getBugTrackingSystemManager().getBugTrackingSystemManagers()); mongo.close(); // Start the application return null;// w ww. j a v a 2 s .c o m // return new OssmeterApplication().start(context); }
From source file:org.ossmeter.platform.client.api.AbstractApiResource.java
License:Open Source License
@Get("json") public final Representation represent() { Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes() .get("org.restlet.http.headers"); if (responseHeaders == null) { responseHeaders = new Series(Header.class); getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders); }//w ww.ja v a 2s . c o m responseHeaders.add(new Header("Access-Control-Allow-Origin", "*")); responseHeaders.add(new Header("Access-Control-Allow-Methods", "GET")); mapper = new ObjectMapper(); Mongo mongo; try { mongo = Configuration.getInstance().getMongoConnection(); } catch (UnknownHostException e1) { e1.printStackTrace(); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); return Util.generateErrorMessageRepresentation(generateRequestJson(mapper, null), "The API was unable to connect to the database."); } platform = new Platform(mongo); // Delegate to resource Representation rep = doRepresent(); mongo.close(); return rep; }
From source file:org.ossmeter.platform.osgi.ExampleProjectCreator.java
License:Open Source License
public static void main(String[] args) throws Exception { Mongo mongo = new Mongo(); Platform platform = new Platform(mongo); Project project = new Project(); project.setName("Foo"); project.setShortName("Foo"); platform.getProjectRepositoryManager().getProjectRepository().getProjects().add(project); project = new Project(); project.setName("Bar"); project.setShortName("Bar"); platform.getProjectRepositoryManager().getProjectRepository().getProjects().add(project); project = new Project(); project.setName("Whizz"); project.setShortName("Whizz"); platform.getProjectRepositoryManager().getProjectRepository().getProjects().add(project); project = new Project(); project.setName("Baz"); project.setShortName("Baz"); platform.getProjectRepositoryManager().getProjectRepository().getProjects().add(project); project = new Project(); project.setName("Boop"); project.setShortName("Boop"); platform.getProjectRepositoryManager().getProjectRepository().getProjects().add(project); platform.getProjectRepositoryManager().getProjectRepository().getSchedulingInformation() .add(new SchedulingInformation()); platform.getProjectRepositoryManager().getProjectRepository().sync(); mongo.close(); }
From source file:org.ossmeter.platform.osgi.executors.MetricListExecutor.java
License:Open Source License
@Override public void run() { Mongo mongo; try {/*from w ww. j a v a 2s.c om*/ mongo = Configuration.getInstance().getMongoConnection(); } catch (UnknownHostException e2) { e2.printStackTrace(); // FIXME appropriately log return; } Platform platform = new Platform(mongo); Project project = platform.getProjectRepositoryManager().getProjectRepository().getProjects() .findOneByShortName(projectId); for (IMetricProvider m : metrics) { m.setMetricProviderContext(new MetricProviderContext(platform, new OssmeterLoggerFactory().makeNewLoggerInstance(m.getIdentifier()))); addDependenciesToMetricProvider(platform, m); // We need to check that it hasn't already been excuted for this date // e.g. in cases where a different MP MetricProviderType type = MetricProviderType.TRANSIENT; if (m instanceof IHistoricalMetricProvider) type = MetricProviderType.HISTORIC; MetricProviderExecution mpd = getProjectModelMetricProvider(project, m); if (mpd == null) { mpd = new MetricProviderExecution(); project.getExecutionInformation().getMetricProviderData().add(mpd); mpd.setMetricProviderId(m.getIdentifier()); mpd.setType(type); platform.getProjectRepositoryManager().getProjectRepository().sync(); } try { Date lastExec = new Date(mpd.getLastExecuted()); // Check we haven't already executed the MP for this day. if (date.compareTo(lastExec) < 0) { logger.warn("Metric provider '" + m.getIdentifier() + "' has been executed for this date already. Ignoring."); continue; } } catch (ParseException e) { // we can ignore this } catch (NumberFormatException e) { // We can ignore this } // Performance analysis MetricAnalysis mAnal = new MetricAnalysis(); mAnal.setMetricId(m.getIdentifier()); mAnal.setProjectId(project.getShortName()); // FIXME mAnal.setAnalysisDate(date.toJavaDate()); mAnal.setExecutionDate(new java.util.Date()); platform.getProjectRepositoryManager().getProjectRepository().getMetricAnalysis().add(mAnal); long start = now(); // TODO: Could edit the generated code to encapsulate this. // Now execute try { if (m instanceof ITransientMetricProvider) { //JURI added if statement if (m.appliesTo(project)) ((ITransientMetricProvider) m).measure(project, delta, ((ITransientMetricProvider) m) .adapt(platform.getMetricsRepository(project).getDb())); } else if (m instanceof IHistoricalMetricProvider) { MetricHistoryManager historyManager = new MetricHistoryManager(platform); //JURI added if statement if (m.appliesTo(project)) historyManager.store(project, date, (IHistoricalMetricProvider) m); } // Update the meta data -- need to requery the database due to Pongo caching in different threads(!) project = platform.getProjectRepositoryManager().getProjectRepository().getProjects() .findOneByShortName(project.getShortName()); mpd = getProjectModelMetricProvider(project, m); mpd.setLastExecuted(date.toString()); platform.getProjectRepositoryManager().getProjectRepository().sync(); } catch (Exception e) { logger.error("Exception thrown during metric provider execution (" + m.getShortIdentifier() + ").", e); project.getExecutionInformation().setInErrorState(true); platform.getProjectRepositoryManager().getProjectRepository().sync(); break; } mAnal.setMillisTaken(now() - start); platform.getProjectRepositoryManager().getProjectRepository().sync(); // Will sync-ing here mess things up? } mongo.close(); }
From source file:org.springframework.data.mongodb.core.MongoClientFactoryBean.java
License:Apache License
@Override protected void destroyInstance(Mongo instance) throws Exception { instance.close(); }
From source file:org.springframework.data.mongodb.core.MongoFactoryBean.java
License:Apache License
@Override protected void destroyInstance(Mongo mongo) throws Exception { mongo.close(); }
From source file:org.unitedid.shibboleth.attribute.resolver.provider.dataConnector.MongoDbDataConnector.java
License:Apache License
/** {@inheritDoc} */ public void validate() throws AttributeResolutionException { log.debug("Validating data connector {} configuration.", getId()); Mongo connection = null; try {/*from w ww.j a va 2s . c o m*/ connection = new Mongo(mongoHost); if (connection == null) { log.error("Unable to create connections using {} data connector ", getId()); throw new AttributeResolutionException( "Unable to create connections using " + getId() + " data connector."); } } catch (MongoException e) { log.error("Unable to validate {} data connector", getId(), e); throw new AttributeResolutionException("Unable to validate " + getId() + " data connector: ", e); } finally { connection.close(); } }
From source file:piecework.repository.concrete.EmbeddedMongoInstance.java
License:Educational Community License
public void importData() throws Exception { Mongo mongo = new Mongo(bindIp, port); DB db = mongo.getDB(dbName);/* w w w. j a v a 2s . c om*/ File directory = new File(storePath, "dbs"); if (!directory.exists()) { LOG.debug("No startup data exists"); return; } File dbDirectory = new File(directory, dbName); if (!dbDirectory.exists()) { LOG.debug("No startup data exists for " + dbName); return; } File[] collectionFiles = dbDirectory.listFiles(); for (File collectionFile : collectionFiles) { if (collectionFile.isFile() && collectionFile.exists()) { String collectionName = collectionFile.getName(); LOG.debug("Loading collection '" + collectionName + "'..."); DBCollection dbCollection = db.getCollection(collectionName); try { LOG.debug("Loading JSON from file '" + collectionFile.getName() + "'"); importCollection(dbCollection, new FileInputStream(collectionFile)); } catch (FileNotFoundException fnfe) { LOG.warn("Unable to initialize local mongo with data from " + collectionFile.getAbsolutePath(), fnfe); } } } mongo.close(); }