当前位置: 首页>>代码示例>>Java>>正文


Java MongoClient.close方法代码示例

本文整理汇总了Java中com.mongodb.MongoClient.close方法的典型用法代码示例。如果您正苦于以下问题:Java MongoClient.close方法的具体用法?Java MongoClient.close怎么用?Java MongoClient.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mongodb.MongoClient的用法示例。


在下文中一共展示了MongoClient.close方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testInsert

import com.mongodb.MongoClient; //导入方法依赖的package包/类
@Test
@Ignore
public void testInsert() {
    MongoClient mongoClient = new MongoClient("localhost", 27017);
    try {
        MongoDatabase db = mongoClient.getDatabase("prova");
        MongoCollection<Document> coll = db.getCollection("prova");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("signature", "void test()");
        map.put("param", convert(new Object[0]));
        map.put("returnValue", 1);
        map.put("exception", convert(new IllegalAccessError("prova")));
        Document doc = new Document(map);
        coll.insertOne(doc);
        LOG.info(doc);
    } catch (Exception e) {
        LOG.error(e);
    } finally {
        mongoClient.close();
    }
}
 
开发者ID:sap-nocops,项目名称:Jerkoff,代码行数:22,代码来源:MongoTest.java

示例2: testMongo1

import com.mongodb.MongoClient; //导入方法依赖的package包/类
@POST
@Path("testMongo1")
public void testMongo1(String jsonString) {

    MongoClient client = new MongoClient();
    client.listDatabaseNames().first();
    MongoDatabase db = client.getDatabase("apphubDataStore");
    db.listCollectionNames().first();
    MongoCollection<Document> collection = db.getCollection("test");
    collection.listIndexes().first();
    Document doc = new Document("name", "Amarcord Pizzeria")
            .append("contact",
                    new Document("phone", "264-555-0193").append("email", "[email protected]")
                            .append("location", Arrays.asList(-73.88502, 40.749556)))
            .append("stars", 2).append("categories", Arrays.asList("Pizzeria", "Italian", "Pasta"));
    collection.insertOne(doc);
    collection.find().first();

    MongoClient client2 = new MongoClient("localhost:27017");
    db = client2.getDatabase("apphubDataStore");
    db.listCollectionNames().first();
    collection = db.getCollection("test");
    collection.listIndexes().first();

    client.close();
    client2.close();
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:28,代码来源:TestRestService.java

示例3: testRead

import com.mongodb.MongoClient; //导入方法依赖的package包/类
@Test
@Ignore
public void testRead() {
    MongoClient mongoClient = new MongoClient("localhost", 27017);
    try {
        MongoDatabase db = mongoClient.getDatabase("prova");
        MongoCollection<Document> coll = db.getCollection("prova");
        FindIterable<Document> res = coll.find();
        for (Document doc : res) {
            String thisObj = doc.getString("this");
            LOG.info(thisObj);
            String thisClass = doc.getString("thisClass");
            LOG.info(thisClass);
            Gson gson = new Gson();
            Class<?> cl = Class.forName(thisClass);
            Object obj = gson.fromJson(thisObj, cl);
            LOG.info(obj);
        }
    } catch (Exception e) {
        LOG.error(e);
    } finally {
        mongoClient.close();
    }
}
 
开发者ID:sap-nocops,项目名称:Jerkoff,代码行数:25,代码来源:MongoTest.java

示例4: test_mongoservice_not_enabled

import com.mongodb.MongoClient; //导入方法依赖的package包/类
@Test
public void test_mongoservice_not_enabled() throws InitializationException {
    final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
    final StandardMongoClientService service = new StandardMongoClientService();

    runner.addControllerService("test-mongo-closed", service);
    runner.enableControllerService(service);

    // Close MongoClient
    MongoClient client = service.getMongoClient();

    // NOTE: This test requires mongo to be running
    assertEquals("localhost:27017", client.getConnectPoint());

    // Close the mongo connection
    client.close();

    // Now, this should throw an illegal state exception
    thrown.expect(IllegalStateException.class);
    client.getConnectPoint();
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:22,代码来源:StandardMongoClientServiceIT.java

示例5: closeMongoClient

import com.mongodb.MongoClient; //导入方法依赖的package包/类
/**
 * close the mongo client 
 * 
 * @param mongoClient - client which is have to close 
 */
public void closeMongoClient(MongoClient mongoClient) {
	try {
		if (mongoClient != null) {
			mongoClient.close();
		}
	} catch (MongoException e) {
		log.error("Exception occurred while close MongoClient : " + e, e);
	}
}
 
开发者ID:sundarcse1216,项目名称:mongodb-crud,代码行数:15,代码来源:MongoConnectionUtils.java

示例6: test

import com.mongodb.MongoClient; //导入方法依赖的package包/类
/**
 * 测试用例
 * 
 * @return
 */
@GET
@Path("test")
public String test() {

    MongoClient client = new MongoClient();
    client.listDatabaseNames().first();
    MongoDatabase db = client.getDatabase("apphubDataStore");
    db.listCollectionNames().first();
    MongoCollection<Document> collection = db.getCollection("test");
    collection.listIndexes().first();
    Document doc = new Document("name", "Amarcord Pizzeria")
            .append("contact",
                    new Document("phone", "264-555-0193").append("email", "[email protected]")
                            .append("location", Arrays.asList(-73.88502, 40.749556)))
            .append("stars", 2).append("categories", Arrays.asList("Pizzeria", "Italian", "Pasta"));
    collection.insertOne(doc);
    collection.find().first();

    // MongoClient client2 = new MongoClient("localhost:27017");
    // db = client2.getDatabase("apphubDataStore");
    // db.listCollectionNames().first();
    // collection = db.getCollection("test");
    // collection.listIndexes().first();

    client.close();
    // client2.close();
    return "mongo perfect";
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:34,代码来源:MongoService.java

示例7: main

import com.mongodb.MongoClient; //导入方法依赖的package包/类
public static void main(String args[]) {

        ConsoleLogger cl = new ConsoleLogger("test");

        cl.setDebugable(true);

        UAVServer.instance().setLog(cl);

        UAVServer.instance().putServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR, ServerVendor.TOMCAT);

        MongoClientHookProxy p = new MongoClientHookProxy("test", Collections.emptyMap());

        p.doInstallDProxy(null, "testApp");

        MongoClient client = new MongoClient();
        client.listDatabaseNames().first();
        MongoDatabase db = client.getDatabase("apphubDataStore");
        db.listCollectionNames().first();
        MongoCollection<Document> collection = db.getCollection("test");
        collection.listIndexes().first();
        Document doc = new Document("name", "Amarcord Pizzeria")
                .append("contact",
                        new Document("phone", "264-555-0193").append("email", "[email protected]")
                                .append("location", Arrays.asList(-73.88502, 40.749556)))
                .append("stars", 2).append("categories", Arrays.asList("Pizzeria", "Italian", "Pasta"));
        collection.insertOne(doc);
        collection.find().first();

        MongoClient client2 = new MongoClient("localhost:27017");
        db = client2.getDatabase("apphubDataStore");
        db.listCollectionNames().first();
        collection = db.getCollection("test");
        collection.listIndexes().first();

        client.close();
        client2.close();
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:38,代码来源:DoTestMongoClientProxy.java

示例8: MongoTransporterConfig

import com.mongodb.MongoClient; //导入方法依赖的package包/类
public MongoTransporterConfig(Config config) {
    try {
        MongoClientOptions.Builder builder = MongoClientOptions.builder().connectTimeout(5000).socketTimeout(5000).serverSelectionTimeout(3000);
        client = new MongoClient(new ServerAddress(config.getConfigString("host"), config.getConfigInt("port")), builder.build());
        client.getAddress();
        database = client.getDatabase(config.getConfigString("database"));
        collection = database.getCollection(config.getConfigString("collection"));
    } catch (MongoTimeoutException e) {
        client.close();
        log.error("MongoClient initial failed", e);
        throw new LogregatorException();
    }
}
 
开发者ID:geminiKim,项目名称:logregator,代码行数:14,代码来源:MongoTransporterConfig.java

示例9: tearDown

import com.mongodb.MongoClient; //导入方法依赖的package包/类
@After
public void tearDown() throws Exception {
    if (null != mongo) {
        MongoClient client = mongo.getMongoClient();
        if (client != null) {
            MongoDatabase db = client.getDatabase(MONGO_DATABASE_NAME);
            if (db != null) {
                db.drop();
            }
            client.close();
        }
    }
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:14,代码来源:StoreInMongoIT.java

示例10: tearDown

import com.mongodb.MongoClient; //导入方法依赖的package包/类
@After
public void tearDown() throws Exception {
    if (null != mongo) {
        MongoClient client = mongo.getMongoClient();
        MongoDatabase db = client.getDatabase(MONGO_DATABASE_NAME);
        if (db != null) {
            db.drop();
        }
        client.close();
    }
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:12,代码来源:QueryMongoIT.java

示例11: destroyTestStorageGuard

import com.mongodb.MongoClient; //导入方法依赖的package包/类
/**
 * A method that destroys the test storage guard.
 */
private void destroyTestStorageGuard() {
  MongoClient testMongoClient = testStorageGuard.getMongo();
  testMongoClient.dropDatabase(TEST_DATABASE_NAME);
  testMongoClient.close();
}
 
开发者ID:catalincraciun,项目名称:scancode,代码行数:9,代码来源:ScancodeStorageTests.java

示例12: main

import com.mongodb.MongoClient; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static void main(String[] args) {

	try {

		MongoClient mongoClient = new MongoClient(host, port);

		MongoDatabase db = mongoClient.getDatabase(database);

		MongoCollection<Document> jugsCollection = db.getCollection(collection);

		System.out.println("-------- MongoDB JUG List from REGION 4 (Java Driver only) ------------");

		List<Document> mongodbDocuments = jugsCollection.find(eq("region", "Sudeste"))
				.into(new ArrayList<Document>());

		List<JUG> jugsList = new ArrayList<JUG>();

		System.out.println(mongodbDocuments);
		List<Document> jugsDocument = (List<Document>) mongodbDocuments.get(0).get("jugs");

		jugsList = jugsDocument.stream().map(obj -> new JUG((String) obj.get("name"),
				(String) obj.get("description"), (String) obj.get("local"), (String) obj.get("url")))
				.collect(Collectors.toList());

		jugsList.stream().forEach(System.out::println);

		mongoClient.close();

	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:boaglio,项目名称:mongodb-java-examples,代码行数:34,代码来源:JUGsList.java


注:本文中的com.mongodb.MongoClient.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。